ruby-grafana-reporter 0.2.2 → 0.4.3
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 +126 -88
- data/bin/ruby-grafana-reporter +2 -2
- data/lib/VERSION.rb +3 -2
- data/lib/grafana/abstract_datasource.rb +146 -0
- data/lib/grafana/dashboard.rb +1 -3
- data/lib/grafana/errors.rb +18 -3
- data/lib/grafana/grafana.rb +64 -66
- 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 +30 -0
- data/lib/grafana/graphite_datasource.rb +72 -0
- data/lib/grafana/image_rendering_datasource.rb +44 -0
- data/lib/grafana/influxdb_datasource.rb +70 -0
- data/lib/grafana/panel.rb +9 -3
- data/lib/grafana/prometheus_datasource.rb +67 -0
- data/lib/grafana/sql_datasource.rb +78 -0
- data/lib/grafana/unsupported_datasource.rb +7 -0
- data/lib/grafana/variable.rb +1 -1
- data/lib/grafana/webrequest.rb +71 -0
- data/lib/grafana_reporter/abstract_query.rb +460 -0
- data/lib/grafana_reporter/abstract_report.rb +139 -18
- data/lib/grafana_reporter/alerts_table_query.rb +39 -0
- data/lib/grafana_reporter/annotations_table_query.rb +38 -0
- data/lib/grafana_reporter/application/application.rb +34 -286
- data/lib/grafana_reporter/application/webservice.rb +50 -15
- data/lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb +91 -0
- data/lib/grafana_reporter/asciidoctor/annotations_table_include_processor.rb +90 -0
- data/lib/grafana_reporter/asciidoctor/panel_image_block_macro.rb +74 -0
- data/lib/grafana_reporter/asciidoctor/panel_image_inline_macro.rb +76 -0
- data/lib/grafana_reporter/asciidoctor/panel_property_inline_macro.rb +70 -0
- data/lib/grafana_reporter/asciidoctor/panel_query_table_include_processor.rb +95 -0
- data/lib/grafana_reporter/asciidoctor/panel_query_value_inline_macro.rb +90 -0
- data/lib/grafana_reporter/asciidoctor/processor_mixin.rb +49 -0
- data/lib/grafana_reporter/asciidoctor/report.rb +32 -76
- 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 +90 -0
- data/lib/grafana_reporter/asciidoctor/sql_value_inline_macro.rb +86 -0
- data/lib/grafana_reporter/asciidoctor/value_as_variable_include_processor.rb +90 -0
- data/lib/grafana_reporter/configuration.rb +59 -52
- data/lib/grafana_reporter/console_configuration_wizard.rb +311 -0
- data/lib/grafana_reporter/demo_report_wizard.rb +105 -0
- data/lib/grafana_reporter/erb/report.rb +30 -0
- data/lib/grafana_reporter/erb/report_jail.rb +21 -0
- data/lib/grafana_reporter/errors.rb +55 -0
- data/lib/grafana_reporter/help.rb +443 -0
- data/lib/grafana_reporter/logger/{two_way_logger.rb → two_way_delegate_logger.rb} +1 -1
- data/lib/grafana_reporter/panel_image_query.rb +25 -0
- data/lib/grafana_reporter/panel_property_query.rb +22 -0
- data/lib/grafana_reporter/query_value_query.rb +61 -0
- data/lib/grafana_reporter/report_webhook.rb +35 -0
- data/lib/ruby_grafana_extension.rb +8 -0
- data/lib/{ruby-grafana-reporter.rb → ruby_grafana_reporter.rb} +1 -0
- metadata +47 -39
- 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 -104
- data/lib/grafana_reporter/asciidoctor/annotations_table_query.rb +0 -99
- 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 -86
- data/lib/grafana_reporter/asciidoctor/help.rb +0 -435
- data/lib/grafana_reporter/asciidoctor/panel_first_value_query.rb +0 -34
- data/lib/grafana_reporter/asciidoctor/panel_image_query.rb +0 -26
- data/lib/grafana_reporter/asciidoctor/panel_property_query.rb +0 -44
- data/lib/grafana_reporter/asciidoctor/panel_table_query.rb +0 -38
- data/lib/grafana_reporter/asciidoctor/query_mixin.rb +0 -301
- 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,70 @@
|
|
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), variables: build_attribute_hash(parent.document.attributes, attrs))
|
42
|
+
query.raw_query = { property_name: attrs[:field] }
|
43
|
+
|
44
|
+
description = query.execute
|
45
|
+
rescue GrafanaReporterError => e
|
46
|
+
@report.logger.error(e.message)
|
47
|
+
return create_inline(parent, :quoted, e.message)
|
48
|
+
rescue StandardError => e
|
49
|
+
@report.logger.fatal(e.message)
|
50
|
+
return create_inline(parent, :quoted, e.message)
|
51
|
+
end
|
52
|
+
|
53
|
+
# translate linebreaks to asciidoctor syntax
|
54
|
+
# and HTML encode to make sure, that HTML formattings are respected
|
55
|
+
create_inline(parent, :quoted, CGI.escapeHTML(description.gsub(%r{//[^\n]*(?:\n)?}, '').gsub(/\n/, " +\n")))
|
56
|
+
end
|
57
|
+
|
58
|
+
# @see ProcessorMixin#build_demo_entry
|
59
|
+
def build_demo_entry(panel)
|
60
|
+
return nil unless panel
|
61
|
+
return nil unless panel.model['title']
|
62
|
+
return nil if panel.model['title'].strip == ''
|
63
|
+
return nil if panel.model['title'].strip == 'Panel Title'
|
64
|
+
|
65
|
+
"this text includes the panel with title grafana_panel_property:#{panel.id}[\"title\","\
|
66
|
+
"dashboard=\"#{panel.dashboard.id}\"]"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,95 @@
|
|
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 {AbstractQuery#format_columns}
|
36
|
+
#
|
37
|
+
# +replace_values+ - see {AbstractQuery#replace_values}
|
38
|
+
#
|
39
|
+
# +filter_columns+ - see {AbstractQuery#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, variables: build_attribute_hash(doc.attributes, attrs))
|
63
|
+
|
64
|
+
reader.unshift_lines query.execute
|
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
|
+
|
76
|
+
# @see ProcessorMixin#build_demo_entry
|
77
|
+
def build_demo_entry(panel)
|
78
|
+
return nil unless panel
|
79
|
+
return nil unless panel.model['type'].include?('table')
|
80
|
+
|
81
|
+
ref_id = nil
|
82
|
+
panel.model['targets'].each do |item|
|
83
|
+
if !item['hide'] && !panel.query(item['refId']).to_s.empty?
|
84
|
+
ref_id = item['refId']
|
85
|
+
break
|
86
|
+
end
|
87
|
+
end
|
88
|
+
return nil unless ref_id
|
89
|
+
|
90
|
+
"|===\ninclude::grafana_panel_query_table:#{panel.id}[query=\"#{ref_id}\",filter_columns=\"time\","\
|
91
|
+
"dashboard=\"#{panel.dashboard.id}\"]\n|==="
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,90 @@
|
|
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 {AbstractQuery#format_columns}
|
36
|
+
#
|
37
|
+
# +replace_values+ - see {AbstractQuery#replace_values}
|
38
|
+
#
|
39
|
+
# +filter_columns+ - see {AbstractQuery#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, variables: build_attribute_hash(parent.document.attributes, attrs))
|
60
|
+
|
61
|
+
create_inline(parent, :quoted, query.execute)
|
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
|
+
|
71
|
+
# @see ProcessorMixin#build_demo_entry
|
72
|
+
def build_demo_entry(panel)
|
73
|
+
return nil unless panel
|
74
|
+
return nil unless panel.model['type'] == 'singlestat'
|
75
|
+
|
76
|
+
ref_id = nil
|
77
|
+
panel.model['targets'].each do |item|
|
78
|
+
if !item['hide'] && !panel.query(item['refId']).to_s.empty?
|
79
|
+
ref_id = item['refId']
|
80
|
+
break
|
81
|
+
end
|
82
|
+
end
|
83
|
+
return nil unless ref_id
|
84
|
+
|
85
|
+
"it's easily possible to include the query value: grafana_panel_query_value:#{panel.id}[query=\"#{ref_id}\""\
|
86
|
+
",dashboard=\"#{panel.dashboard.id}\"] - just within this text."
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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 {Grafana::Panel}.
|
16
|
+
# @param panel [Grafana::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
|
+
|
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.
|
24
|
+
# @param document_hash [Hash] variables from report template level
|
25
|
+
# @param item_hash [Hash] variables from item configuration level, i.e. specific call, which may override document
|
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)
|
36
|
+
|
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)
|
44
|
+
|
45
|
+
result
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,27 +1,22 @@
|
|
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
|
-
#
|
9
|
-
def initialize(config
|
8
|
+
class Report < ::GrafanaReporter::AbstractReport
|
9
|
+
# @see AbstractReport#initialize
|
10
|
+
def initialize(config)
|
10
11
|
super
|
11
|
-
@current_pos = 0
|
12
12
|
@image_files = []
|
13
|
-
@grafana_instances = {}
|
14
13
|
end
|
15
14
|
|
16
|
-
# Starts to create an asciidoctor report. It utilizes all {
|
17
|
-
# realize the conversion.
|
18
|
-
# @see AbstractReport#
|
19
|
-
|
20
|
-
def create_report
|
21
|
-
@start_time = Time.now
|
15
|
+
# Starts to create an asciidoctor report. It utilizes all extensions in the {GrafanaReporter::Asciidoctor}
|
16
|
+
# namespace to realize the conversion.
|
17
|
+
# @see AbstractReport#build
|
18
|
+
def build(template, destination_file_or_path, custom_attributes)
|
22
19
|
attrs = { 'convert-backend' => 'pdf' }.merge(@config.default_document_attributes.merge(@custom_attributes))
|
23
|
-
attrs['grafana-report-timestamp'] = @start_time.to_s
|
24
|
-
logger.info("Report started at #{@start_time}")
|
25
20
|
logger.debug("Document attributes: #{attrs}")
|
26
21
|
|
27
22
|
initialize_step_counter
|
@@ -30,19 +25,18 @@ module GrafanaReporter
|
|
30
25
|
::Asciidoctor::LoggerManager.logger = logger
|
31
26
|
|
32
27
|
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)
|
28
|
+
registry.inline_macro PanelImageInlineMacro.new.current_report(self)
|
29
|
+
registry.inline_macro PanelQueryValueInlineMacro.new.current_report(self)
|
30
|
+
registry.inline_macro PanelPropertyInlineMacro.new.current_report(self)
|
31
|
+
registry.inline_macro SqlValueInlineMacro.new.current_report(self)
|
32
|
+
registry.block_macro PanelImageBlockMacro.new.current_report(self)
|
33
|
+
registry.include_processor ValueAsVariableIncludeProcessor.new.current_report(self)
|
34
|
+
registry.include_processor PanelQueryTableIncludeProcessor.new.current_report(self)
|
35
|
+
registry.include_processor SqlTableIncludeProcessor.new.current_report(self)
|
36
|
+
registry.include_processor ShowEnvironmentIncludeProcessor.new.current_report(self)
|
37
|
+
registry.include_processor ShowHelpIncludeProcessor.new.current_report(self)
|
38
|
+
registry.include_processor AnnotationsTableIncludeProcessor.new.current_report(self)
|
39
|
+
registry.include_processor AlertsTableIncludeProcessor.new.current_report(self)
|
46
40
|
|
47
41
|
::Asciidoctor.convert_file(@template, extension_registry: registry, backend: attrs['convert-backend'],
|
48
42
|
to_file: path, attributes: attrs, header_footer: true)
|
@@ -51,15 +45,11 @@ module GrafanaReporter
|
|
51
45
|
|
52
46
|
# store report including als images as ZIP file, if the result is not a PDF
|
53
47
|
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
|
48
|
+
dest_path = if @destination_file_or_path.is_a?(File) || @destination_file_or_path.is_a?(Tempfile)
|
49
|
+
@destination_file_or_path.path
|
50
|
+
else
|
51
|
+
@destination_file_or_path
|
52
|
+
end
|
63
53
|
|
64
54
|
# build zip file
|
65
55
|
zip_file = Tempfile.new('gf_zip')
|
@@ -92,40 +82,6 @@ module GrafanaReporter
|
|
92
82
|
end
|
93
83
|
|
94
84
|
clean_image_files
|
95
|
-
@end_time = Time.now
|
96
|
-
logger.info("Report finished after #{@end_time - @start_time} seconds.")
|
97
|
-
@done = true
|
98
|
-
rescue StandardError => e
|
99
|
-
# catch all errors during execution
|
100
|
-
died_with_error(e)
|
101
|
-
raise e
|
102
|
-
end
|
103
|
-
|
104
|
-
# @see AbstractReport#progress
|
105
|
-
# @return [Float] number between 0 and 1 reflecting the current progress.
|
106
|
-
def progress
|
107
|
-
return 0 if @total_steps.to_i.zero?
|
108
|
-
|
109
|
-
@current_pos.to_f / @total_steps
|
110
|
-
end
|
111
|
-
|
112
|
-
# @param instance [String] requested grafana instance
|
113
|
-
# @return [Grafana::Grafana] the requested grafana instance.
|
114
|
-
def grafana(instance)
|
115
|
-
unless @grafana_instances[instance]
|
116
|
-
@grafana_instances[instance] = ::Grafana::Grafana.new(@config.grafana_host(instance),
|
117
|
-
@config.grafana_api_key(instance),
|
118
|
-
logger: @logger,
|
119
|
-
datasources: @config.grafana_datasources(instance))
|
120
|
-
end
|
121
|
-
@grafana_instances[instance]
|
122
|
-
end
|
123
|
-
|
124
|
-
# Increments the progress.
|
125
|
-
# @return [Integer] number of the current progress position.
|
126
|
-
def next_step
|
127
|
-
@current_pos += 1
|
128
|
-
@current_pos
|
129
85
|
end
|
130
86
|
|
131
87
|
# Called to save a temporary image file. After the final generation of the
|
@@ -134,6 +90,7 @@ module GrafanaReporter
|
|
134
90
|
# @return [String] path to the temporary file.
|
135
91
|
def save_image_file(img_data)
|
136
92
|
file = Tempfile.new(['gf_image_', '.png'], @config.images_folder.to_s)
|
93
|
+
file.binmode
|
137
94
|
file.write(img_data)
|
138
95
|
path = file.path.gsub(/#{@config.images_folder}/, '')
|
139
96
|
|
@@ -143,13 +100,11 @@ module GrafanaReporter
|
|
143
100
|
path
|
144
101
|
end
|
145
102
|
|
146
|
-
#
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
@end_time = Time.now
|
152
|
-
@done = true
|
103
|
+
# @see AbstractReport#demo_report_classes
|
104
|
+
def self.demo_report_classes
|
105
|
+
[AlertsTableIncludeProcessor, AnnotationsTableIncludeProcessor, PanelImageBlockMacro, PanelImageInlineMacro,
|
106
|
+
PanelPropertyInlineMacro, PanelQueryTableIncludeProcessor, PanelQueryValueInlineMacro,
|
107
|
+
SqlTableIncludeProcessor, SqlValueInlineMacro, ShowHelpIncludeProcessor, ShowEnvironmentIncludeProcessor]
|
153
108
|
end
|
154
109
|
|
155
110
|
private
|
@@ -163,6 +118,7 @@ module GrafanaReporter
|
|
163
118
|
@total_steps = 0
|
164
119
|
File.readlines(@template).each do |line|
|
165
120
|
begin
|
121
|
+
# TODO: move these calls to the specific processors to ensure all are counted properly
|
166
122
|
@total_steps += line.gsub(%r{//.*}, '').scan(/(?:grafana_panel_image|grafana_panel_query_value|
|
167
123
|
grafana_panel_query_table|grafana_sql_value|
|
168
124
|
grafana_sql_table|grafana_environment|grafana_help|
|