ruby-grafana-reporter 0.2.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 +126 -85
- 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 +21 -23
- 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 +40 -81
- 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 -2
- metadata +47 -38
- 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 -228
- 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/panel_first_value_query.rb +0 -34
- data/lib/grafana_reporter/asciidoctor/panel_image_query.rb +0 -25
- 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 -294
- data/lib/grafana_reporter/asciidoctor/sql_first_value_query.rb +0 -32
- data/lib/grafana_reporter/asciidoctor/sql_table_query.rb +0 -34
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'processor_mixin'
|
4
|
-
|
5
|
-
module GrafanaReporter
|
6
|
-
module Asciidoctor
|
7
|
-
module Extensions
|
8
|
-
# Implements the hook
|
9
|
-
# grafana_panel_image::<panel_id>[<options>]
|
10
|
-
#
|
11
|
-
# Stores the queried panel as a temporary image file and returns an asciidoctor link
|
12
|
-
# to be included in the report.
|
13
|
-
#
|
14
|
-
# == Used document parameters
|
15
|
-
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
16
|
-
#
|
17
|
-
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
18
|
-
#
|
19
|
-
# +from+ - 'from' time for the sql query
|
20
|
-
#
|
21
|
-
# +to+ - 'to' time for the sql query
|
22
|
-
#
|
23
|
-
# == Supported options
|
24
|
-
# +field+ - property to query for, e.g. +description+ or +title+ (*mandatory*)
|
25
|
-
#
|
26
|
-
# +instance+ - name of grafana instance, 'default' if not specified
|
27
|
-
#
|
28
|
-
# +dashboard+ - uid of grafana dashboard to use
|
29
|
-
#
|
30
|
-
# +from+ - 'from' time for the sql query
|
31
|
-
#
|
32
|
-
# +to+ - 'to' time for the sql query
|
33
|
-
class PanelImageBlockMacro < ::Asciidoctor::Extensions::BlockMacroProcessor
|
34
|
-
include ProcessorMixin
|
35
|
-
use_dsl
|
36
|
-
|
37
|
-
named :grafana_panel_image
|
38
|
-
|
39
|
-
# :nodoc:
|
40
|
-
def process(parent, target, attrs)
|
41
|
-
return if @report.cancel
|
42
|
-
|
43
|
-
@report.next_step
|
44
|
-
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
45
|
-
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
46
|
-
@report.logger.debug("Processing PanelImageBlockMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
47
|
-
" panel: #{target})")
|
48
|
-
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target))
|
49
|
-
query.merge_hash_variables(parent.document.attributes, attrs)
|
50
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
51
|
-
|
52
|
-
begin
|
53
|
-
image = query.execute(@report.grafana(instance))
|
54
|
-
image_path = @report.save_image_file(image)
|
55
|
-
rescue GrafanaReporterError => e
|
56
|
-
@report.logger.error(e.message)
|
57
|
-
return create_paragraph(parent, e.message, attrs)
|
58
|
-
rescue StandardError => e
|
59
|
-
@report.logger.fatal(e.message)
|
60
|
-
return create_paragraph(parent, e.message, attrs)
|
61
|
-
end
|
62
|
-
|
63
|
-
attrs['target'] = image_path
|
64
|
-
create_image_block(parent, attrs)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'processor_mixin'
|
4
|
-
|
5
|
-
module GrafanaReporter
|
6
|
-
module Asciidoctor
|
7
|
-
module Extensions
|
8
|
-
# Implements the hook
|
9
|
-
# grafana_panel_image:<panel_id>[<options>]
|
10
|
-
#
|
11
|
-
# Stores the queried panel as a temporary image file and returns an asciidoctor link
|
12
|
-
# to be included in the report.
|
13
|
-
#
|
14
|
-
# == Used document parameters
|
15
|
-
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
16
|
-
#
|
17
|
-
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
18
|
-
#
|
19
|
-
# +from+ - 'from' time for the sql query
|
20
|
-
#
|
21
|
-
# +to+ - 'to' time for the sql query
|
22
|
-
#
|
23
|
-
# == Supported options
|
24
|
-
# +field+ - property to query for, e.g. +description+ or +title+ (*mandatory*)
|
25
|
-
#
|
26
|
-
# +instance+ - name of grafana instance, 'default' if not specified
|
27
|
-
#
|
28
|
-
# +dashboard+ - uid of grafana dashboard to use
|
29
|
-
#
|
30
|
-
# +from+ - 'from' time for the sql query
|
31
|
-
#
|
32
|
-
# +to+ - 'to' time for the sql query
|
33
|
-
class PanelImageInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
34
|
-
include ProcessorMixin
|
35
|
-
use_dsl
|
36
|
-
|
37
|
-
named :grafana_panel_image
|
38
|
-
|
39
|
-
# :nodoc:
|
40
|
-
def process(parent, target, attrs)
|
41
|
-
return if @report.cancel
|
42
|
-
|
43
|
-
@report.next_step
|
44
|
-
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
45
|
-
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
46
|
-
@report.logger.debug("Processing PanelImageInlineMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
47
|
-
" panel: #{target})")
|
48
|
-
query = PanelImageQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target))
|
49
|
-
query.merge_hash_variables(parent.document.attributes, attrs)
|
50
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
51
|
-
|
52
|
-
begin
|
53
|
-
image = query.execute(@report.grafana(instance))
|
54
|
-
image_path = @report.save_image_file(image)
|
55
|
-
rescue GrafanaReporterError => e
|
56
|
-
@report.logger.error(e.message)
|
57
|
-
return create_inline(parent, :quoted, e.message)
|
58
|
-
rescue StandardError => e
|
59
|
-
@report.logger.fatal(e.message)
|
60
|
-
return create_inline(parent, :quoted, e.message)
|
61
|
-
end
|
62
|
-
|
63
|
-
create_inline(parent, :image, nil, { target: image_path, attributes: attrs })
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'processor_mixin'
|
4
|
-
|
5
|
-
module GrafanaReporter
|
6
|
-
module Asciidoctor
|
7
|
-
module Extensions
|
8
|
-
# Implements the hook
|
9
|
-
# grafana_panel_property:<panel_id>[<options>]
|
10
|
-
#
|
11
|
-
# Returns the requested panel property.
|
12
|
-
#
|
13
|
-
# == Used document parameters
|
14
|
-
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
15
|
-
#
|
16
|
-
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
17
|
-
#
|
18
|
-
# == Supported options
|
19
|
-
# +field+ - property to query for, e.g. +description+ or +title+ (*mandatory*)
|
20
|
-
#
|
21
|
-
# +instance+ - name of grafana instance, 'default' if not specified
|
22
|
-
#
|
23
|
-
# +dashboard+ - uid of grafana dashboard to use
|
24
|
-
class PanelPropertyInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
25
|
-
include ProcessorMixin
|
26
|
-
use_dsl
|
27
|
-
|
28
|
-
named :grafana_panel_property
|
29
|
-
name_positional_attributes :field
|
30
|
-
|
31
|
-
# :nodoc:
|
32
|
-
def process(parent, target, attrs)
|
33
|
-
return if @report.cancel
|
34
|
-
|
35
|
-
@report.next_step
|
36
|
-
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
37
|
-
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
38
|
-
@report.logger.debug("Processing PanelPropertyInlineMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
39
|
-
" panel: #{target}, property: #{attrs[:field]})")
|
40
|
-
query = PanelPropertyQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target), attrs[:field])
|
41
|
-
query.merge_hash_variables(parent.document.attributes, attrs)
|
42
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
43
|
-
|
44
|
-
begin
|
45
|
-
description = query.execute(@report.grafana(instance))
|
46
|
-
rescue GrafanaReporterError => e
|
47
|
-
@report.logger.error(e.message)
|
48
|
-
return create_inline(parent, :quoted, e.message)
|
49
|
-
rescue StandardError => e
|
50
|
-
@report.logger.fatal(e.message)
|
51
|
-
return create_inline(parent, :quoted, e.message)
|
52
|
-
end
|
53
|
-
|
54
|
-
# translate linebreaks to asciidoctor syntax
|
55
|
-
# and HTML encode to make sure, that HTML formattings are respected
|
56
|
-
create_inline(parent, :quoted, CGI.escapeHTML(description.gsub(%r{//[^\n]*(?:\n)?}, '').gsub(/\n/, " +\n")))
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'processor_mixin'
|
4
|
-
|
5
|
-
module GrafanaReporter
|
6
|
-
module Asciidoctor
|
7
|
-
module Extensions
|
8
|
-
# Implements the hook
|
9
|
-
# include::grafana_panel_query_table:<panel_id>[<options>]
|
10
|
-
#
|
11
|
-
# Returns the results of the SQL query as a asciidoctor table.
|
12
|
-
#
|
13
|
-
# == Used document parameters
|
14
|
-
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
15
|
-
#
|
16
|
-
# +grafana_default_dashboard+ - uid of grafana default dashboard to use
|
17
|
-
#
|
18
|
-
# +from+ - 'from' time for the sql query
|
19
|
-
#
|
20
|
-
# +to+ - 'to' time for the sql query
|
21
|
-
#
|
22
|
-
# All other variables starting with +var-+ will be used to replace grafana templating strings
|
23
|
-
# in the given SQL query.
|
24
|
-
#
|
25
|
-
# == Supported options
|
26
|
-
# +query+ - query letter, which shall be used, e.g. +C+ (*mandatory*)
|
27
|
-
#
|
28
|
-
# +instance+ - name of grafana instance, 'default' if not specified
|
29
|
-
#
|
30
|
-
# +dashboard+ - uid of grafana dashboard to use
|
31
|
-
#
|
32
|
-
# +from+ - 'from' time for the sql query
|
33
|
-
#
|
34
|
-
# +to+ - 'to' time for the sql query
|
35
|
-
#
|
36
|
-
# +format+ - see {QueryMixin#format_columns}
|
37
|
-
#
|
38
|
-
# +replace_values+ - see {QueryMixin#replace_values}
|
39
|
-
#
|
40
|
-
# +filter_columns+ - see {QueryMixin#filter_columns}
|
41
|
-
class PanelQueryTableIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
42
|
-
include ProcessorMixin
|
43
|
-
|
44
|
-
# :nodoc:
|
45
|
-
def handles?(target)
|
46
|
-
target.start_with? 'grafana_panel_query_table:'
|
47
|
-
end
|
48
|
-
|
49
|
-
# :nodoc:
|
50
|
-
def process(doc, reader, target, attrs)
|
51
|
-
return if @report.cancel
|
52
|
-
|
53
|
-
@report.next_step
|
54
|
-
panel_id = target.split(':')[1]
|
55
|
-
instance = attrs['instance'] || doc.attr('grafana_default_instance') || 'default'
|
56
|
-
dashboard = attrs['dashboard'] || doc.attr('grafana_default_dashboard')
|
57
|
-
@report.logger.debug("Processing PanelQueryTableIncludeProcessor (instance: #{instance}, "\
|
58
|
-
"dashboard: #{dashboard}, panel: #{panel_id}, query: #{attrs['query']})")
|
59
|
-
query = PanelTableQuery.new(@report.grafana(instance).dashboard(dashboard).panel(panel_id), attrs['query'])
|
60
|
-
query.merge_hash_variables(doc.attributes, attrs)
|
61
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
62
|
-
|
63
|
-
begin
|
64
|
-
reader.unshift_lines query.execute(@report.grafana(instance))
|
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
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'processor_mixin'
|
4
|
-
|
5
|
-
module GrafanaReporter
|
6
|
-
module Asciidoctor
|
7
|
-
module Extensions
|
8
|
-
# Implements the hook
|
9
|
-
# grafana_panel_query_value:<panel_id>[<options>]
|
10
|
-
#
|
11
|
-
# Returns the first value of the resulting SQL query.
|
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
|
-
# All other variables starting with +var-+ will be used to replace grafana templating strings
|
23
|
-
# in the given SQL query.
|
24
|
-
#
|
25
|
-
# == Supported options
|
26
|
-
# +query+ - query letter, which shall be used, e.g. +C+ (*mandatory*)
|
27
|
-
#
|
28
|
-
# +instance+ - name of grafana instance, 'default' if not specified
|
29
|
-
#
|
30
|
-
# +dashboard+ - uid of grafana dashboard to use
|
31
|
-
#
|
32
|
-
# +from+ - 'from' time for the sql query
|
33
|
-
#
|
34
|
-
# +to+ - 'to' time for the sql query
|
35
|
-
#
|
36
|
-
# +format+ - see {QueryMixin#format_columns}
|
37
|
-
#
|
38
|
-
# +replace_values+ - see {QueryMixin#replace_values}
|
39
|
-
#
|
40
|
-
# +filter_columns+ - see {QueryMixin#filter_columns}
|
41
|
-
class PanelQueryValueInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
42
|
-
include ProcessorMixin
|
43
|
-
use_dsl
|
44
|
-
|
45
|
-
named :grafana_panel_query_value
|
46
|
-
|
47
|
-
# :nodoc:
|
48
|
-
def process(parent, target, attrs)
|
49
|
-
return if @report.cancel
|
50
|
-
|
51
|
-
@report.next_step
|
52
|
-
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
53
|
-
dashboard = attrs['dashboard'] || parent.document.attr('grafana_default_dashboard')
|
54
|
-
@report.logger.debug("Processing PanelQueryValueInlineMacro (instance: #{instance}, dashboard: #{dashboard},"\
|
55
|
-
" panel: #{target}, query: #{attrs['query']})")
|
56
|
-
query = PanelFirstValueQuery.new(@report.grafana(instance).dashboard(dashboard).panel(target), attrs['query'])
|
57
|
-
query.merge_hash_variables(parent.document.attributes, attrs)
|
58
|
-
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
59
|
-
|
60
|
-
begin
|
61
|
-
create_inline(parent, :quoted, query.execute(@report.grafana(instance)))
|
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
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module GrafanaReporter
|
4
|
-
module Asciidoctor
|
5
|
-
# The classes within this module implement the interface to asciidoctor. Each class implements a specific extension
|
6
|
-
# to asciidoctor.
|
7
|
-
module Extensions
|
8
|
-
# This module contains common methods for all asciidoctor extensions.
|
9
|
-
module ProcessorMixin
|
10
|
-
# Used when initializing a object instance, to set the report object, which is currently in progress.
|
11
|
-
# @param report [GrafanaReporter::Asciidoctor::Report] current report
|
12
|
-
# @return [::Asciidoctor::Extensions::Processor] self
|
13
|
-
def current_report(report)
|
14
|
-
@report = report
|
15
|
-
self
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module GrafanaReporter
|
4
|
-
module Asciidoctor
|
5
|
-
module Extensions
|
6
|
-
# Implements the hook
|
7
|
-
# include::grafana_environment[]
|
8
|
-
#
|
9
|
-
# Shows all available variables, which are accessible during this run of the asciidoctor
|
10
|
-
# grafana reporter in a asciidoctor readable form.
|
11
|
-
#
|
12
|
-
# This processor is very helpful during report template design, to find out the available
|
13
|
-
# variables, that can be accessed.
|
14
|
-
#
|
15
|
-
# == Used document parameters
|
16
|
-
# All, to be listed as the available environment.
|
17
|
-
class ShowEnvironmentIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
18
|
-
include ProcessorMixin
|
19
|
-
|
20
|
-
# :nodoc:
|
21
|
-
def handles?(target)
|
22
|
-
target.start_with? 'grafana_environment'
|
23
|
-
end
|
24
|
-
|
25
|
-
# :nodoc:
|
26
|
-
def process(doc, reader, _target, _attrs)
|
27
|
-
# return if @report.cancel
|
28
|
-
@report.next_step
|
29
|
-
@report.logger.debug('Processing ShowEnvironmentIncludeProcessor')
|
30
|
-
|
31
|
-
vars = ['== Accessible Variables',
|
32
|
-
'|===']
|
33
|
-
doc.attributes.sort.each do |k, v|
|
34
|
-
vars << "| `+{#{k}}+` | #{v}"
|
35
|
-
end
|
36
|
-
vars << '|==='
|
37
|
-
|
38
|
-
reader.unshift_lines vars
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,228 +0,0 @@
|
|
1
|
-
module GrafanaReporter
|
2
|
-
module Asciidoctor
|
3
|
-
module Extensions
|
4
|
-
# Implements the hook
|
5
|
-
# include::grafana_help[]
|
6
|
-
#
|
7
|
-
# Shows all available options for the asciidoctor grafana reporter in a asciidoctor readable form.
|
8
|
-
#
|
9
|
-
# == Used document parameters
|
10
|
-
# None
|
11
|
-
class ShowHelpIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
12
|
-
include ProcessorMixin
|
13
|
-
|
14
|
-
# :nodoc:
|
15
|
-
def handles?(target)
|
16
|
-
target.start_with? 'grafana_help'
|
17
|
-
end
|
18
|
-
|
19
|
-
# :nodoc:
|
20
|
-
def replaces_variables(where = nil)
|
21
|
-
"https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax[Grafana variables] will be replaced#{' ' + where.to_s if where}."
|
22
|
-
end
|
23
|
-
|
24
|
-
# :nodoc:
|
25
|
-
def process(_doc, reader, _target, _attrs)
|
26
|
-
# return if @report.cancel
|
27
|
-
@report.next_step
|
28
|
-
@report.logger.debug('Processing ShowHelpIncludeProcessor')
|
29
|
-
exec_order = 'Execution is applied in the following order: `format`, `replace_values`, `filter_columns`, `transpose`.'
|
30
|
-
|
31
|
-
param_instance = '| `instance="<instance_name>"` | can be used to override global grafana instance, set in the report with `grafana_default_instance`. If nothing is set, the configured grafana instance with name `default` will be used.'
|
32
|
-
param_dashboard = '| `dashboard="<dashboard_uid>"` | Specifies the dashboard to be used. If `grafana_default_dashboard` is specified in the report template, this value can be overridden with this option.'
|
33
|
-
param_from = '| `from="<from_timestamp>"` | can be used to override default `from` time'
|
34
|
-
param_to = '| `to="<to_timestamp>"` | can be used to override default `to` time'
|
35
|
-
|
36
|
-
param_format = '| `format="<format_col1>,<format_col2>,..."` | Specify format in which the results shall be returned, e.g. `%.2f` for only two digit decimals of a float. Several columns are separated by `,`. For details see https://ruby-doc.org/core-2.4.0/Kernel.html#method-i-sprintf[Ruby documentation].'
|
37
|
-
param_replace_values = "| `replace_values=\"<replace_1>:<with_1>,<replace_2>:<with_2>,...\"` | Specify result values which shall be replaced, e.g. `2:OK` will replace query values `2` with value `OK`. Replacing several values is possible by separating by `,`. Matches with regular expressions are also supported, but must be full matches, i.e. have to start with `^` and end with `$`, e.g. `^[012]$:OK`. For details see https://ruby-doc.org/core-2.7.1/Regexp.html#class-Regexp-label-Character+Classes[Ruby Regexp class]. Number replacements can also be performed, e.g. `<8.2` or `<>3`. #{exec_order}"
|
38
|
-
param_filter_columns = '| `filter_columns="<column_name_1>,<column_name_2>,..."` | Removes specified columns from result.'
|
39
|
-
param_transpose = '| `transpose="true"` | Transposes the query result, i.e. columns become rows and rows become columnns.'
|
40
|
-
param_column_divider = '| `column_divider="<divider>"` | Replace the default column divider with another one. Defaults to ` | ` for being interpreted as a asciidoctor column.'
|
41
|
-
param_row_divider = '| `row_divider="<divider>"` | Replace the default row divider with another one. Defaults to `| ` for being interpreted as a asciidoctor row.'
|
42
|
-
param_timeout = '| `timeout="<timeout_in_seconds>" | Set a timeout for the current query. If not overridden with `grafana-default-timeout` in the report template, this defaults to 60 seconds.'
|
43
|
-
|
44
|
-
help = "
|
45
|
-
== Grafana Reporter Functions
|
46
|
-
=== `grafana_help`
|
47
|
-
[cols=\"~,80\"]
|
48
|
-
|===
|
49
|
-
| Call | `+include::grafana_help[]+`
|
50
|
-
| Description | Shows this information.
|
51
|
-
|===
|
52
|
-
|
53
|
-
=== `grafana_environment`
|
54
|
-
[cols=\"~,80\"]
|
55
|
-
|===
|
56
|
-
| Call | `+include::grafana_environment[]+`
|
57
|
-
| Description | Shows all available variables in the rendering context which can be used in the document.
|
58
|
-
|===
|
59
|
-
|
60
|
-
=== `grafana_alerts`
|
61
|
-
[cols=\"~,80\"]
|
62
|
-
|===
|
63
|
-
| Call | `+grafana_alerts[columns=\"<column_name_1>,<column_name_2>,...\",options]+`
|
64
|
-
| Description | Returns a table of active alert states with the specified columns. Valid colums are `id`, `dashboardId`, `dashboardUId`, `dashboardSlug`, `panelId`, `name`, `state`, `newStateDate`, `evalDate`, `evalData` and `executionError` (for details see https://grafana.com/docs/grafana/latest/http_api/alerting/#get-alerts[Grafana Alerting API]).
|
65
|
-
|===
|
66
|
-
[%autowidth.stretch, options=\"header\"]
|
67
|
-
|===
|
68
|
-
| Option | Description
|
69
|
-
#{param_column_divider}
|
70
|
-
#{param_dashboard} If this option, or the global option `grafana_default_dashboard` is set, the resulting alerts will be limited to this dashboard. To show all alerts in this case, specify `dashboard=\"\"` as option.
|
71
|
-
#{param_filter_columns} #{exec_order}
|
72
|
-
#{param_format} #{exec_order}
|
73
|
-
#{param_from}
|
74
|
-
#{param_instance}
|
75
|
-
| `panel=\"<panel_id>\"` | If specified, the resulting alerts are filtered for this panel. This option will only work, if a `dashboard` or `grafana_default_dashboard` is set.
|
76
|
-
#{param_replace_values} #{exec_order}
|
77
|
-
#{param_row_divider}
|
78
|
-
#{param_timeout}
|
79
|
-
#{param_to}
|
80
|
-
#{param_transpose} #{exec_order}
|
81
|
-
|===
|
82
|
-
Additionally all query parameters from the https://grafana.com/docs/grafana/latest/http_api/alerting/#get-alerts[Grafana Alerting API], such as `query`, `state`, `limit`, `folderId` and others are supported.
|
83
|
-
|
84
|
-
=== `grafana_annotations`
|
85
|
-
[cols=\"~,80\"]
|
86
|
-
|===
|
87
|
-
| Call | `+grafana_annotations[columns=\"<column_name_1>,<column_name_2>,...\",options]+`
|
88
|
-
| Description | Returns a table of all annotations, matching the specified filter criteria and the specified columns. Valid colums are `id`, `alertId`, `dashboardId`, `panelId`, `userId`, `userName`, `newState`, `prevState, `time`, `timeEnd`, `text`, `metric` and `type` (for details see https://grafana.com/docs/grafana/latest/http_api/annotations/#find_annotations[Grafana Annotations API]).
|
89
|
-
|===
|
90
|
-
[%autowidth.stretch, options=\"header\"]
|
91
|
-
|===
|
92
|
-
| Option | Description
|
93
|
-
#{param_column_divider}
|
94
|
-
#{param_dashboard} If this option, or the global option `grafana_default_dashboard` is set, the resulting annotations will be limited to this dashboard. To show all annotations in this case, specify `dashboard=\"\"` as option.
|
95
|
-
#{param_filter_columns} #{exec_order}
|
96
|
-
#{param_format} #{exec_order}
|
97
|
-
#{param_from}
|
98
|
-
#{param_instance}
|
99
|
-
| `panel=\"<panel_id>\"` | If specified, the resulting annotations are filtered for this panel. This option will only work, if a `dashboard` or `grafana_default_dashboard` is set.
|
100
|
-
#{param_replace_values} #{exec_order}
|
101
|
-
#{param_row_divider}
|
102
|
-
#{param_timeout}
|
103
|
-
#{param_to}
|
104
|
-
#{param_transpose} #{exec_order}
|
105
|
-
|===
|
106
|
-
Additionally all quer parameters from the https://grafana.com/docs/grafana/latest/http_api/annotations/#find_annotations[Grafana Alerting API], such as `limit`, `alertId`, `panelId` and others are supported.
|
107
|
-
|
108
|
-
=== `grafana_panel_description`
|
109
|
-
[cols=\"~,80\"]
|
110
|
-
|===
|
111
|
-
| Call | `+grafana_panel_description:<panel_id>[\"<type>\",options]+`
|
112
|
-
| Description | Returns a description field for the specified panel. `+<type>+` can either be `title` or `description`. #{replaces_variables('in the returned value')}
|
113
|
-
|===
|
114
|
-
[%autowidth.stretch, options=\"header\"]
|
115
|
-
|===
|
116
|
-
| Option | Description
|
117
|
-
#{param_dashboard}
|
118
|
-
#{param_instance}
|
119
|
-
|===
|
120
|
-
|
121
|
-
=== `grafana_panel_image`
|
122
|
-
[cols=\"~,80\"]
|
123
|
-
|===
|
124
|
-
| Call Inline | `+grafana_panel_image:<panel_id>[options]+`
|
125
|
-
| Call Block | `+grafana_panel_image::<panel_id>[options]+`
|
126
|
-
| Description | Includes a panel image as an image in the document. Can be calles for inline-images as well as for blocks.
|
127
|
-
|===
|
128
|
-
[%autowidth.stretch, options=\"header\"]
|
129
|
-
|===
|
130
|
-
| Option | Description
|
131
|
-
#{param_dashboard}
|
132
|
-
#{param_from}
|
133
|
-
#{param_instance}
|
134
|
-
#{param_timeout}
|
135
|
-
#{param_to}
|
136
|
-
| `render-height=\"<height>\"` | can be used to override default `height` in which the panel shall be rendered
|
137
|
-
| `render-width=\"<width>\"` | can be used to override default `width` in which the panel shall be rendered
|
138
|
-
| `render-theme=\"<theme>\"` | can be used to override default `theme` in which the panel shall be rendered (`light` by default)
|
139
|
-
| `render-timeout=\"<timeout>\"` | can be used to override default `timeout` in which the panel shall be rendered (60 seconds by default)
|
140
|
-
|===
|
141
|
-
|
142
|
-
=== `grafana_panel_query_table`
|
143
|
-
[cols=\"~,80\"]
|
144
|
-
|===
|
145
|
-
| Call | `+include:grafana_panel_query_table:<panel_id>[query=\"<query_letter>\",options]+`
|
146
|
-
| Description | Returns the results of a query, which is configured in a grafana panel, as a table in asciidoc. `+<query_letter>+` needs to point to the grafana query which shall be evaluated, e.g. `A` or `B`. #{replaces_variables("in the panel's SQL statement")}
|
147
|
-
|===
|
148
|
-
[%autowidth.stretch, options=\"header\"]
|
149
|
-
|===
|
150
|
-
| Option | Description
|
151
|
-
#{param_column_divider}
|
152
|
-
#{param_dashboard}
|
153
|
-
#{param_filter_columns} #{exec_order}
|
154
|
-
#{param_format} #{exec_order}
|
155
|
-
#{param_from}
|
156
|
-
#{param_instance}
|
157
|
-
#{param_replace_values} #{exec_order}
|
158
|
-
#{param_row_divider}
|
159
|
-
#{param_timeout}
|
160
|
-
#{param_to}
|
161
|
-
#{param_transpose} #{exec_order}
|
162
|
-
|===
|
163
|
-
|
164
|
-
=== `grafana_panel_query_value`
|
165
|
-
[cols=\"~,80\"]
|
166
|
-
|===
|
167
|
-
| Call | `+grafana_panel_query_value:<panel_id>[query=\"<query_letter>\",options]+`
|
168
|
-
| Description | Returns the first returned value of in the first column of a query, which is configured in a grafana panel. `+<query_letter>+` needs to point to the grafana query which shall be evaluated, e.g. `A` or `B`. #{replaces_variables("in the panel's SQL statement")}
|
169
|
-
|===
|
170
|
-
[%autowidth.stretch, options=\"header\"]
|
171
|
-
|===
|
172
|
-
| Option | Description
|
173
|
-
#{param_dashboard}
|
174
|
-
#{param_filter_columns} #{exec_order}
|
175
|
-
#{param_format} #{exec_order}
|
176
|
-
#{param_from}
|
177
|
-
#{param_instance}
|
178
|
-
#{param_replace_values} #{exec_order}
|
179
|
-
#{param_row_divider}
|
180
|
-
#{param_timeout}
|
181
|
-
#{param_to}
|
182
|
-
|===
|
183
|
-
|
184
|
-
=== `grafana_sql_table`
|
185
|
-
[cols=\"~,80\"]
|
186
|
-
|===
|
187
|
-
| Call | `+include::grafana_sql_table:<datasource_id>[sql=\"<sql_query>\",options]+`
|
188
|
-
| Description | Returns a table with all results of the given query. #{replaces_variables('in the SQL statement')}
|
189
|
-
|===
|
190
|
-
[%autowidth.stretch, options=\"header\"]
|
191
|
-
|===
|
192
|
-
| Option | Description
|
193
|
-
#{param_column_divider}
|
194
|
-
#{param_filter_columns} #{exec_order}
|
195
|
-
#{param_format} #{exec_order}
|
196
|
-
#{param_from}
|
197
|
-
#{param_instance}
|
198
|
-
#{param_replace_values} #{exec_order}
|
199
|
-
#{param_row_divider}
|
200
|
-
#{param_timeout}
|
201
|
-
#{param_to}
|
202
|
-
#{param_transpose} #{exec_order}
|
203
|
-
|===
|
204
|
-
|
205
|
-
=== `grafana_sql_value`
|
206
|
-
[cols=\"~,80\"]
|
207
|
-
|===
|
208
|
-
| Call | `+grafana_sql_value:<datasource_id>[sql=\"<sql_query>\",options]+`
|
209
|
-
| Description | Returns a table with all results of the given query. #{replaces_variables('in the SQL statement')}
|
210
|
-
|===
|
211
|
-
[%autowidth.stretch, options=\"header\"]
|
212
|
-
|===
|
213
|
-
| Option | Description
|
214
|
-
#{param_filter_columns} #{exec_order}
|
215
|
-
#{param_format} #{exec_order}
|
216
|
-
#{param_from}
|
217
|
-
#{param_instance}
|
218
|
-
#{param_replace_values} #{exec_order}
|
219
|
-
#{param_timeout}
|
220
|
-
#{param_to}
|
221
|
-
|==="
|
222
|
-
|
223
|
-
reader.unshift_lines help.split("\n")
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|