ruby-grafana-reporter 0.4.1 → 0.4.2
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 +203 -185
- data/lib/VERSION.rb +2 -2
- data/lib/grafana/abstract_datasource.rb +25 -15
- data/lib/grafana/errors.rb +10 -2
- data/lib/grafana/grafana.rb +2 -0
- data/lib/grafana/grafana_property_datasource.rb +5 -0
- data/lib/grafana/graphite_datasource.rb +27 -5
- data/lib/grafana/influxdb_datasource.rb +70 -0
- data/lib/grafana/prometheus_datasource.rb +27 -5
- data/lib/grafana/sql_datasource.rb +9 -2
- data/lib/grafana/variable.rb +0 -1
- data/lib/grafana_reporter/abstract_query.rb +124 -23
- data/lib/grafana_reporter/abstract_report.rb +21 -2
- data/lib/grafana_reporter/alerts_table_query.rb +1 -6
- data/lib/grafana_reporter/annotations_table_query.rb +1 -6
- data/lib/grafana_reporter/application/webservice.rb +1 -1
- data/lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb +5 -4
- data/lib/grafana_reporter/asciidoctor/annotations_table_include_processor.rb +5 -4
- data/lib/grafana_reporter/asciidoctor/panel_image_block_macro.rb +1 -4
- data/lib/grafana_reporter/asciidoctor/panel_image_inline_macro.rb +1 -4
- data/lib/grafana_reporter/asciidoctor/panel_property_inline_macro.rb +1 -4
- data/lib/grafana_reporter/asciidoctor/panel_query_table_include_processor.rb +1 -5
- data/lib/grafana_reporter/asciidoctor/panel_query_value_inline_macro.rb +1 -4
- data/lib/grafana_reporter/asciidoctor/processor_mixin.rb +20 -35
- data/lib/grafana_reporter/asciidoctor/report.rb +2 -14
- data/lib/grafana_reporter/asciidoctor/sql_table_include_processor.rb +1 -3
- data/lib/grafana_reporter/asciidoctor/sql_value_inline_macro.rb +1 -3
- data/lib/grafana_reporter/demo_report_wizard.rb +5 -1
- data/lib/grafana_reporter/erb/report.rb +3 -16
- data/lib/grafana_reporter/erb/report_jail.rb +21 -0
- data/lib/grafana_reporter/errors.rb +14 -0
- data/lib/grafana_reporter/help.rb +2 -2
- data/lib/grafana_reporter/panel_image_query.rb +1 -5
- data/lib/grafana_reporter/query_value_query.rb +1 -19
- data/lib/ruby_grafana_reporter.rb +0 -12
- metadata +4 -2
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module GrafanaReporter
|
4
|
-
# @abstract Override {#
|
4
|
+
# @abstract Override {#build} and {#progress}.
|
5
5
|
#
|
6
6
|
# This class is used to build a report on basis of a given configuration and
|
7
7
|
# template.
|
@@ -124,7 +124,8 @@ module GrafanaReporter
|
|
124
124
|
logger.internal_messages
|
125
125
|
end
|
126
126
|
|
127
|
-
# Is being called to start the report generation.
|
127
|
+
# Is being called to start the report generation. To execute the specific report generation, this function
|
128
|
+
# calls the abstract {#build} method with the given parameters.
|
128
129
|
# @param template [String] path to the template to be used, trailing +.adoc+ extension may be omitted
|
129
130
|
# @param destination_file_or_path [String or File] path to the destination report or file object to use
|
130
131
|
# @param custom_attributes [Hash] custom attributes, which shall be merged with priority over the configuration
|
@@ -142,6 +143,24 @@ module GrafanaReporter
|
|
142
143
|
notify(:on_before_create)
|
143
144
|
@start_time = Time.new
|
144
145
|
logger.info("Report started at #{@start_time}")
|
146
|
+
build(template, destination_file_or_path, custom_attributes)
|
147
|
+
rescue MissingTemplateError => e
|
148
|
+
@logger.error(e.message)
|
149
|
+
@error = [e.message]
|
150
|
+
done!
|
151
|
+
raise e
|
152
|
+
rescue StandardError => e
|
153
|
+
# catch all errors during execution
|
154
|
+
died_with_error(e)
|
155
|
+
raise e
|
156
|
+
ensure
|
157
|
+
done!
|
158
|
+
end
|
159
|
+
|
160
|
+
# @abstract
|
161
|
+
# Needs to be overridden by the report implementation.
|
162
|
+
def build(template, destination_file_or_path, custom_attributes)
|
163
|
+
raise NotImplementedError
|
145
164
|
end
|
146
165
|
|
147
166
|
# Used to calculate the progress of a report. By default expects +@total_steps+ to contain the total
|
@@ -19,10 +19,6 @@ module GrafanaReporter
|
|
19
19
|
def pre_process
|
20
20
|
raise MissingMandatoryAttributeError, 'columns' unless @raw_query['columns']
|
21
21
|
|
22
|
-
@from = translate_date(@from, @variables['grafana_report_timestamp'], false, @variables['from_timezone'] ||
|
23
|
-
@variables['grafana_default_from_timezone'])
|
24
|
-
@to = translate_date(@to, @variables['grafana_report_timestamp'], true, @variables['to_timezone'] ||
|
25
|
-
@variables['grafana_default_to_timezone'])
|
26
22
|
@datasource = Grafana::GrafanaAlertsDatasource.new(nil)
|
27
23
|
end
|
28
24
|
|
@@ -37,8 +33,7 @@ module GrafanaReporter
|
|
37
33
|
@result = replace_values(@result, @variables.select { |k, _v| k =~ /^replace_values_\d+/ })
|
38
34
|
@result = filter_columns(@result, @variables['filter_columns'])
|
39
35
|
|
40
|
-
|
41
|
-
@result = @result[:content].map { |row| "| #{row.map { |item| item.to_s.gsub('|', '\\|') }.join(' | ')}" }
|
36
|
+
@result = format_table_output(@result, row_divider: @variables['row_divider'], column_divider: @variables['column_divider'])
|
42
37
|
end
|
43
38
|
end
|
44
39
|
end
|
@@ -18,10 +18,6 @@ module GrafanaReporter
|
|
18
18
|
def pre_process
|
19
19
|
raise MissingMandatoryAttributeError, 'columns' unless @raw_query['columns']
|
20
20
|
|
21
|
-
@from = translate_date(@from, @variables['grafana_report_timestamp'], false, @variables['from_timezone'] ||
|
22
|
-
@variables['grafana_default_from_timezone'])
|
23
|
-
@to = translate_date(@to, @variables['grafana_report_timestamp'], true, @variables['to_timezone'] ||
|
24
|
-
@variables['grafana_default_to_timezone'])
|
25
21
|
@datasource = Grafana::GrafanaAnnotationsDatasource.new(nil)
|
26
22
|
end
|
27
23
|
|
@@ -36,8 +32,7 @@ module GrafanaReporter
|
|
36
32
|
@result = replace_values(@result, @variables.select { |k, _v| k =~ /^replace_values_\d+/ })
|
37
33
|
@result = filter_columns(@result, @variables['filter_columns'])
|
38
34
|
|
39
|
-
|
40
|
-
@result = result[:content].map { |row| "| #{row.map { |item| item.to_s.gsub('|', '\\|') }.join(' | ')}" }
|
35
|
+
@result = format_table_output(@result, row_divider: @variables['row_divider'], column_divider: @variables['column_divider'])
|
41
36
|
end
|
42
37
|
end
|
43
38
|
end
|
@@ -84,7 +84,7 @@ module GrafanaReporter
|
|
84
84
|
@logger.debug(e.message)
|
85
85
|
socket.write http_response(404, '', e.message)
|
86
86
|
rescue WebserviceGeneralRenderingError => e
|
87
|
-
@logger.
|
87
|
+
@logger.error(e.message)
|
88
88
|
socket.write http_response(400, 'Bad Request', e.message)
|
89
89
|
rescue StandardError => e
|
90
90
|
@logger.fatal(e.message)
|
@@ -55,18 +55,19 @@ module GrafanaReporter
|
|
55
55
|
@report.logger.debug("Processing AlertsTableIncludeProcessor (instance: #{instance},"\
|
56
56
|
" dashboard: #{dashboard_id}, panel: #{panel_id})")
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
grafana_obj = @report.grafana(instance)
|
59
|
+
grafana_obj = @report.grafana(instance).dashboard(dashboard_id) if dashboard_id
|
60
|
+
grafana_obj = grafana_obj.panel(panel_id) if panel_id
|
61
|
+
|
62
|
+
query = AlertsTableQuery.new(grafana_obj, variables: build_attribute_hash(doc.attributes, attrs))
|
60
63
|
defaults = {}
|
61
64
|
defaults['dashboardId'] = dashboard_id if dashboard_id
|
62
65
|
defaults['panelId'] = panel_id if panel_id
|
63
66
|
|
64
|
-
assign_doc_and_item_variables(query, doc.attributes, attrs)
|
65
67
|
selected_attrs = attrs.select do |k, _v|
|
66
68
|
k =~ /(?:columns|limit|folderId|dashboardId|panelId|dahboardTag|dashboardQuery|state|query)/x
|
67
69
|
end
|
68
70
|
query.raw_query = defaults.merge(selected_attrs.each_with_object({}) { |(k, v), h| h[k] = v })
|
69
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
70
71
|
|
71
72
|
begin
|
72
73
|
reader.unshift_lines query.execute
|
@@ -54,18 +54,19 @@ module GrafanaReporter
|
|
54
54
|
panel_id = attrs['panel']
|
55
55
|
@report.logger.debug("Processing AnnotationsTableIncludeProcessor (instance: #{instance})")
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
grafana_obj = @report.grafana(instance)
|
58
|
+
grafana_obj = @report.grafana(instance).dashboard(dashboard_id) if dashboard_id
|
59
|
+
grafana_obj = grafana_obj.panel(panel_id) if panel_id
|
60
|
+
|
61
|
+
query = AnnotationsTableQuery.new(grafana_obj, variables: build_attribute_hash(doc.attributes, attrs))
|
59
62
|
defaults = {}
|
60
63
|
defaults['dashboardId'] = dashboard_id if dashboard_id
|
61
64
|
defaults['panelId'] = panel_id if panel_id
|
62
65
|
|
63
|
-
assign_doc_and_item_variables(query, doc.attributes, attrs)
|
64
66
|
selected_attrs = attrs.select do |k, _v|
|
65
67
|
k =~ /(?:columns|limit|alertId|dashboardId|panelId|userId|type|tags)/
|
66
68
|
end
|
67
69
|
query.raw_query = defaults.merge(selected_attrs.each_with_object({}) { |(k, v), h| h[k] = v })
|
68
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
69
70
|
|
70
71
|
begin
|
71
72
|
reader.unshift_lines query.execute
|
@@ -46,10 +46,7 @@ module GrafanaReporter
|
|
46
46
|
" panel: #{target})")
|
47
47
|
|
48
48
|
begin
|
49
|
-
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target))
|
50
|
-
assign_dashboard_defaults(query, @report.grafana(instance).dashboard(dashboard))
|
51
|
-
assign_doc_and_item_variables(query, parent.document.attributes, attrs)
|
52
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
49
|
+
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target), variables: build_attribute_hash(parent.document.attributes, attrs))
|
53
50
|
|
54
51
|
image = query.execute
|
55
52
|
image_path = @report.save_image_file(image)
|
@@ -46,12 +46,9 @@ module GrafanaReporter
|
|
46
46
|
" panel: #{target})")
|
47
47
|
|
48
48
|
begin
|
49
|
-
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target))
|
50
49
|
# set alt text to a default, because otherwise asciidoctor fails
|
51
50
|
attrs['alt'] = '' unless attrs['alt']
|
52
|
-
|
53
|
-
assign_doc_and_item_variables(query, parent.document.attributes, attrs)
|
54
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
51
|
+
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target), variables: build_attribute_hash(parent.document.attributes, attrs))
|
55
52
|
|
56
53
|
image = query.execute
|
57
54
|
image_path = @report.save_image_file(image)
|
@@ -38,11 +38,8 @@ module GrafanaReporter
|
|
38
38
|
" panel: #{target}, property: #{attrs[:field]})")
|
39
39
|
|
40
40
|
begin
|
41
|
-
query = PanelPropertyQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target))
|
41
|
+
query = PanelPropertyQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target), variables: build_attribute_hash(parent.document.attributes, attrs))
|
42
42
|
query.raw_query = { property_name: attrs[:field] }
|
43
|
-
assign_dashboard_defaults(query, @report.grafana(instance).dashboard(dashboard))
|
44
|
-
assign_doc_and_item_variables(query, parent.document.attributes, attrs)
|
45
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
46
43
|
|
47
44
|
description = query.execute
|
48
45
|
rescue GrafanaReporterError => e
|
@@ -51,7 +51,6 @@ module GrafanaReporter
|
|
51
51
|
|
52
52
|
@report.next_step
|
53
53
|
panel_id = target.split(':')[1]
|
54
|
-
# TODO: check if instance and dashboard shouldn't be set in assign_doc_and_item_variables method
|
55
54
|
instance = attrs['instance'] || doc.attr('grafana_default_instance') || 'default'
|
56
55
|
dashboard = attrs['dashboard'] || doc.attr('grafana_default_dashboard')
|
57
56
|
attrs['result_type'] = 'panel_table'
|
@@ -60,10 +59,7 @@ module GrafanaReporter
|
|
60
59
|
|
61
60
|
begin
|
62
61
|
panel = @report.grafana(instance).dashboard(dashboard).panel(panel_id)
|
63
|
-
query = QueryValueQuery.new(panel)
|
64
|
-
assign_dashboard_defaults(query, panel.dashboard)
|
65
|
-
assign_doc_and_item_variables(query, doc.attributes, attrs)
|
66
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
62
|
+
query = QueryValueQuery.new(panel, variables: build_attribute_hash(doc.attributes, attrs))
|
67
63
|
|
68
64
|
reader.unshift_lines query.execute
|
69
65
|
rescue GrafanaReporterError => e
|
@@ -56,10 +56,7 @@ module GrafanaReporter
|
|
56
56
|
|
57
57
|
begin
|
58
58
|
panel = @report.grafana(instance).dashboard(dashboard).panel(target)
|
59
|
-
query = QueryValueQuery.new(panel)
|
60
|
-
assign_dashboard_defaults(query, panel.dashboard)
|
61
|
-
assign_doc_and_item_variables(query, parent.document.attributes, attrs)
|
62
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
59
|
+
query = QueryValueQuery.new(panel, variables: build_attribute_hash(parent.document.attributes, attrs))
|
63
60
|
|
64
61
|
create_inline(parent, :quoted, query.execute)
|
65
62
|
rescue GrafanaReporterError => e
|
@@ -19,45 +19,30 @@ module GrafanaReporter
|
|
19
19
|
raise NotImplementedError
|
20
20
|
end
|
21
21
|
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# Following data is extracted:
|
26
|
-
# - +from+, by {Grafana::Dashboard#from_time}
|
27
|
-
# - +to+, by {Grafana::Dashboard#to_time}
|
28
|
-
# - and all variables as {Grafana::Variable}, prefixed with +var-+, as grafana also does it
|
29
|
-
# @param query [AbstractQuery] query object, for which the defaults are set
|
30
|
-
# @param dashboard [Grafana::Dashboard] dashboard from which the defaults are captured
|
31
|
-
# TODO: assign_dashboard_defaults is a common method for all report classes - move it to a public place
|
32
|
-
def assign_dashboard_defaults(query, dashboard)
|
33
|
-
query.from = dashboard.from_time
|
34
|
-
query.to = dashboard.to_time
|
35
|
-
dashboard.variables.each { |item| query.assign_variable("var-#{item.name}", item) }
|
36
|
-
end
|
37
|
-
|
38
|
-
# Merges the given hashes to the given query object. It respects the priorities of the hashes and the
|
39
|
-
# object and allows only valid variables to be passed.
|
40
|
-
# @param query [AbstractQuery] query object, for which the defaults are set
|
22
|
+
# Merges the given hashes to a common attribute Hash. It respects the priorities of the hashes and the
|
23
|
+
# object and allows only valid variables to be used.
|
41
24
|
# @param document_hash [Hash] variables from report template level
|
42
25
|
# @param item_hash [Hash] variables from item configuration level, i.e. specific call, which may override document
|
43
|
-
# @return [
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
26
|
+
# @return [Hash] containing accepted variable names including values
|
27
|
+
def build_attribute_hash(document_hash, item_hash)
|
28
|
+
result = {}
|
29
|
+
|
30
|
+
result['grafana_report_timestamp'] = document_hash['localdatetime']
|
31
|
+
result.merge!(document_hash.select do |k, _v|
|
32
|
+
k =~ /^var-/ ||
|
33
|
+
k =~ /^(?:from|to)$/ ||
|
34
|
+
k =~ /^grafana_default_(?:from_timezone|to_timezone|timeout)$/
|
35
|
+
end)
|
50
36
|
|
51
|
-
|
52
|
-
# TODO: specify accepted options
|
53
|
-
k =~ /^var
|
54
|
-
|
55
|
-
|
56
|
-
|
37
|
+
result.merge!(item_hash.select do |k, _v|
|
38
|
+
# TODO: specify accepted options for each processor class individually
|
39
|
+
k =~ /^(?:var-|render-)/ ||
|
40
|
+
k =~ /^(?:timeout|from|to)$/ ||
|
41
|
+
k =~ /filter_columns|format|replace_values_.*|transpose|column_divider|
|
42
|
+
row_divider|from_timezone|to_timezone|result_type|query/x
|
43
|
+
end)
|
57
44
|
|
58
|
-
|
59
|
-
query.from = item_hash['from'] || document_hash['from'] || query.from
|
60
|
-
query.to = item_hash['to'] || document_hash['to'] || query.to
|
45
|
+
result
|
61
46
|
end
|
62
47
|
end
|
63
48
|
end
|
@@ -14,9 +14,8 @@ module GrafanaReporter
|
|
14
14
|
|
15
15
|
# Starts to create an asciidoctor report. It utilizes all extensions in the {GrafanaReporter::Asciidoctor}
|
16
16
|
# namespace to realize the conversion.
|
17
|
-
# @see AbstractReport#
|
18
|
-
def
|
19
|
-
super
|
17
|
+
# @see AbstractReport#build
|
18
|
+
def build(template, destination_file_or_path, custom_attributes)
|
20
19
|
attrs = { 'convert-backend' => 'pdf' }.merge(@config.default_document_attributes.merge(@custom_attributes))
|
21
20
|
logger.debug("Document attributes: #{attrs}")
|
22
21
|
|
@@ -83,17 +82,6 @@ module GrafanaReporter
|
|
83
82
|
end
|
84
83
|
|
85
84
|
clean_image_files
|
86
|
-
rescue MissingTemplateError => e
|
87
|
-
@logger.error(e.message)
|
88
|
-
@error = [e.message]
|
89
|
-
done!
|
90
|
-
raise e
|
91
|
-
rescue StandardError => e
|
92
|
-
# catch all errors during execution
|
93
|
-
died_with_error(e)
|
94
|
-
raise e
|
95
|
-
ensure
|
96
|
-
done!
|
97
85
|
end
|
98
86
|
|
99
87
|
# Called to save a temporary image file. After the final generation of the
|
@@ -51,11 +51,9 @@ module GrafanaReporter
|
|
51
51
|
|
52
52
|
begin
|
53
53
|
# catch properly if datasource could not be identified
|
54
|
-
query = QueryValueQuery.new(@report.grafana(instance))
|
54
|
+
query = QueryValueQuery.new(@report.grafana(instance), variables: build_attribute_hash(doc.attributes, attrs))
|
55
55
|
query.datasource = @report.grafana(instance).datasource_by_id(target.split(':')[1].to_i)
|
56
56
|
query.raw_query = attrs['sql']
|
57
|
-
assign_doc_and_item_variables(query, doc.attributes, attrs)
|
58
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
59
57
|
|
60
58
|
reader.unshift_lines query.execute
|
61
59
|
rescue GrafanaReporterError => e
|
@@ -49,11 +49,9 @@ module GrafanaReporter
|
|
49
49
|
|
50
50
|
begin
|
51
51
|
# catch properly if datasource could not be identified
|
52
|
-
query = QueryValueQuery.new(@report.grafana(instance))
|
52
|
+
query = QueryValueQuery.new(@report.grafana(instance), variables: build_attribute_hash(parent.document.attributes, attrs))
|
53
53
|
query.datasource = @report.grafana(instance).datasource_by_id(target)
|
54
54
|
query.raw_query = attrs['sql']
|
55
|
-
assign_doc_and_item_variables(query, parent.document.attributes, attrs)
|
56
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
57
55
|
|
58
56
|
create_inline(parent, :quoted, query.execute)
|
59
57
|
rescue GrafanaReporterError => e
|
@@ -55,7 +55,11 @@ module GrafanaReporter
|
|
55
55
|
results = {}
|
56
56
|
|
57
57
|
dashboard.panels.shuffle.each do |panel|
|
58
|
-
|
58
|
+
begin
|
59
|
+
next if panel.datasource.is_a?(Grafana::UnsupportedDatasource)
|
60
|
+
rescue Grafana::DatasourceDoesNotExistError
|
61
|
+
next
|
62
|
+
end
|
59
63
|
|
60
64
|
query_classes.each do |query_class|
|
61
65
|
unless query_class.public_instance_methods.include?(:build_demo_entry)
|
@@ -9,29 +9,16 @@ module GrafanaReporter
|
|
9
9
|
class Report < ::GrafanaReporter::AbstractReport
|
10
10
|
# Starts to create an asciidoctor report. It utilizes all extensions in the {GrafanaReporter::Asciidoctor}
|
11
11
|
# namespace to realize the conversion.
|
12
|
-
# @see AbstractReport#
|
13
|
-
def
|
14
|
-
super
|
12
|
+
# @see AbstractReport#build
|
13
|
+
def build(template, destination_file_or_path, custom_attributes)
|
15
14
|
attrs = @config.default_document_attributes.merge(@custom_attributes)
|
16
15
|
logger.debug("Document attributes: #{attrs}")
|
17
16
|
|
18
17
|
# TODO: if path is true, a default filename has to be generated. check if this should be a general function instead
|
19
|
-
|
20
|
-
File.write(path, ::ERB.new(File.read(template)).result(binding))
|
18
|
+
File.write(path, ::ERB.new(File.read(template)).result(ReportJail.new(self, attrs).bind))
|
21
19
|
|
22
20
|
# TODO: check if closing output file is correct here, or maybe can be moved to AbstractReport.done!
|
23
21
|
@destination_file_or_path.close if @destination_file_or_path.is_a?(File)
|
24
|
-
rescue MissingTemplateError => e
|
25
|
-
@logger.error(e.message)
|
26
|
-
@error = [e.message]
|
27
|
-
done!
|
28
|
-
raise e
|
29
|
-
rescue StandardError => e
|
30
|
-
# catch all errors during execution
|
31
|
-
died_with_error(e)
|
32
|
-
raise e
|
33
|
-
ensure
|
34
|
-
done!
|
35
22
|
end
|
36
23
|
|
37
24
|
# @see AbstractReport#demo_report_classes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
module ERB
|
5
|
+
# An instance of this class is used as binding for the ERB execution, i.e.
|
6
|
+
# this class contains everything known within the ERB template
|
7
|
+
class ReportJail
|
8
|
+
attr_reader :report, :attributes
|
9
|
+
|
10
|
+
def initialize(report, attributes)
|
11
|
+
@report = report
|
12
|
+
@attributes = attributes
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return binding to this object
|
16
|
+
def bind
|
17
|
+
binding
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -16,6 +16,20 @@ module GrafanaReporter
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
# Raised if some unhandled exception is raised during a datasource request execution.
|
20
|
+
class DatasourceRequestInternalError < GrafanaReporterError
|
21
|
+
def initialize(ds, message)
|
22
|
+
super("The datasource request to '#{ds.name}' (#{ds.class}) failed with an internal error: #{message}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Raised if the return value of a datasource request does not match the expected return hash.
|
27
|
+
class DatasourceRequestInvalidReturnValueError < GrafanaReporterError
|
28
|
+
def initialize(ds, message)
|
29
|
+
super("The datasource request to '#{ds.name}' (#{ds.class}) returned an invalid value: '#{message}'")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
19
33
|
# Thrown, if the requested grafana instance does not have the mandatory 'host'
|
20
34
|
# setting configured.
|
21
35
|
class GrafanaInstanceWithoutHostError < GrafanaReporterError
|
@@ -5,6 +5,7 @@ require 'yaml'
|
|
5
5
|
module GrafanaReporter
|
6
6
|
# This class generates the functional help documentation for the reporter.
|
7
7
|
# It can create the documentation for github markdown, as well as in asciidoctor.
|
8
|
+
# TODO: this help is limited to Asciidoctor - move it to that namespace
|
8
9
|
class Help
|
9
10
|
# @param headline_level [Integer] top level of headline
|
10
11
|
# @return [String] asciidoctor compatible documentation
|
@@ -129,7 +130,6 @@ end}
|
|
129
130
|
result
|
130
131
|
end
|
131
132
|
|
132
|
-
# TODO: use same wording/grouping as in README file
|
133
133
|
def raw_help_yaml
|
134
134
|
<<~YAML_HELP
|
135
135
|
global_options:
|
@@ -236,7 +236,7 @@ end}
|
|
236
236
|
timeout:
|
237
237
|
call: timeout="<timeout_in_seconds>"
|
238
238
|
description: >-
|
239
|
-
Set a timeout for the current query. If not overridden with `
|
239
|
+
Set a timeout for the current query. If not overridden with `grafana_default_timeout` in the report template,
|
240
240
|
this defaults to 60 seconds.
|
241
241
|
|
242
242
|
# ----------------------------------
|