ruby-grafana-reporter 0.4.1 → 0.4.5
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 +336 -185
- data/lib/VERSION.rb +2 -2
- data/lib/grafana/abstract_datasource.rb +30 -17
- data/lib/grafana/errors.rb +4 -4
- data/lib/grafana/grafana.rb +2 -0
- data/lib/grafana/grafana_property_datasource.rb +12 -0
- data/lib/grafana/graphite_datasource.rb +27 -5
- data/lib/grafana/influxdb_datasource.rb +156 -0
- data/lib/grafana/panel.rb +1 -1
- data/lib/grafana/prometheus_datasource.rb +37 -6
- data/lib/grafana/sql_datasource.rb +10 -11
- data/lib/grafana/variable.rb +29 -22
- data/lib/grafana_reporter/abstract_query.rb +150 -31
- data/lib/grafana_reporter/abstract_report.rb +37 -5
- data/lib/grafana_reporter/abstract_table_format_strategy.rb +34 -0
- data/lib/grafana_reporter/alerts_table_query.rb +5 -6
- data/lib/grafana_reporter/annotations_table_query.rb +5 -6
- data/lib/grafana_reporter/application/application.rb +7 -2
- data/lib/grafana_reporter/application/webservice.rb +35 -30
- data/lib/grafana_reporter/asciidoctor/adoc_plain_table_format_strategy.rb +25 -0
- data/lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb +7 -5
- data/lib/grafana_reporter/asciidoctor/annotations_table_include_processor.rb +7 -5
- data/lib/grafana_reporter/asciidoctor/help.rb +458 -0
- data/lib/grafana_reporter/asciidoctor/panel_image_block_macro.rb +5 -4
- data/lib/grafana_reporter/asciidoctor/panel_image_inline_macro.rb +5 -4
- data/lib/grafana_reporter/asciidoctor/panel_property_inline_macro.rb +5 -4
- data/lib/grafana_reporter/asciidoctor/panel_query_table_include_processor.rb +6 -6
- data/lib/grafana_reporter/asciidoctor/panel_query_value_inline_macro.rb +4 -4
- data/lib/grafana_reporter/asciidoctor/processor_mixin.rb +21 -35
- data/lib/grafana_reporter/asciidoctor/report.rb +16 -26
- data/lib/grafana_reporter/asciidoctor/show_help_include_processor.rb +1 -1
- data/lib/grafana_reporter/asciidoctor/sql_table_include_processor.rb +6 -4
- data/lib/grafana_reporter/asciidoctor/sql_value_inline_macro.rb +5 -3
- data/lib/grafana_reporter/console_configuration_wizard.rb +2 -2
- data/lib/grafana_reporter/csv_table_format_strategy.rb +23 -0
- data/lib/grafana_reporter/demo_report_wizard.rb +5 -2
- data/lib/grafana_reporter/erb/demo_report_builder.rb +46 -0
- data/lib/grafana_reporter/erb/report.rb +14 -21
- data/lib/grafana_reporter/erb/report_jail.rb +21 -0
- data/lib/grafana_reporter/errors.rb +19 -3
- data/lib/grafana_reporter/panel_image_query.rb +2 -5
- data/lib/grafana_reporter/query_value_query.rb +1 -19
- data/lib/grafana_reporter/report_webhook.rb +12 -8
- data/lib/ruby_grafana_reporter.rb +10 -11
- metadata +9 -3
- data/lib/grafana_reporter/help.rb +0 -443
@@ -46,13 +46,14 @@ module GrafanaReporter
|
|
46
46
|
" panel: #{target})")
|
47
47
|
|
48
48
|
begin
|
49
|
-
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target)
|
50
|
-
|
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),
|
50
|
+
variables: build_attribute_hash(parent.document.attributes, attrs))
|
53
51
|
|
54
52
|
image = query.execute
|
55
53
|
image_path = @report.save_image_file(image)
|
54
|
+
rescue Grafana::GrafanaError => e
|
55
|
+
@report.logger.error(e.message)
|
56
|
+
return create_paragraph(parent, e.message, attrs)
|
56
57
|
rescue GrafanaReporterError => e
|
57
58
|
@report.logger.error(e.message)
|
58
59
|
return create_paragraph(parent, e.message, attrs)
|
@@ -46,15 +46,16 @@ 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
|
-
|
54
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
51
|
+
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target),
|
52
|
+
variables: build_attribute_hash(parent.document.attributes, attrs))
|
55
53
|
|
56
54
|
image = query.execute
|
57
55
|
image_path = @report.save_image_file(image)
|
56
|
+
rescue Grafana::GrafanaError => e
|
57
|
+
@report.logger.error(e.message)
|
58
|
+
return create_inline(parent, :quoted, e.message)
|
58
59
|
rescue GrafanaReporterError => e
|
59
60
|
@report.logger.error(e.message)
|
60
61
|
return create_inline(parent, :quoted, e.message)
|
@@ -38,13 +38,14 @@ 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),
|
42
|
+
variables: build_attribute_hash(parent.document.attributes, attrs))
|
42
43
|
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
44
|
|
47
45
|
description = query.execute
|
46
|
+
rescue Grafana::GrafanaError => e
|
47
|
+
@report.logger.error(e.message)
|
48
|
+
return create_inline(parent, :quoted, e.message)
|
48
49
|
rescue GrafanaReporterError => e
|
49
50
|
@report.logger.error(e.message)
|
50
51
|
return create_inline(parent, :quoted, e.message)
|
@@ -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,12 +59,13 @@ module GrafanaReporter
|
|
60
59
|
|
61
60
|
begin
|
62
61
|
panel = @report.grafana(instance).dashboard(dashboard).panel(panel_id)
|
63
|
-
|
64
|
-
|
65
|
-
assign_doc_and_item_variables(query, doc.attributes, attrs)
|
66
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
62
|
+
vars = { 'table_formatter' => 'adoc_plain' }.merge(build_attribute_hash(doc.attributes, attrs))
|
63
|
+
query = QueryValueQuery.new(panel, variables: vars)
|
67
64
|
|
68
|
-
reader.unshift_lines query.execute
|
65
|
+
reader.unshift_lines query.execute.split("\n")
|
66
|
+
rescue Grafana::GrafanaError => e
|
67
|
+
@report.logger.error(e.message)
|
68
|
+
reader.unshift_line "|#{e.message}"
|
69
69
|
rescue GrafanaReporterError => e
|
70
70
|
@report.logger.error(e.message)
|
71
71
|
reader.unshift_line "|#{e.message}"
|
@@ -56,12 +56,12 @@ 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)
|
62
|
+
rescue Grafana::GrafanaError => e
|
63
|
+
@report.logger.error(e.message)
|
64
|
+
create_inline(parent, :quoted, e.message)
|
65
65
|
rescue GrafanaReporterError => e
|
66
66
|
@report.logger.error(e.message)
|
67
67
|
create_inline(parent, :quoted, e.message)
|
@@ -19,45 +19,31 @@ 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|from_timezone|
|
42
|
+
to_timezone|result_type|query|table_formatter|include_headline|
|
43
|
+
column_divider|row_divider/x
|
44
|
+
end)
|
57
45
|
|
58
|
-
|
59
|
-
query.from = item_hash['from'] || document_hash['from'] || query.from
|
60
|
-
query.to = item_hash['to'] || document_hash['to'] || query.to
|
46
|
+
result
|
61
47
|
end
|
62
48
|
end
|
63
49
|
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
|
20
19
|
attrs = { 'convert-backend' => 'pdf' }.merge(@config.default_document_attributes.merge(@custom_attributes))
|
21
20
|
logger.debug("Document attributes: #{attrs}")
|
22
21
|
|
@@ -42,22 +41,14 @@ module GrafanaReporter
|
|
42
41
|
::Asciidoctor.convert_file(@template, extension_registry: registry, backend: attrs['convert-backend'],
|
43
42
|
to_file: path, attributes: attrs, header_footer: true)
|
44
43
|
|
45
|
-
@destination_file_or_path.close if @destination_file_or_path.is_a?(File)
|
46
|
-
|
47
44
|
# store report including als images as ZIP file, if the result is not a PDF
|
48
45
|
if attrs['convert-backend'] != 'pdf'
|
49
|
-
dest_path = if @destination_file_or_path.is_a?(File) || @destination_file_or_path.is_a?(Tempfile)
|
50
|
-
@destination_file_or_path.path
|
51
|
-
else
|
52
|
-
@destination_file_or_path
|
53
|
-
end
|
54
|
-
|
55
46
|
# build zip file
|
56
47
|
zip_file = Tempfile.new('gf_zip')
|
57
48
|
buffer = Zip::OutputStream.write_buffer do |zipfile|
|
58
49
|
# add report file
|
59
|
-
zipfile.put_next_entry("#{
|
60
|
-
zipfile.write File.read(
|
50
|
+
zipfile.put_next_entry("#{path.gsub(@config.reports_folder, '')}.#{attrs['convert-backend']}")
|
51
|
+
zipfile.write File.read(path)
|
61
52
|
|
62
53
|
# add image files
|
63
54
|
@image_files.each do |file|
|
@@ -72,9 +63,9 @@ module GrafanaReporter
|
|
72
63
|
# replace original file with zip file
|
73
64
|
zip_file.rewind
|
74
65
|
begin
|
75
|
-
File.write(
|
66
|
+
File.write(path, zip_file.read)
|
76
67
|
rescue StandardError => e
|
77
|
-
logger.fatal("Could not overwrite report file '#{
|
68
|
+
logger.fatal("Could not overwrite report file '#{path}' with ZIP file. (#{e.message}).")
|
78
69
|
end
|
79
70
|
|
80
71
|
# cleanup temporary zip file
|
@@ -83,17 +74,6 @@ module GrafanaReporter
|
|
83
74
|
end
|
84
75
|
|
85
76
|
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
77
|
end
|
98
78
|
|
99
79
|
# Called to save a temporary image file. After the final generation of the
|
@@ -112,6 +92,16 @@ module GrafanaReporter
|
|
112
92
|
path
|
113
93
|
end
|
114
94
|
|
95
|
+
# @see AbstractReport#default_template_extension
|
96
|
+
def self.default_template_extension
|
97
|
+
'adoc'
|
98
|
+
end
|
99
|
+
|
100
|
+
# @see AbstractReport#default_result_extension
|
101
|
+
def self.default_result_extension
|
102
|
+
'pdf'
|
103
|
+
end
|
104
|
+
|
115
105
|
# @see AbstractReport#demo_report_classes
|
116
106
|
def self.demo_report_classes
|
117
107
|
[AlertsTableIncludeProcessor, AnnotationsTableIncludeProcessor, PanelImageBlockMacro, PanelImageInlineMacro,
|
@@ -23,7 +23,7 @@ module GrafanaReporter
|
|
23
23
|
@report.next_step
|
24
24
|
@report.logger.debug('Processing ShowHelpIncludeProcessor')
|
25
25
|
|
26
|
-
reader.unshift_lines
|
26
|
+
reader.unshift_lines Help.new.asciidoctor.split("\n")
|
27
27
|
end
|
28
28
|
|
29
29
|
# @see ProcessorMixin#build_demo_entry
|
@@ -51,13 +51,15 @@ module GrafanaReporter
|
|
51
51
|
|
52
52
|
begin
|
53
53
|
# catch properly if datasource could not be identified
|
54
|
-
|
54
|
+
vars = { 'table_formatter' => 'adoc_plain' }.merge(build_attribute_hash(doc.attributes, attrs))
|
55
|
+
query = QueryValueQuery.new(@report.grafana(instance), variables: vars)
|
55
56
|
query.datasource = @report.grafana(instance).datasource_by_id(target.split(':')[1].to_i)
|
56
57
|
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
58
|
|
60
|
-
reader.unshift_lines query.execute
|
59
|
+
reader.unshift_lines query.execute.split("\n")
|
60
|
+
rescue Grafana::GrafanaError => e
|
61
|
+
@report.logger.error(e.message)
|
62
|
+
reader.unshift_line "|#{e.message}"
|
61
63
|
rescue GrafanaReporterError => e
|
62
64
|
@report.logger.error(e.message)
|
63
65
|
reader.unshift_line "|#{e.message}"
|
@@ -49,13 +49,15 @@ 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),
|
53
|
+
variables: build_attribute_hash(parent.document.attributes, attrs))
|
53
54
|
query.datasource = @report.grafana(instance).datasource_by_id(target)
|
54
55
|
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
56
|
|
58
57
|
create_inline(parent, :quoted, query.execute)
|
58
|
+
rescue Grafana::GrafanaError => e
|
59
|
+
@report.logger.error(e.message)
|
60
|
+
create_inline(parent, :quoted, e.message)
|
59
61
|
rescue GrafanaReporterError => e
|
60
62
|
@report.logger.error(e.message)
|
61
63
|
create_inline(parent, :quoted, e.message)
|
@@ -39,7 +39,7 @@ module GrafanaReporter
|
|
39
39
|
puts 'Now everything is setup properly. Create your reports as required in the templates '\
|
40
40
|
'folder and run the reporter either standalone with e.g. the following command:'
|
41
41
|
puts
|
42
|
-
puts " #{program_call}#{config_param} -t #{demo_report} -o
|
42
|
+
puts " #{program_call}#{config_param} -t #{demo_report} -o demo_report.#{config.report_class.default_result_extension}"
|
43
43
|
puts
|
44
44
|
puts 'or run it as a service using the following command:'
|
45
45
|
puts
|
@@ -120,7 +120,7 @@ default-document-attributes:
|
|
120
120
|
return nil unless create =~ /^(?:y|Y)$/
|
121
121
|
|
122
122
|
demo_report = 'demo_report'
|
123
|
-
demo_report_file = "#{config.templates_folder}#{demo_report}.
|
123
|
+
demo_report_file = "#{config.templates_folder}#{demo_report}.#{config.report_class.default_template_extension}"
|
124
124
|
|
125
125
|
# ask to overwrite file
|
126
126
|
if File.exist?(demo_report_file)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
# Implements a default table format strategy, which will return tables
|
5
|
+
# as CSV formatted strings.
|
6
|
+
class CsvTableFormatStrategy < AbstractTableFormatStrategy
|
7
|
+
# @see AbstractTableFormatStrategy#abbreviation
|
8
|
+
def self.abbreviation
|
9
|
+
'csv'
|
10
|
+
end
|
11
|
+
|
12
|
+
# @see AbstractTableFormatStrategy#format
|
13
|
+
def format(result, include_headline)
|
14
|
+
headline = result[:header].map { |item| item.to_s.gsub(',', '\\,') }.join(',')
|
15
|
+
|
16
|
+
content = result[:content].map do |row|
|
17
|
+
row.map { |item| item.to_s.gsub(',', '\,') }.join(',')
|
18
|
+
end.join("\n")
|
19
|
+
|
20
|
+
"#{"#{headline}\n" if include_headline}#{content}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -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)
|
@@ -80,7 +84,6 @@ module GrafanaReporter
|
|
80
84
|
results
|
81
85
|
end
|
82
86
|
|
83
|
-
# TODO: move this method to Asciidoctor::Report
|
84
87
|
def format_results(raw_results)
|
85
88
|
results = ['= Demo report',
|
86
89
|
"Created by `+ruby-grafana-reporter+` version #{GRAFANA_REPORTER_VERSION.join('.')}",
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
module ERB
|
5
|
+
# This class builds a demo report for ERB templates
|
6
|
+
class DemoReportBuilder
|
7
|
+
# This method is called if a demo report shall be built for the given {Grafana::Panel}.
|
8
|
+
# @param panel [Grafana::Panel] panel object, for which a demo entry shall be created.
|
9
|
+
# @return [String] String containing the entry, or nil if not possible for given panel
|
10
|
+
def build_demo_entry(panel)
|
11
|
+
return nil unless panel
|
12
|
+
return nil unless panel.model['type'].include?('table')
|
13
|
+
|
14
|
+
ref_id = nil
|
15
|
+
panel.model['targets'].each do |item|
|
16
|
+
if !item['hide'] && !panel.query(item['refId']).to_s.empty?
|
17
|
+
ref_id = item['refId']
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
return nil unless ref_id
|
22
|
+
|
23
|
+
<<~DEMO_ERB_TEMPLATE
|
24
|
+
<%
|
25
|
+
dashboard = '#{panel.dashboard.id}'
|
26
|
+
instance = 'default'
|
27
|
+
# load the panel object from grafana instance
|
28
|
+
panel = @report.grafana(instance).dashboard(dashboard).panel(#{panel.id})
|
29
|
+
# build a complete attributes hash, including the variables set for this report call
|
30
|
+
# e.g. including command line parameters etc.
|
31
|
+
attrs = @attributes.merge({ 'result_type' => 'panel_table', 'query' => '#{ref_id}' })
|
32
|
+
query = QueryValueQuery.new(panel, variables: attrs)
|
33
|
+
%>
|
34
|
+
|
35
|
+
This is a test table for panel <%= panel.id %>:
|
36
|
+
|
37
|
+
<%= query.execute %>
|
38
|
+
|
39
|
+
For detailed API documentation you may start with:
|
40
|
+
1) the AbstractReport (https://rubydoc.info/gems/ruby-grafana-reporter/GrafanaReporter/AbstractReport), or
|
41
|
+
2) subclasses of the AbstractQuery (https://rubydoc.info/gems/ruby-grafana-reporter/GrafanaReporter/AbstractQuery)
|
42
|
+
DEMO_ERB_TEMPLATE
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -9,34 +9,27 @@ 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
|
-
|
15
|
-
attrs = @config.default_document_attributes.merge(@custom_attributes)
|
12
|
+
# @see AbstractReport#build
|
13
|
+
def build
|
14
|
+
attrs = @config.default_document_attributes.merge(@custom_attributes).merge({ 'grafana_report_timestamp' => ::Grafana::Variable.new(Time.now.to_s) })
|
16
15
|
logger.debug("Document attributes: #{attrs}")
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
File.write(path, ::ERB.new(File.read(@template)).result(ReportJail.new(self, attrs).bind))
|
18
|
+
end
|
19
|
+
|
20
|
+
# @see AbstractReport#default_template_extension
|
21
|
+
def self.default_template_extension
|
22
|
+
'erb'
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
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!
|
25
|
+
# @see AbstractReport#default_result_extension
|
26
|
+
def self.default_result_extension
|
27
|
+
'txt'
|
35
28
|
end
|
36
29
|
|
37
30
|
# @see AbstractReport#demo_report_classes
|
38
31
|
def self.demo_report_classes
|
39
|
-
[]
|
32
|
+
[DemoReportBuilder]
|
40
33
|
end
|
41
34
|
end
|
42
35
|
end
|