ruby-grafana-reporter 0.3.0 → 0.4.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 +81 -71
- data/bin/ruby-grafana-reporter +5 -5
- data/lib/VERSION.rb +3 -2
- data/lib/grafana/abstract_datasource.rb +116 -0
- data/lib/grafana/dashboard.rb +1 -3
- data/lib/grafana/errors.rb +15 -0
- data/lib/grafana/grafana.rb +53 -56
- data/lib/grafana/grafana_alerts_datasource.rb +57 -0
- data/lib/grafana/grafana_annotations_datasource.rb +56 -0
- data/lib/grafana/grafana_property_datasource.rb +25 -0
- data/lib/grafana/graphite_datasource.rb +44 -0
- data/lib/grafana/image_rendering_datasource.rb +44 -0
- data/lib/grafana/panel.rb +9 -3
- data/lib/grafana/prometheus_datasource.rb +39 -0
- data/lib/grafana/sql_datasource.rb +65 -0
- data/lib/grafana/variable.rb +1 -0
- data/lib/grafana/webrequest.rb +71 -0
- data/lib/grafana_reporter/abstract_query.rb +401 -0
- data/lib/grafana_reporter/abstract_report.rb +54 -3
- data/lib/grafana_reporter/alerts_table_query.rb +44 -0
- data/lib/grafana_reporter/annotations_table_query.rb +43 -0
- data/lib/grafana_reporter/application/application.rb +12 -8
- data/lib/grafana_reporter/application/webservice.rb +18 -6
- data/lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb +90 -0
- data/lib/grafana_reporter/asciidoctor/annotations_table_include_processor.rb +89 -0
- data/lib/grafana_reporter/asciidoctor/panel_image_block_macro.rb +76 -0
- data/lib/grafana_reporter/asciidoctor/panel_image_inline_macro.rb +77 -0
- data/lib/grafana_reporter/asciidoctor/panel_property_inline_macro.rb +72 -0
- data/lib/grafana_reporter/asciidoctor/panel_query_table_include_processor.rb +98 -0
- data/lib/grafana_reporter/asciidoctor/panel_query_value_inline_macro.rb +93 -0
- data/lib/grafana_reporter/asciidoctor/processor_mixin.rb +23 -0
- data/lib/grafana_reporter/asciidoctor/report.rb +24 -31
- data/lib/grafana_reporter/asciidoctor/show_environment_include_processor.rb +46 -0
- data/lib/grafana_reporter/asciidoctor/show_help_include_processor.rb +35 -0
- data/lib/grafana_reporter/asciidoctor/sql_table_include_processor.rb +92 -0
- data/lib/grafana_reporter/asciidoctor/sql_value_inline_macro.rb +88 -0
- data/lib/grafana_reporter/asciidoctor/value_as_variable_include_processor.rb +90 -0
- data/lib/grafana_reporter/configuration.rb +12 -6
- data/lib/grafana_reporter/console_configuration_wizard.rb +115 -65
- data/lib/grafana_reporter/demo_report_wizard.rb +87 -0
- data/lib/grafana_reporter/errors.rb +33 -0
- data/lib/grafana_reporter/help.rb +447 -0
- data/lib/grafana_reporter/logger/two_way_logger.rb +1 -1
- data/lib/grafana_reporter/panel_image_query.rb +29 -0
- data/lib/grafana_reporter/panel_property_query.rb +22 -0
- data/lib/grafana_reporter/query_value_query.rb +79 -0
- data/lib/grafana_reporter/report_webhook.rb +35 -0
- data/lib/{ruby-grafana-reporter.rb → ruby_grafana_reporter.rb} +0 -3
- metadata +37 -35
- data/lib/grafana/abstract_panel_query.rb +0 -22
- data/lib/grafana/abstract_query.rb +0 -132
- data/lib/grafana/abstract_sql_query.rb +0 -51
- data/lib/grafana/panel_image_query.rb +0 -52
- data/lib/grafana_reporter/asciidoctor/alerts_table_query.rb +0 -101
- data/lib/grafana_reporter/asciidoctor/annotations_table_query.rb +0 -96
- data/lib/grafana_reporter/asciidoctor/errors.rb +0 -40
- data/lib/grafana_reporter/asciidoctor/extensions/alerts_table_include_processor.rb +0 -92
- data/lib/grafana_reporter/asciidoctor/extensions/annotations_table_include_processor.rb +0 -91
- data/lib/grafana_reporter/asciidoctor/extensions/panel_image_block_macro.rb +0 -69
- data/lib/grafana_reporter/asciidoctor/extensions/panel_image_inline_macro.rb +0 -68
- data/lib/grafana_reporter/asciidoctor/extensions/panel_property_inline_macro.rb +0 -61
- data/lib/grafana_reporter/asciidoctor/extensions/panel_query_table_include_processor.rb +0 -78
- data/lib/grafana_reporter/asciidoctor/extensions/panel_query_value_inline_macro.rb +0 -73
- data/lib/grafana_reporter/asciidoctor/extensions/processor_mixin.rb +0 -20
- data/lib/grafana_reporter/asciidoctor/extensions/show_environment_include_processor.rb +0 -43
- data/lib/grafana_reporter/asciidoctor/extensions/show_help_include_processor.rb +0 -30
- data/lib/grafana_reporter/asciidoctor/extensions/sql_table_include_processor.rb +0 -70
- data/lib/grafana_reporter/asciidoctor/extensions/sql_value_inline_macro.rb +0 -66
- data/lib/grafana_reporter/asciidoctor/extensions/value_as_variable_include_processor.rb +0 -88
- data/lib/grafana_reporter/asciidoctor/help.rb +0 -435
- data/lib/grafana_reporter/asciidoctor/panel_first_value_query.rb +0 -36
- data/lib/grafana_reporter/asciidoctor/panel_image_query.rb +0 -28
- data/lib/grafana_reporter/asciidoctor/panel_property_query.rb +0 -44
- data/lib/grafana_reporter/asciidoctor/panel_table_query.rb +0 -40
- data/lib/grafana_reporter/asciidoctor/query_mixin.rb +0 -312
- data/lib/grafana_reporter/asciidoctor/sql_first_value_query.rb +0 -42
- data/lib/grafana_reporter/asciidoctor/sql_table_query.rb +0 -44
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'processor_mixin'
|
4
|
+
|
5
|
+
module GrafanaReporter
|
6
|
+
module Asciidoctor
|
7
|
+
# Implements the hook
|
8
|
+
# grafana_panel_image:<panel_id>[<options>]
|
9
|
+
#
|
10
|
+
# Stores the queried panel as a temporary image file and returns an asciidoctor link
|
11
|
+
# to be included in the report.
|
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
|
+
# +field+ - property to query for, e.g. +description+ or +title+ (*mandatory*)
|
24
|
+
#
|
25
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
26
|
+
#
|
27
|
+
# +dashboard+ - uid of grafana dashboard to use
|
28
|
+
#
|
29
|
+
# +from+ - 'from' time for the sql query
|
30
|
+
#
|
31
|
+
# +to+ - 'to' time for the sql query
|
32
|
+
class PanelImageInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
33
|
+
include ProcessorMixin
|
34
|
+
use_dsl
|
35
|
+
|
36
|
+
named :grafana_panel_image
|
37
|
+
|
38
|
+
# :nodoc:
|
39
|
+
def process(parent, target, attrs)
|
40
|
+
return if @report.cancel
|
41
|
+
|
42
|
+
@report.next_step
|
43
|
+
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
44
|
+
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
45
|
+
@report.logger.debug("Processing PanelImageInlineMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
46
|
+
" panel: #{target})")
|
47
|
+
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target))
|
48
|
+
# set alt text to a default, because otherwise asciidoctor fails
|
49
|
+
attrs['alt'] = '' unless attrs['alt']
|
50
|
+
query.merge_hash_variables(parent.document.attributes, attrs)
|
51
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
52
|
+
|
53
|
+
begin
|
54
|
+
image = query.execute
|
55
|
+
image_path = @report.save_image_file(image)
|
56
|
+
rescue GrafanaReporterError => e
|
57
|
+
@report.logger.error(e.message)
|
58
|
+
return create_inline(parent, :quoted, e.message)
|
59
|
+
rescue StandardError => e
|
60
|
+
@report.logger.fatal(e.message)
|
61
|
+
return create_inline(parent, :quoted, e.message)
|
62
|
+
end
|
63
|
+
|
64
|
+
create_inline(parent, :image, nil, { target: image_path, attributes: attrs })
|
65
|
+
end
|
66
|
+
|
67
|
+
# @see ProcessorMixin#build_demo_entry
|
68
|
+
def build_demo_entry(panel)
|
69
|
+
return nil unless panel
|
70
|
+
return nil unless panel.model['type'] == 'graph'
|
71
|
+
|
72
|
+
"see here: grafana_panel_image:#{panel.id}[dashboard=\"#{panel.dashboard.id}\","\
|
73
|
+
'width="90%"] - a working inline image'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'processor_mixin'
|
4
|
+
|
5
|
+
module GrafanaReporter
|
6
|
+
module Asciidoctor
|
7
|
+
# Implements the hook
|
8
|
+
# grafana_panel_property:<panel_id>[<options>]
|
9
|
+
#
|
10
|
+
# Returns the requested panel property.
|
11
|
+
#
|
12
|
+
# == Used document parameters
|
13
|
+
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
14
|
+
#
|
15
|
+
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
16
|
+
#
|
17
|
+
# == Supported options
|
18
|
+
# +field+ - property to query for, e.g. +description+ or +title+ (*mandatory*)
|
19
|
+
#
|
20
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
21
|
+
#
|
22
|
+
# +dashboard+ - uid of grafana dashboard to use
|
23
|
+
class PanelPropertyInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
24
|
+
include ProcessorMixin
|
25
|
+
use_dsl
|
26
|
+
|
27
|
+
named :grafana_panel_property
|
28
|
+
name_positional_attributes :field
|
29
|
+
|
30
|
+
# :nodoc:
|
31
|
+
def process(parent, target, attrs)
|
32
|
+
return if @report.cancel
|
33
|
+
|
34
|
+
@report.next_step
|
35
|
+
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
36
|
+
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
37
|
+
@report.logger.debug("Processing PanelPropertyInlineMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
38
|
+
" panel: #{target}, property: #{attrs[:field]})")
|
39
|
+
|
40
|
+
begin
|
41
|
+
query = PanelPropertyQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target))
|
42
|
+
query.raw_query = { property_name: attrs[:field] }
|
43
|
+
query.merge_hash_variables(parent.document.attributes, attrs)
|
44
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
45
|
+
|
46
|
+
description = query.execute
|
47
|
+
rescue GrafanaReporterError => e
|
48
|
+
@report.logger.error(e.message)
|
49
|
+
return create_inline(parent, :quoted, e.message)
|
50
|
+
rescue StandardError => e
|
51
|
+
@report.logger.fatal(e.message)
|
52
|
+
return create_inline(parent, :quoted, e.message)
|
53
|
+
end
|
54
|
+
|
55
|
+
# translate linebreaks to asciidoctor syntax
|
56
|
+
# and HTML encode to make sure, that HTML formattings are respected
|
57
|
+
create_inline(parent, :quoted, CGI.escapeHTML(description.gsub(%r{//[^\n]*(?:\n)?}, '').gsub(/\n/, " +\n")))
|
58
|
+
end
|
59
|
+
|
60
|
+
# @see ProcessorMixin#build_demo_entry
|
61
|
+
def build_demo_entry(panel)
|
62
|
+
return nil unless panel
|
63
|
+
return nil unless panel.model['title']
|
64
|
+
return nil if panel.model['title'].strip == ''
|
65
|
+
return nil if panel.model['title'].strip == 'Panel Title'
|
66
|
+
|
67
|
+
"this text includes the panel with title grafana_panel_property:#{panel.id}[\"title\","\
|
68
|
+
"dashboard=\"#{panel.dashboard.id}\"]"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'processor_mixin'
|
4
|
+
|
5
|
+
module GrafanaReporter
|
6
|
+
module Asciidoctor
|
7
|
+
# Implements the hook
|
8
|
+
# include::grafana_panel_query_table:<panel_id>[<options>]
|
9
|
+
#
|
10
|
+
# Returns the results of the SQL query as a asciidoctor table.
|
11
|
+
#
|
12
|
+
# == Used document parameters
|
13
|
+
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
14
|
+
#
|
15
|
+
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
16
|
+
#
|
17
|
+
# +from+ - 'from' time for the sql query
|
18
|
+
#
|
19
|
+
# +to+ - 'to' time for the sql query
|
20
|
+
#
|
21
|
+
# All other variables starting with +var-+ will be used to replace grafana templating strings
|
22
|
+
# in the given SQL query.
|
23
|
+
#
|
24
|
+
# == Supported options
|
25
|
+
# +query+ - query letter, which shall be used, e.g. +C+ (*mandatory*)
|
26
|
+
#
|
27
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
28
|
+
#
|
29
|
+
# +dashboard+ - uid of grafana dashboard to use
|
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 PanelQueryTableIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
41
|
+
include ProcessorMixin
|
42
|
+
|
43
|
+
# :nodoc:
|
44
|
+
def handles?(target)
|
45
|
+
target.start_with? 'grafana_panel_query_table:'
|
46
|
+
end
|
47
|
+
|
48
|
+
# :nodoc:
|
49
|
+
def process(doc, reader, target, attrs)
|
50
|
+
return if @report.cancel
|
51
|
+
|
52
|
+
@report.next_step
|
53
|
+
panel_id = target.split(':')[1]
|
54
|
+
instance = attrs['instance'] || doc.attr('grafana_default_instance') || 'default'
|
55
|
+
dashboard = attrs['dashboard'] || doc.attr('grafana_default_dashboard')
|
56
|
+
attrs['result_type'] = 'panel_table'
|
57
|
+
@report.logger.debug("Processing PanelQueryTableIncludeProcessor (instance: #{instance}, "\
|
58
|
+
"dashboard: #{dashboard}, panel: #{panel_id}, query: #{attrs['query']})")
|
59
|
+
|
60
|
+
begin
|
61
|
+
panel = @report.grafana(instance).dashboard(dashboard).panel(panel_id)
|
62
|
+
query = QueryValueQuery.new(panel)
|
63
|
+
query.set_defaults_from_dashboard(panel.dashboard)
|
64
|
+
query.merge_hash_variables(doc.attributes, attrs)
|
65
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
66
|
+
|
67
|
+
reader.unshift_lines query.execute
|
68
|
+
rescue GrafanaReporterError => e
|
69
|
+
@report.logger.error(e.message)
|
70
|
+
reader.unshift_line "|#{e.message}"
|
71
|
+
rescue StandardError => e
|
72
|
+
@report.logger.fatal(e.message)
|
73
|
+
reader.unshift_line "|#{e.message}"
|
74
|
+
end
|
75
|
+
|
76
|
+
reader
|
77
|
+
end
|
78
|
+
|
79
|
+
# @see ProcessorMixin#build_demo_entry
|
80
|
+
def build_demo_entry(panel)
|
81
|
+
return nil unless panel
|
82
|
+
return nil unless panel.model['type'].include?('table')
|
83
|
+
|
84
|
+
ref_id = nil
|
85
|
+
panel.model['targets'].each do |item|
|
86
|
+
if !item['hide'] && !panel.query(item['refId']).to_s.empty?
|
87
|
+
ref_id = item['refId']
|
88
|
+
break
|
89
|
+
end
|
90
|
+
end
|
91
|
+
return nil unless ref_id
|
92
|
+
|
93
|
+
"|===\ninclude::grafana_panel_query_table:#{panel.id}[query=\"#{ref_id}\",filter_columns=\"time\","\
|
94
|
+
"dashboard=\"#{panel.dashboard.id}\"]\n|==="
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'processor_mixin'
|
4
|
+
|
5
|
+
module GrafanaReporter
|
6
|
+
module Asciidoctor
|
7
|
+
# Implements the hook
|
8
|
+
# grafana_panel_query_value:<panel_id>[<options>]
|
9
|
+
#
|
10
|
+
# Returns the first value of the resulting SQL query.
|
11
|
+
#
|
12
|
+
# == Used document parameters
|
13
|
+
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
14
|
+
#
|
15
|
+
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
16
|
+
#
|
17
|
+
# +from+ - 'from' time for the sql query
|
18
|
+
#
|
19
|
+
# +to+ - 'to' time for the sql query
|
20
|
+
#
|
21
|
+
# All other variables starting with +var-+ will be used to replace grafana templating strings
|
22
|
+
# in the given SQL query.
|
23
|
+
#
|
24
|
+
# == Supported options
|
25
|
+
# +query+ - query letter, which shall be used, e.g. +C+ (*mandatory*)
|
26
|
+
#
|
27
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
28
|
+
#
|
29
|
+
# +dashboard+ - uid of grafana dashboard to use
|
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 PanelQueryValueInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
41
|
+
include ProcessorMixin
|
42
|
+
use_dsl
|
43
|
+
|
44
|
+
named :grafana_panel_query_value
|
45
|
+
|
46
|
+
# :nodoc:
|
47
|
+
def process(parent, target, attrs)
|
48
|
+
return if @report.cancel
|
49
|
+
|
50
|
+
@report.next_step
|
51
|
+
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
52
|
+
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
53
|
+
attrs['result_type'] = 'panel_value'
|
54
|
+
@report.logger.debug("Processing PanelQueryValueInlineMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
55
|
+
" panel: #{target}, query: #{attrs['query']})")
|
56
|
+
|
57
|
+
begin
|
58
|
+
panel = @report.grafana(instance).dashboard(dashboard).panel(target)
|
59
|
+
query = QueryValueQuery.new(panel)
|
60
|
+
query.set_defaults_from_dashboard(panel.dashboard)
|
61
|
+
query.merge_hash_variables(parent.document.attributes, attrs)
|
62
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
63
|
+
|
64
|
+
create_inline(parent, :quoted, query.execute)
|
65
|
+
rescue GrafanaReporterError => e
|
66
|
+
@report.logger.error(e.message)
|
67
|
+
create_inline(parent, :quoted, e.message)
|
68
|
+
rescue StandardError => e
|
69
|
+
@report.logger.fatal(e.message)
|
70
|
+
create_inline(parent, :quoted, e.message)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# @see ProcessorMixin#build_demo_entry
|
75
|
+
def build_demo_entry(panel)
|
76
|
+
return nil unless panel
|
77
|
+
return nil unless panel.model['type'] == 'singlestat'
|
78
|
+
|
79
|
+
ref_id = nil
|
80
|
+
panel.model['targets'].each do |item|
|
81
|
+
if !item['hide'] && !panel.query(item['refId']).to_s.empty?
|
82
|
+
ref_id = item['refId']
|
83
|
+
break
|
84
|
+
end
|
85
|
+
end
|
86
|
+
return nil unless ref_id
|
87
|
+
|
88
|
+
"it's easily possible to include the query value: grafana_panel_query_value:#{panel.id}[query=\"#{ref_id}\""\
|
89
|
+
",dashboard=\"#{panel.dashboard.id}\"] - just within this text."
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
module Asciidoctor
|
5
|
+
# This module contains common methods for all asciidoctor extensions.
|
6
|
+
module ProcessorMixin
|
7
|
+
# Used when initializing a object instance, to set the report object, which is currently in progress.
|
8
|
+
# @param report [GrafanaReporter::Asciidoctor::Report] current report
|
9
|
+
# @return [::Asciidoctor::Extensions::Processor] self
|
10
|
+
def current_report(report)
|
11
|
+
@report = report
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
# This method is called if a demo report shall be built for the given {Panel}.
|
16
|
+
# @param panel [Panel] panel object, for which a demo entry shall be created.
|
17
|
+
# @return [String] String containing the entry, or nil if not possible for given panel
|
18
|
+
def build_demo_entry(panel)
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module GrafanaReporter
|
4
|
+
# This module contains all classes, which are necessary to use the reporter in conjunction with asciidoctor.
|
4
5
|
module Asciidoctor
|
5
6
|
# Implementation of a specific {AbstractReport}. It is used to
|
6
7
|
# build reports specifically for asciidoctor results.
|
7
|
-
class Report < GrafanaReporter::AbstractReport
|
8
|
+
class Report < ::GrafanaReporter::AbstractReport
|
8
9
|
# (see AbstractReport#initialize)
|
9
10
|
def initialize(config, template, destination_file_or_path = nil, custom_attributes = {})
|
10
11
|
super
|
@@ -18,10 +19,9 @@ module GrafanaReporter
|
|
18
19
|
# @see AbstractReport#create_report
|
19
20
|
# @return [void]
|
20
21
|
def create_report
|
21
|
-
|
22
|
+
super
|
22
23
|
attrs = { 'convert-backend' => 'pdf' }.merge(@config.default_document_attributes.merge(@custom_attributes))
|
23
24
|
attrs['grafana-report-timestamp'] = @start_time.to_s
|
24
|
-
logger.info("Report started at #{@start_time}")
|
25
25
|
logger.debug("Document attributes: #{attrs}")
|
26
26
|
|
27
27
|
initialize_step_counter
|
@@ -30,19 +30,18 @@ module GrafanaReporter
|
|
30
30
|
::Asciidoctor::LoggerManager.logger = logger
|
31
31
|
|
32
32
|
registry = ::Asciidoctor::Extensions::Registry.new
|
33
|
-
|
34
|
-
registry.inline_macro
|
35
|
-
registry.inline_macro
|
36
|
-
registry.inline_macro
|
37
|
-
registry.
|
38
|
-
registry.
|
39
|
-
registry.include_processor
|
40
|
-
registry.include_processor
|
41
|
-
registry.include_processor
|
42
|
-
registry.include_processor
|
43
|
-
registry.include_processor
|
44
|
-
registry.include_processor
|
45
|
-
registry.include_processor Extensions::AlertsTableIncludeProcessor.new.current_report(self)
|
33
|
+
registry.inline_macro PanelImageInlineMacro.new.current_report(self)
|
34
|
+
registry.inline_macro PanelQueryValueInlineMacro.new.current_report(self)
|
35
|
+
registry.inline_macro PanelPropertyInlineMacro.new.current_report(self)
|
36
|
+
registry.inline_macro SqlValueInlineMacro.new.current_report(self)
|
37
|
+
registry.block_macro PanelImageBlockMacro.new.current_report(self)
|
38
|
+
registry.include_processor ValueAsVariableIncludeProcessor.new.current_report(self)
|
39
|
+
registry.include_processor PanelQueryTableIncludeProcessor.new.current_report(self)
|
40
|
+
registry.include_processor SqlTableIncludeProcessor.new.current_report(self)
|
41
|
+
registry.include_processor ShowEnvironmentIncludeProcessor.new.current_report(self)
|
42
|
+
registry.include_processor ShowHelpIncludeProcessor.new.current_report(self)
|
43
|
+
registry.include_processor AnnotationsTableIncludeProcessor.new.current_report(self)
|
44
|
+
registry.include_processor AlertsTableIncludeProcessor.new.current_report(self)
|
46
45
|
|
47
46
|
::Asciidoctor.convert_file(@template, extension_registry: registry, backend: attrs['convert-backend'],
|
48
47
|
to_file: path, attributes: attrs, header_footer: true)
|
@@ -51,15 +50,11 @@ module GrafanaReporter
|
|
51
50
|
|
52
51
|
# store report including als images as ZIP file, if the result is not a PDF
|
53
52
|
if attrs['convert-backend'] != 'pdf'
|
54
|
-
dest_path =
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
dest_path = @destination_file_or_path.path
|
60
|
-
else
|
61
|
-
dest_path = @destination_file_or_path
|
62
|
-
end
|
53
|
+
dest_path = if @destination_file_or_path.is_a?(File) || @destination_file_or_path.is_a?(Tempfile)
|
54
|
+
@destination_file_or_path.path
|
55
|
+
else
|
56
|
+
@destination_file_or_path
|
57
|
+
end
|
63
58
|
|
64
59
|
# build zip file
|
65
60
|
zip_file = Tempfile.new('gf_zip')
|
@@ -92,9 +87,7 @@ module GrafanaReporter
|
|
92
87
|
end
|
93
88
|
|
94
89
|
clean_image_files
|
95
|
-
|
96
|
-
logger.info("Report finished after #{@end_time - @start_time} seconds.")
|
97
|
-
@done = true
|
90
|
+
done!
|
98
91
|
rescue StandardError => e
|
99
92
|
# catch all errors during execution
|
100
93
|
died_with_error(e)
|
@@ -115,7 +108,7 @@ module GrafanaReporter
|
|
115
108
|
unless @grafana_instances[instance]
|
116
109
|
@grafana_instances[instance] = ::Grafana::Grafana.new(@config.grafana_host(instance),
|
117
110
|
@config.grafana_api_key(instance),
|
118
|
-
logger: @logger
|
111
|
+
logger: @logger)
|
119
112
|
end
|
120
113
|
@grafana_instances[instance]
|
121
114
|
end
|
@@ -147,8 +140,7 @@ module GrafanaReporter
|
|
147
140
|
# @return [void]
|
148
141
|
def died_with_error(error)
|
149
142
|
@error = [error.message] << [error.backtrace]
|
150
|
-
|
151
|
-
@done = true
|
143
|
+
done!
|
152
144
|
end
|
153
145
|
|
154
146
|
private
|
@@ -162,6 +154,7 @@ module GrafanaReporter
|
|
162
154
|
@total_steps = 0
|
163
155
|
File.readlines(@template).each do |line|
|
164
156
|
begin
|
157
|
+
# TODO: move these calls to the specific processors to ensure all are counted properly
|
165
158
|
@total_steps += line.gsub(%r{//.*}, '').scan(/(?:grafana_panel_image|grafana_panel_query_value|
|
166
159
|
grafana_panel_query_table|grafana_sql_value|
|
167
160
|
grafana_sql_table|grafana_environment|grafana_help|
|