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,86 +1,91 @@
|
|
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
|
-
@report.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
@report.
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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_annotations[<options>]
|
10
|
+
#
|
11
|
+
# Returns the results of alerts 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
|
+
# == Supported options
|
23
|
+
# +columns+ - see {AnnotationsTableQuery#pre_process} (*mandatory*)
|
24
|
+
#
|
25
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
26
|
+
#
|
27
|
+
# +dashboard+ - uid of grafana dashboard to query for, empty string if no filter is wanted
|
28
|
+
#
|
29
|
+
# +panel+ - id of the panel to query for
|
30
|
+
#
|
31
|
+
# +from+ - 'from' time for the sql query
|
32
|
+
#
|
33
|
+
# +to+ - 'to' time for the sql query
|
34
|
+
#
|
35
|
+
# +format+ - see {QueryMixin#format_columns}
|
36
|
+
#
|
37
|
+
# +replace_values+ - see {QueryMixin#replace_values}
|
38
|
+
#
|
39
|
+
# +filter_columns+ - see {QueryMixin#filter_columns}
|
40
|
+
class AnnotationsTableIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
41
|
+
include ProcessorMixin
|
42
|
+
|
43
|
+
# :nodoc:
|
44
|
+
def handles?(target)
|
45
|
+
target.start_with? 'grafana_annotations'
|
46
|
+
end
|
47
|
+
|
48
|
+
# :nodoc:
|
49
|
+
def process(doc, reader, _target, attrs)
|
50
|
+
return if @report.cancel
|
51
|
+
|
52
|
+
@report.next_step
|
53
|
+
instance = attrs['instance'] || doc.attr('grafana_default_instance') || 'default'
|
54
|
+
dashboard_id = attrs['dashboard'] || doc.attr('grafana_default_dashboard')
|
55
|
+
panel_id = attrs['panel']
|
56
|
+
@report.logger.debug("Processing AnnotationsTableIncludeProcessor (instance: #{instance})")
|
57
|
+
|
58
|
+
query = if dashboard_id.to_s.empty?
|
59
|
+
# no dashboard shall be used, so also the panel will be omitted
|
60
|
+
AnnotationsTableQuery.new
|
61
|
+
elsif panel_id.to_s.empty?
|
62
|
+
# a dashboard is given, but no panel, so set filter for dashboard only
|
63
|
+
AnnotationsTableQuery.new(dashboard: @report.grafana(instance).dashboard(dashboard_id))
|
64
|
+
else
|
65
|
+
# dashboard and panel is given, so set filter for panel
|
66
|
+
AnnotationsTableQuery.new(panel: @report.grafana(instance).dashboard(dashboard_id).panel(panel_id))
|
67
|
+
end
|
68
|
+
|
69
|
+
query.merge_hash_variables(doc.attributes, attrs)
|
70
|
+
selected_attrs = attrs.select do |k, _v|
|
71
|
+
k =~ /(?:columns|limit|alertId|dashboardId|panelId|userId|type|tags)/
|
72
|
+
end
|
73
|
+
query.merge_variables(selected_attrs.transform_values { |item| ::Grafana::Variable.new(item) })
|
74
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
75
|
+
|
76
|
+
begin
|
77
|
+
reader.unshift_lines query.execute(@report.grafana(instance))
|
78
|
+
rescue GrafanaReporterError => e
|
79
|
+
@report.logger.error(e.message)
|
80
|
+
reader.unshift_line "|#{e.message}"
|
81
|
+
rescue StandardError => e
|
82
|
+
@report.logger.fatal(e.message)
|
83
|
+
reader.unshift_line "|#{e.message}"
|
84
|
+
end
|
85
|
+
|
86
|
+
reader
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -1,67 +1,69 @@
|
|
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
|
-
@report.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
@report.
|
54
|
-
|
55
|
-
rescue
|
56
|
-
@report.logger.
|
57
|
-
return create_paragraph(parent, e.message, attrs)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
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_image::<panel_id>[<options>]
|
10
|
+
#
|
11
|
+
# Stores the queried panel as a temporary image file and returns an asciidoctor link
|
12
|
+
# to be included in the report.
|
13
|
+
#
|
14
|
+
# == Used document parameters
|
15
|
+
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
16
|
+
#
|
17
|
+
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
18
|
+
#
|
19
|
+
# +from+ - 'from' time for the sql query
|
20
|
+
#
|
21
|
+
# +to+ - 'to' time for the sql query
|
22
|
+
#
|
23
|
+
# == Supported options
|
24
|
+
# +field+ - property to query for, e.g. +description+ or +title+ (*mandatory*)
|
25
|
+
#
|
26
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
27
|
+
#
|
28
|
+
# +dashboard+ - uid of grafana dashboard to use
|
29
|
+
#
|
30
|
+
# +from+ - 'from' time for the sql query
|
31
|
+
#
|
32
|
+
# +to+ - 'to' time for the sql query
|
33
|
+
class PanelImageBlockMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
|
34
|
+
include ProcessorMixin
|
35
|
+
use_dsl
|
36
|
+
|
37
|
+
named :grafana_panel_image
|
38
|
+
|
39
|
+
# :nodoc:
|
40
|
+
def process(parent, target, attrs)
|
41
|
+
return if @report.cancel
|
42
|
+
|
43
|
+
@report.next_step
|
44
|
+
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
45
|
+
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
46
|
+
@report.logger.debug("Processing PanelImageBlockMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
47
|
+
" panel: #{target})")
|
48
|
+
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target))
|
49
|
+
query.merge_hash_variables(parent.document.attributes, attrs)
|
50
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
51
|
+
|
52
|
+
begin
|
53
|
+
image = query.execute(@report.grafana(instance))
|
54
|
+
image_path = @report.save_image_file(image)
|
55
|
+
rescue GrafanaReporterError => e
|
56
|
+
@report.logger.error(e.message)
|
57
|
+
return create_paragraph(parent, e.message, attrs)
|
58
|
+
rescue StandardError => e
|
59
|
+
@report.logger.fatal(e.message)
|
60
|
+
return create_paragraph(parent, e.message, attrs)
|
61
|
+
end
|
62
|
+
|
63
|
+
attrs['target'] = image_path
|
64
|
+
create_image_block(parent, attrs)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,65 +1,68 @@
|
|
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
|
-
@report.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
@report.
|
54
|
-
|
55
|
-
rescue
|
56
|
-
@report.logger.
|
57
|
-
return create_inline(parent, :quoted, e.message)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
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_image:<panel_id>[<options>]
|
10
|
+
#
|
11
|
+
# Stores the queried panel as a temporary image file and returns an asciidoctor link
|
12
|
+
# to be included in the report.
|
13
|
+
#
|
14
|
+
# == Used document parameters
|
15
|
+
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
16
|
+
#
|
17
|
+
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
18
|
+
#
|
19
|
+
# +from+ - 'from' time for the sql query
|
20
|
+
#
|
21
|
+
# +to+ - 'to' time for the sql query
|
22
|
+
#
|
23
|
+
# == Supported options
|
24
|
+
# +field+ - property to query for, e.g. +description+ or +title+ (*mandatory*)
|
25
|
+
#
|
26
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
27
|
+
#
|
28
|
+
# +dashboard+ - uid of grafana dashboard to use
|
29
|
+
#
|
30
|
+
# +from+ - 'from' time for the sql query
|
31
|
+
#
|
32
|
+
# +to+ - 'to' time for the sql query
|
33
|
+
class PanelImageInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
34
|
+
include ProcessorMixin
|
35
|
+
use_dsl
|
36
|
+
|
37
|
+
named :grafana_panel_image
|
38
|
+
|
39
|
+
# :nodoc:
|
40
|
+
def process(parent, target, attrs)
|
41
|
+
return if @report.cancel
|
42
|
+
|
43
|
+
@report.next_step
|
44
|
+
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
45
|
+
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
46
|
+
@report.logger.debug("Processing PanelImageInlineMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
47
|
+
" panel: #{target})")
|
48
|
+
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target))
|
49
|
+
query.merge_hash_variables(parent.document.attributes, attrs)
|
50
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
51
|
+
|
52
|
+
begin
|
53
|
+
image = query.execute(@report.grafana(instance))
|
54
|
+
image_path = @report.save_image_file(image)
|
55
|
+
rescue GrafanaReporterError => e
|
56
|
+
@report.logger.error(e.message)
|
57
|
+
return create_inline(parent, :quoted, e.message)
|
58
|
+
rescue StandardError => e
|
59
|
+
@report.logger.fatal(e.message)
|
60
|
+
return create_inline(parent, :quoted, e.message)
|
61
|
+
end
|
62
|
+
|
63
|
+
create_inline(parent, :image, nil, { target: image_path, attributes: attrs })
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,58 +1,61 @@
|
|
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
|
-
@report.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
rescue
|
47
|
-
@report.logger.
|
48
|
-
return create_inline(parent, :quoted, e.message)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
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_property:<panel_id>[<options>]
|
10
|
+
#
|
11
|
+
# Returns the requested panel property.
|
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
|
+
# == Supported options
|
19
|
+
# +field+ - property to query for, e.g. +description+ or +title+ (*mandatory*)
|
20
|
+
#
|
21
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
22
|
+
#
|
23
|
+
# +dashboard+ - uid of grafana dashboard to use
|
24
|
+
class PanelPropertyInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
25
|
+
include ProcessorMixin
|
26
|
+
use_dsl
|
27
|
+
|
28
|
+
named :grafana_panel_property
|
29
|
+
name_positional_attributes :field
|
30
|
+
|
31
|
+
# :nodoc:
|
32
|
+
def process(parent, target, attrs)
|
33
|
+
return if @report.cancel
|
34
|
+
|
35
|
+
@report.next_step
|
36
|
+
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
37
|
+
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
38
|
+
@report.logger.debug("Processing PanelPropertyInlineMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
39
|
+
" panel: #{target}, property: #{attrs[:field]})")
|
40
|
+
query = PanelPropertyQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target), attrs[:field])
|
41
|
+
query.merge_hash_variables(parent.document.attributes, attrs)
|
42
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
43
|
+
|
44
|
+
begin
|
45
|
+
description = query.execute(@report.grafana(instance))
|
46
|
+
rescue GrafanaReporterError => e
|
47
|
+
@report.logger.error(e.message)
|
48
|
+
return create_inline(parent, :quoted, e.message)
|
49
|
+
rescue StandardError => e
|
50
|
+
@report.logger.fatal(e.message)
|
51
|
+
return create_inline(parent, :quoted, e.message)
|
52
|
+
end
|
53
|
+
|
54
|
+
# translate linebreaks to asciidoctor syntax
|
55
|
+
# and HTML encode to make sure, that HTML formattings are respected
|
56
|
+
create_inline(parent, :quoted, CGI.escapeHTML(description.gsub(%r{//[^\n]*(?:\n)?}, '').gsub(/\n/, " +\n")))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|