ruby-grafana-reporter 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +166 -339
- data/bin/ruby-grafana-reporter +5 -4
- data/lib/VERSION.rb +5 -3
- data/lib/grafana/abstract_panel_query.rb +22 -20
- data/lib/grafana/abstract_query.rb +132 -127
- data/lib/grafana/abstract_sql_query.rb +51 -42
- data/lib/grafana/dashboard.rb +77 -66
- data/lib/grafana/errors.rb +66 -61
- data/lib/grafana/grafana.rb +130 -131
- data/lib/grafana/panel.rb +41 -39
- data/lib/grafana/panel_image_query.rb +52 -49
- data/lib/grafana/variable.rb +217 -259
- data/lib/grafana_reporter/abstract_report.rb +112 -109
- data/lib/grafana_reporter/application/application.rb +404 -229
- data/lib/grafana_reporter/application/errors.rb +33 -30
- data/lib/grafana_reporter/application/webservice.rb +231 -0
- data/lib/grafana_reporter/asciidoctor/alerts_table_query.rb +104 -99
- data/lib/grafana_reporter/asciidoctor/annotations_table_query.rb +99 -96
- data/lib/grafana_reporter/asciidoctor/errors.rb +40 -37
- data/lib/grafana_reporter/asciidoctor/extensions/alerts_table_include_processor.rb +92 -86
- data/lib/grafana_reporter/asciidoctor/extensions/annotations_table_include_processor.rb +91 -86
- data/lib/grafana_reporter/asciidoctor/extensions/panel_image_block_macro.rb +69 -67
- data/lib/grafana_reporter/asciidoctor/extensions/panel_image_inline_macro.rb +68 -65
- data/lib/grafana_reporter/asciidoctor/extensions/panel_property_inline_macro.rb +61 -58
- data/lib/grafana_reporter/asciidoctor/extensions/panel_query_table_include_processor.rb +78 -75
- data/lib/grafana_reporter/asciidoctor/extensions/panel_query_value_inline_macro.rb +73 -70
- data/lib/grafana_reporter/asciidoctor/extensions/processor_mixin.rb +20 -18
- data/lib/grafana_reporter/asciidoctor/extensions/show_environment_include_processor.rb +43 -41
- data/lib/grafana_reporter/asciidoctor/extensions/sql_table_include_processor.rb +70 -67
- data/lib/grafana_reporter/asciidoctor/extensions/sql_value_inline_macro.rb +66 -65
- data/lib/grafana_reporter/asciidoctor/extensions/value_as_variable_include_processor.rb +61 -57
- data/lib/grafana_reporter/asciidoctor/panel_first_value_query.rb +34 -32
- data/lib/grafana_reporter/asciidoctor/panel_image_query.rb +25 -23
- data/lib/grafana_reporter/asciidoctor/panel_property_query.rb +44 -43
- data/lib/grafana_reporter/asciidoctor/panel_table_query.rb +38 -36
- data/lib/grafana_reporter/asciidoctor/query_mixin.rb +310 -309
- data/lib/grafana_reporter/asciidoctor/report.rb +177 -159
- data/lib/grafana_reporter/asciidoctor/sql_first_value_query.rb +37 -34
- data/lib/grafana_reporter/asciidoctor/sql_table_query.rb +39 -32
- data/lib/grafana_reporter/configuration.rb +257 -326
- data/lib/grafana_reporter/errors.rb +48 -38
- data/lib/grafana_reporter/logger/two_way_logger.rb +58 -52
- data/lib/ruby-grafana-reporter.rb +29 -27
- metadata +10 -23
@@ -1,75 +1,78 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# +
|
15
|
-
#
|
16
|
-
# +
|
17
|
-
#
|
18
|
-
# +
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# +
|
27
|
-
#
|
28
|
-
# +
|
29
|
-
#
|
30
|
-
# +
|
31
|
-
#
|
32
|
-
# +
|
33
|
-
#
|
34
|
-
# +
|
35
|
-
#
|
36
|
-
# +
|
37
|
-
#
|
38
|
-
# +
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@report.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
reader.
|
65
|
-
rescue
|
66
|
-
@report.logger.
|
67
|
-
reader.unshift_line
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'processor_mixin'
|
4
|
+
|
5
|
+
module GrafanaReporter
|
6
|
+
module Asciidoctor
|
7
|
+
module Extensions
|
8
|
+
# Implements the hook
|
9
|
+
# include::grafana_panel_query_table:<panel_id>[<options>]
|
10
|
+
#
|
11
|
+
# Returns the results of the SQL query as a asciidoctor table.
|
12
|
+
#
|
13
|
+
# == Used document parameters
|
14
|
+
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
15
|
+
#
|
16
|
+
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
17
|
+
#
|
18
|
+
# +from+ - 'from' time for the sql query
|
19
|
+
#
|
20
|
+
# +to+ - 'to' time for the sql query
|
21
|
+
#
|
22
|
+
# All other variables starting with +var-+ will be used to replace grafana templating strings
|
23
|
+
# in the given SQL query.
|
24
|
+
#
|
25
|
+
# == Supported options
|
26
|
+
# +query+ - query letter, which shall be used, e.g. +C+ (*mandatory*)
|
27
|
+
#
|
28
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
29
|
+
#
|
30
|
+
# +dashboard+ - uid of grafana dashboard to use
|
31
|
+
#
|
32
|
+
# +from+ - 'from' time for the sql query
|
33
|
+
#
|
34
|
+
# +to+ - 'to' time for the sql query
|
35
|
+
#
|
36
|
+
# +format+ - see {QueryMixin#format_columns}
|
37
|
+
#
|
38
|
+
# +replace_values+ - see {QueryMixin#replace_values}
|
39
|
+
#
|
40
|
+
# +filter_columns+ - see {QueryMixin#filter_columns}
|
41
|
+
class PanelQueryTableIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
42
|
+
include ProcessorMixin
|
43
|
+
|
44
|
+
# :nodoc:
|
45
|
+
def handles?(target)
|
46
|
+
target.start_with? 'grafana_panel_query_table:'
|
47
|
+
end
|
48
|
+
|
49
|
+
# :nodoc:
|
50
|
+
def process(doc, reader, target, attrs)
|
51
|
+
return if @report.cancel
|
52
|
+
|
53
|
+
@report.next_step
|
54
|
+
panel_id = target.split(':')[1]
|
55
|
+
instance = attrs['instance'] || doc.attr('grafana_default_instance') || 'default'
|
56
|
+
dashboard = attrs['dashboard'] || doc.attr('grafana_default_dashboard')
|
57
|
+
@report.logger.debug("Processing PanelQueryTableIncludeProcessor (instance: #{instance}, "\
|
58
|
+
"dashboard: #{dashboard}, panel: #{panel_id}, query: #{attrs['query']})")
|
59
|
+
query = PanelTableQuery.new(@report.grafana(instance).dashboard(dashboard).panel(panel_id), attrs['query'])
|
60
|
+
query.merge_hash_variables(doc.attributes, attrs)
|
61
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
62
|
+
|
63
|
+
begin
|
64
|
+
reader.unshift_lines query.execute(@report.grafana(instance))
|
65
|
+
rescue GrafanaReporterError => e
|
66
|
+
@report.logger.error(e.message)
|
67
|
+
reader.unshift_line "|#{e.message}"
|
68
|
+
rescue StandardError => e
|
69
|
+
@report.logger.fatal(e.message)
|
70
|
+
reader.unshift_line "|#{e.message}"
|
71
|
+
end
|
72
|
+
|
73
|
+
reader
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -1,70 +1,73 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# +
|
15
|
-
#
|
16
|
-
# +
|
17
|
-
#
|
18
|
-
# +
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# +
|
27
|
-
#
|
28
|
-
# +
|
29
|
-
#
|
30
|
-
# +
|
31
|
-
#
|
32
|
-
# +
|
33
|
-
#
|
34
|
-
# +
|
35
|
-
#
|
36
|
-
# +
|
37
|
-
#
|
38
|
-
# +
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
@report.
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
create_inline(parent, :quoted,
|
62
|
-
rescue
|
63
|
-
@report.logger.
|
64
|
-
create_inline(parent, :quoted, e.message)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'processor_mixin'
|
4
|
+
|
5
|
+
module GrafanaReporter
|
6
|
+
module Asciidoctor
|
7
|
+
module Extensions
|
8
|
+
# Implements the hook
|
9
|
+
# grafana_panel_query_value:<panel_id>[<options>]
|
10
|
+
#
|
11
|
+
# Returns the first value of the resulting SQL query.
|
12
|
+
#
|
13
|
+
# == Used document parameters
|
14
|
+
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
15
|
+
#
|
16
|
+
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
17
|
+
#
|
18
|
+
# +from+ - 'from' time for the sql query
|
19
|
+
#
|
20
|
+
# +to+ - 'to' time for the sql query
|
21
|
+
#
|
22
|
+
# All other variables starting with +var-+ will be used to replace grafana templating strings
|
23
|
+
# in the given SQL query.
|
24
|
+
#
|
25
|
+
# == Supported options
|
26
|
+
# +query+ - query letter, which shall be used, e.g. +C+ (*mandatory*)
|
27
|
+
#
|
28
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
29
|
+
#
|
30
|
+
# +dashboard+ - uid of grafana dashboard to use
|
31
|
+
#
|
32
|
+
# +from+ - 'from' time for the sql query
|
33
|
+
#
|
34
|
+
# +to+ - 'to' time for the sql query
|
35
|
+
#
|
36
|
+
# +format+ - see {QueryMixin#format_columns}
|
37
|
+
#
|
38
|
+
# +replace_values+ - see {QueryMixin#replace_values}
|
39
|
+
#
|
40
|
+
# +filter_columns+ - see {QueryMixin#filter_columns}
|
41
|
+
class PanelQueryValueInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
42
|
+
include ProcessorMixin
|
43
|
+
use_dsl
|
44
|
+
|
45
|
+
named :grafana_panel_query_value
|
46
|
+
|
47
|
+
# :nodoc:
|
48
|
+
def process(parent, target, attrs)
|
49
|
+
return if @report.cancel
|
50
|
+
|
51
|
+
@report.next_step
|
52
|
+
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
53
|
+
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
54
|
+
@report.logger.debug("Processing PanelQueryValueInlineMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
55
|
+
" panel: #{target}, query: #{attrs['query']})")
|
56
|
+
query = PanelFirstValueQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target), attrs['query'])
|
57
|
+
query.merge_hash_variables(parent.document.attributes, attrs)
|
58
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
59
|
+
|
60
|
+
begin
|
61
|
+
create_inline(parent, :quoted, query.execute(@report.grafana(instance)))
|
62
|
+
rescue GrafanaReporterError => e
|
63
|
+
@report.logger.error(e.message)
|
64
|
+
create_inline(parent, :quoted, e.message)
|
65
|
+
rescue StandardError => e
|
66
|
+
@report.logger.fatal(e.message)
|
67
|
+
create_inline(parent, :quoted, e.message)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,18 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
module Asciidoctor
|
5
|
+
# The classes within this module implement the interface to asciidoctor. Each class implements a specific extension
|
6
|
+
# to asciidoctor.
|
7
|
+
module Extensions
|
8
|
+
# This module contains common methods for all asciidoctor extensions.
|
9
|
+
module ProcessorMixin
|
10
|
+
# Used when initializing a object instance, to set the report object, which is currently in progress.
|
11
|
+
# @param report [GrafanaReporter::Asciidoctor::Report] current report
|
12
|
+
# @return [::Asciidoctor::Extensions::Processor] self
|
13
|
+
def current_report(report)
|
14
|
+
@report = report
|
15
|
+
self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,41 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@report.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
module Asciidoctor
|
5
|
+
module Extensions
|
6
|
+
# Implements the hook
|
7
|
+
# include::grafana_environment[]
|
8
|
+
#
|
9
|
+
# Shows all available variables, which are accessible during this run of the asciidoctor
|
10
|
+
# grafana reporter in a asciidoctor readable form.
|
11
|
+
#
|
12
|
+
# This processor is very helpful during report template design, to find out the available
|
13
|
+
# variables, that can be accessed.
|
14
|
+
#
|
15
|
+
# == Used document parameters
|
16
|
+
# All, to be listed as the available environment.
|
17
|
+
class ShowEnvironmentIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
18
|
+
include ProcessorMixin
|
19
|
+
|
20
|
+
# :nodoc:
|
21
|
+
def handles?(target)
|
22
|
+
target.start_with? 'grafana_environment'
|
23
|
+
end
|
24
|
+
|
25
|
+
# :nodoc:
|
26
|
+
def process(doc, reader, _target, _attrs)
|
27
|
+
# return if @report.cancel
|
28
|
+
@report.next_step
|
29
|
+
@report.logger.debug('Processing ShowEnvironmentIncludeProcessor')
|
30
|
+
|
31
|
+
vars = ['== Accessible Variables',
|
32
|
+
'|===']
|
33
|
+
doc.attributes.sort.each do |k, v|
|
34
|
+
vars << "| `+{#{k}}+` | #{v}"
|
35
|
+
end
|
36
|
+
vars << '|==='
|
37
|
+
|
38
|
+
reader.unshift_lines vars
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,67 +1,70 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# +
|
13
|
-
#
|
14
|
-
# +
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# +
|
23
|
-
#
|
24
|
-
# +
|
25
|
-
#
|
26
|
-
# +
|
27
|
-
#
|
28
|
-
# +
|
29
|
-
#
|
30
|
-
# +
|
31
|
-
#
|
32
|
-
# +
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@report.
|
46
|
-
|
47
|
-
@report.
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
reader.
|
57
|
-
rescue
|
58
|
-
@report.logger.
|
59
|
-
reader.unshift_line
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
module Asciidoctor
|
5
|
+
module Extensions
|
6
|
+
# Implements the hook
|
7
|
+
# include::grafana_sql_table:<datasource_id>[<options>]
|
8
|
+
#
|
9
|
+
# Returns the results of the SQL query as a asciidoctor table.
|
10
|
+
#
|
11
|
+
# == Used document parameters
|
12
|
+
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
13
|
+
#
|
14
|
+
# +from+ - 'from' time for the sql query
|
15
|
+
#
|
16
|
+
# +to+ - 'to' time for the sql query
|
17
|
+
#
|
18
|
+
# All other variables starting with +var-+ will be used to replace grafana templating strings
|
19
|
+
# in the given SQL query.
|
20
|
+
#
|
21
|
+
# == Supported options
|
22
|
+
# +sql+ - sql statement (*mandatory*)
|
23
|
+
#
|
24
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
25
|
+
#
|
26
|
+
# +from+ - 'from' time for the sql query
|
27
|
+
#
|
28
|
+
# +to+ - 'to' time for the sql query
|
29
|
+
#
|
30
|
+
# +format+ - see {QueryMixin#format_columns}
|
31
|
+
#
|
32
|
+
# +replace_values+ - see {QueryMixin#replace_values}
|
33
|
+
#
|
34
|
+
# +filter_columns+ - see {QueryMixin#filter_columns}
|
35
|
+
class SqlTableIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
36
|
+
include ProcessorMixin
|
37
|
+
|
38
|
+
# :nodoc:
|
39
|
+
def handles?(target)
|
40
|
+
target.start_with? 'grafana_sql_table:'
|
41
|
+
end
|
42
|
+
|
43
|
+
# :nodoc:
|
44
|
+
def process(doc, reader, target, attrs)
|
45
|
+
return if @report.cancel
|
46
|
+
|
47
|
+
@report.next_step
|
48
|
+
instance = attrs['instance'] || doc.attr('grafana_default_instance') || 'default'
|
49
|
+
@report.logger.debug("Processing SqlTableIncludeProcessor (instance: #{instance},"\
|
50
|
+
" datasource: #{target.split(':')[1]}, sql: #{attrs['sql']})")
|
51
|
+
query = SqlTableQuery.new(attrs['sql'], target.split(':')[1])
|
52
|
+
query.merge_hash_variables(doc.attributes, attrs)
|
53
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
54
|
+
|
55
|
+
begin
|
56
|
+
reader.unshift_lines query.execute(@report.grafana(instance))
|
57
|
+
rescue GrafanaReporterError => e
|
58
|
+
@report.logger.error(e.message)
|
59
|
+
reader.unshift_line "|#{e.message}"
|
60
|
+
rescue StandardError => e
|
61
|
+
@report.logger.fatal(e.message)
|
62
|
+
reader.unshift_line "|#{e.message}"
|
63
|
+
end
|
64
|
+
|
65
|
+
reader
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|