ruby-grafana-reporter 0.1.6 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +0 -0
- data/README.md +95 -173
- data/bin/ruby-grafana-reporter +5 -0
- data/lib/VERSION.rb +5 -3
- data/lib/grafana/abstract_panel_query.rb +22 -20
- data/lib/grafana/abstract_query.rb +132 -127
- data/lib/grafana/abstract_sql_query.rb +51 -42
- data/lib/grafana/dashboard.rb +77 -66
- data/lib/grafana/errors.rb +66 -61
- data/lib/grafana/grafana.rb +133 -131
- data/lib/grafana/panel.rb +41 -39
- data/lib/grafana/panel_image_query.rb +52 -49
- data/lib/grafana/variable.rb +217 -259
- data/lib/grafana_reporter/abstract_report.rb +112 -109
- data/lib/grafana_reporter/application/application.rb +158 -229
- data/lib/grafana_reporter/application/errors.rb +33 -30
- data/lib/grafana_reporter/application/webservice.rb +230 -0
- data/lib/grafana_reporter/asciidoctor/alerts_table_query.rb +101 -99
- data/lib/grafana_reporter/asciidoctor/annotations_table_query.rb +96 -96
- data/lib/grafana_reporter/asciidoctor/errors.rb +40 -37
- data/lib/grafana_reporter/asciidoctor/extensions/alerts_table_include_processor.rb +92 -86
- data/lib/grafana_reporter/asciidoctor/extensions/annotations_table_include_processor.rb +91 -86
- data/lib/grafana_reporter/asciidoctor/extensions/panel_image_block_macro.rb +69 -67
- data/lib/grafana_reporter/asciidoctor/extensions/panel_image_inline_macro.rb +68 -65
- data/lib/grafana_reporter/asciidoctor/extensions/panel_property_inline_macro.rb +61 -58
- data/lib/grafana_reporter/asciidoctor/extensions/panel_query_table_include_processor.rb +78 -75
- data/lib/grafana_reporter/asciidoctor/extensions/panel_query_value_inline_macro.rb +73 -70
- data/lib/grafana_reporter/asciidoctor/extensions/processor_mixin.rb +20 -18
- data/lib/grafana_reporter/asciidoctor/extensions/show_environment_include_processor.rb +43 -41
- data/lib/grafana_reporter/asciidoctor/extensions/show_help_include_processor.rb +30 -202
- data/lib/grafana_reporter/asciidoctor/extensions/sql_table_include_processor.rb +70 -67
- data/lib/grafana_reporter/asciidoctor/extensions/sql_value_inline_macro.rb +66 -65
- data/lib/grafana_reporter/asciidoctor/extensions/value_as_variable_include_processor.rb +88 -57
- data/lib/grafana_reporter/asciidoctor/help.rb +435 -0
- data/lib/grafana_reporter/asciidoctor/panel_first_value_query.rb +36 -32
- data/lib/grafana_reporter/asciidoctor/panel_image_query.rb +28 -23
- data/lib/grafana_reporter/asciidoctor/panel_property_query.rb +44 -43
- data/lib/grafana_reporter/asciidoctor/panel_table_query.rb +40 -36
- data/lib/grafana_reporter/asciidoctor/query_mixin.rb +312 -309
- data/lib/grafana_reporter/asciidoctor/report.rb +179 -159
- data/lib/grafana_reporter/asciidoctor/sql_first_value_query.rb +42 -34
- data/lib/grafana_reporter/asciidoctor/sql_table_query.rb +44 -32
- data/lib/grafana_reporter/configuration.rb +304 -326
- data/lib/grafana_reporter/console_configuration_wizard.rb +269 -0
- data/lib/grafana_reporter/errors.rb +48 -38
- data/lib/grafana_reporter/logger/two_way_logger.rb +58 -52
- data/lib/ruby-grafana-reporter.rb +32 -27
- metadata +116 -16
@@ -1,67 +1,70 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# +
|
13
|
-
#
|
14
|
-
# +
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# +
|
23
|
-
#
|
24
|
-
# +
|
25
|
-
#
|
26
|
-
# +
|
27
|
-
#
|
28
|
-
# +
|
29
|
-
#
|
30
|
-
# +
|
31
|
-
#
|
32
|
-
# +
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@report.
|
46
|
-
|
47
|
-
@report.
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
reader.
|
57
|
-
rescue
|
58
|
-
@report.logger.
|
59
|
-
reader.unshift_line
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
module Asciidoctor
|
5
|
+
module Extensions
|
6
|
+
# Implements the hook
|
7
|
+
# include::grafana_sql_table:<datasource_id>[<options>]
|
8
|
+
#
|
9
|
+
# Returns the results of the SQL query as a asciidoctor table.
|
10
|
+
#
|
11
|
+
# == Used document parameters
|
12
|
+
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
13
|
+
#
|
14
|
+
# +from+ - 'from' time for the sql query
|
15
|
+
#
|
16
|
+
# +to+ - 'to' time for the sql query
|
17
|
+
#
|
18
|
+
# All other variables starting with +var-+ will be used to replace grafana templating strings
|
19
|
+
# in the given SQL query.
|
20
|
+
#
|
21
|
+
# == Supported options
|
22
|
+
# +sql+ - sql statement (*mandatory*)
|
23
|
+
#
|
24
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
25
|
+
#
|
26
|
+
# +from+ - 'from' time for the sql query
|
27
|
+
#
|
28
|
+
# +to+ - 'to' time for the sql query
|
29
|
+
#
|
30
|
+
# +format+ - see {QueryMixin#format_columns}
|
31
|
+
#
|
32
|
+
# +replace_values+ - see {QueryMixin#replace_values}
|
33
|
+
#
|
34
|
+
# +filter_columns+ - see {QueryMixin#filter_columns}
|
35
|
+
class SqlTableIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
36
|
+
include ProcessorMixin
|
37
|
+
|
38
|
+
# :nodoc:
|
39
|
+
def handles?(target)
|
40
|
+
target.start_with? 'grafana_sql_table:'
|
41
|
+
end
|
42
|
+
|
43
|
+
# :nodoc:
|
44
|
+
def process(doc, reader, target, attrs)
|
45
|
+
return if @report.cancel
|
46
|
+
|
47
|
+
@report.next_step
|
48
|
+
instance = attrs['instance'] || doc.attr('grafana_default_instance') || 'default'
|
49
|
+
@report.logger.debug("Processing SqlTableIncludeProcessor (instance: #{instance},"\
|
50
|
+
" datasource: #{target.split(':')[1]}, sql: #{attrs['sql']})")
|
51
|
+
query = SqlTableQuery.new(attrs['sql'], target.split(':')[1])
|
52
|
+
query.merge_hash_variables(doc.attributes, attrs)
|
53
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
54
|
+
|
55
|
+
begin
|
56
|
+
reader.unshift_lines query.execute(@report.grafana(instance))
|
57
|
+
rescue GrafanaReporterError => e
|
58
|
+
@report.logger.error(e.message)
|
59
|
+
reader.unshift_line "|#{e.message}"
|
60
|
+
rescue StandardError => e
|
61
|
+
@report.logger.fatal(e.message)
|
62
|
+
reader.unshift_line "|#{e.message}"
|
63
|
+
end
|
64
|
+
|
65
|
+
reader
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -1,65 +1,66 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# Implements the hook
|
7
|
-
# grafana_sql_value:<datasource_id>[<options>]
|
8
|
-
#
|
9
|
-
# Returns the first value of the resulting SQL query.
|
10
|
-
#
|
11
|
-
# == Used document parameters
|
12
|
-
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
13
|
-
#
|
14
|
-
# +from+ - 'from' time for the sql query
|
15
|
-
#
|
16
|
-
# +to+ - 'to' time for the sql query
|
17
|
-
#
|
18
|
-
# All other variables starting with +var-+ will be used to replace grafana templating strings
|
19
|
-
# in the given SQL query.
|
20
|
-
#
|
21
|
-
# == Supported options
|
22
|
-
# +sql+ - sql statement (*mandatory*)
|
23
|
-
#
|
24
|
-
# +instance+ - name of grafana instance, 'default' if not specified
|
25
|
-
#
|
26
|
-
# +from+ - 'from' time for the sql query
|
27
|
-
#
|
28
|
-
# +to+ - 'to' time for the sql query
|
29
|
-
#
|
30
|
-
# +format+ - see {QueryMixin#format_columns}
|
31
|
-
#
|
32
|
-
# +replace_values+ - see {QueryMixin#replace_values}
|
33
|
-
#
|
34
|
-
# +filter_columns+ - see {QueryMixin#filter_columns}
|
35
|
-
class SqlValueInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
36
|
-
include ProcessorMixin
|
37
|
-
use_dsl
|
38
|
-
|
39
|
-
named :grafana_sql_value
|
40
|
-
|
41
|
-
# @see GrafanaReporter::Asciidoctor::SqlFirstValueQuery
|
42
|
-
def process(parent, target, attrs)
|
43
|
-
return if @report.cancel
|
44
|
-
|
45
|
-
@report.next_step
|
46
|
-
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
47
|
-
@report.logger.debug("Processing SqlValueInlineMacro (instance: #{instance}, datasource: #{target},
|
48
|
-
|
49
|
-
query.
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
module Asciidoctor
|
5
|
+
module Extensions
|
6
|
+
# Implements the hook
|
7
|
+
# grafana_sql_value:<datasource_id>[<options>]
|
8
|
+
#
|
9
|
+
# Returns the first value of the resulting SQL query.
|
10
|
+
#
|
11
|
+
# == Used document parameters
|
12
|
+
# +grafana_default_instance+ - name of grafana instance, 'default' if not specified
|
13
|
+
#
|
14
|
+
# +from+ - 'from' time for the sql query
|
15
|
+
#
|
16
|
+
# +to+ - 'to' time for the sql query
|
17
|
+
#
|
18
|
+
# All other variables starting with +var-+ will be used to replace grafana templating strings
|
19
|
+
# in the given SQL query.
|
20
|
+
#
|
21
|
+
# == Supported options
|
22
|
+
# +sql+ - sql statement (*mandatory*)
|
23
|
+
#
|
24
|
+
# +instance+ - name of grafana instance, 'default' if not specified
|
25
|
+
#
|
26
|
+
# +from+ - 'from' time for the sql query
|
27
|
+
#
|
28
|
+
# +to+ - 'to' time for the sql query
|
29
|
+
#
|
30
|
+
# +format+ - see {QueryMixin#format_columns}
|
31
|
+
#
|
32
|
+
# +replace_values+ - see {QueryMixin#replace_values}
|
33
|
+
#
|
34
|
+
# +filter_columns+ - see {QueryMixin#filter_columns}
|
35
|
+
class SqlValueInlineMacro < ::Asciidoctor::Extensions::InlineMacroProcessor
|
36
|
+
include ProcessorMixin
|
37
|
+
use_dsl
|
38
|
+
|
39
|
+
named :grafana_sql_value
|
40
|
+
|
41
|
+
# @see GrafanaReporter::Asciidoctor::SqlFirstValueQuery
|
42
|
+
def process(parent, target, attrs)
|
43
|
+
return if @report.cancel
|
44
|
+
|
45
|
+
@report.next_step
|
46
|
+
instance = attrs['instance'] || parent.document.attr('grafana_default_instance') || 'default'
|
47
|
+
@report.logger.debug("Processing SqlValueInlineMacro (instance: #{instance}, datasource: #{target},"\
|
48
|
+
" sql: #{attrs['sql']})")
|
49
|
+
query = SqlFirstValueQuery.new(attrs['sql'], target)
|
50
|
+
query.merge_hash_variables(parent.document.attributes, attrs)
|
51
|
+
@report.logger.debug("from: #{query.from}, to: #{query.to}")
|
52
|
+
|
53
|
+
begin
|
54
|
+
create_inline(parent, :quoted, query.execute(@report.grafana(instance)))
|
55
|
+
rescue GrafanaReporterError => e
|
56
|
+
@report.logger.error(e.message)
|
57
|
+
create_inline(parent, :quoted, e.message)
|
58
|
+
rescue StandardError => e
|
59
|
+
@report.logger.fatal(e.message)
|
60
|
+
create_inline(parent, :quoted, e.message)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -1,57 +1,88 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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_value_as_variable[<options>]
|
10
|
+
#
|
11
|
+
# Returns an attribute definition in asciidoctor format. This is needed if you want to refer to values of
|
12
|
+
# a grafana query within a variable in asciidoctor. As this works without this function for the
|
13
|
+
# `IncludeProcessor`s values, it will not work for all the other processors.
|
14
|
+
#
|
15
|
+
# This method is just a proxy for all other hooks and will forward parameters accordingly.
|
16
|
+
#
|
17
|
+
# Example:
|
18
|
+
#
|
19
|
+
# include:grafana_value_as_variable[call="grafana_sql_value:1",variable_name="my_variable",sql="SELECT 'looks good'",<any_other_option>]
|
20
|
+
#
|
21
|
+
# This will call the {SqlValueInlineMacro} with `datasource_id` set to `1` and store the result in the
|
22
|
+
# variable. The resulting asciidoctor variable definition will be created as:
|
23
|
+
#
|
24
|
+
# :my_variable: looks good
|
25
|
+
#
|
26
|
+
# and can be refered to in your document easily as
|
27
|
+
#
|
28
|
+
# {my_variable}
|
29
|
+
#
|
30
|
+
# == Supported options
|
31
|
+
# +call+ - regular call to the reporter hook (*mandatory*)
|
32
|
+
#
|
33
|
+
# +variable_name+ - name of the variable, to which the result shall be assigned (*mandatory*)
|
34
|
+
class ValueAsVariableIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
35
|
+
include ProcessorMixin
|
36
|
+
|
37
|
+
# :nodoc:
|
38
|
+
def handles?(target)
|
39
|
+
target.start_with? 'grafana_value_as_variable'
|
40
|
+
end
|
41
|
+
|
42
|
+
# :nodoc:
|
43
|
+
def process(doc, reader, target, attrs)
|
44
|
+
return if @report.cancel
|
45
|
+
|
46
|
+
# do NOT increase step, as this is done by sub processor
|
47
|
+
# @report.next_step
|
48
|
+
|
49
|
+
call_attr = attrs.delete('call')
|
50
|
+
call, target = call_attr.split(':') if call_attr
|
51
|
+
attribute = attrs.delete('variable_name')
|
52
|
+
@report.logger.debug("Processing ValueAsVariableIncludeProcessor (call: #{call}, target: #{target},"\
|
53
|
+
" variable_name: #{attribute}, attrs: #{attrs})")
|
54
|
+
if !call || !attribute
|
55
|
+
@report.logger.error('ValueAsVariableIncludeProcessor: Missing mandatory attribute \'call\' or '\
|
56
|
+
'\'variable_name\'.')
|
57
|
+
return reader
|
58
|
+
end
|
59
|
+
|
60
|
+
# TODO: remove dirty hack to allow the document as parameter for other processors
|
61
|
+
def doc.document
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
# TODO: properly show error messages also in document
|
66
|
+
ext = doc.extensions.find_inline_macro_extension(call) if doc.extensions.inline_macros?
|
67
|
+
if !ext
|
68
|
+
@report.logger.error('ValueAsVariableIncludeProcessor: Could not find inline macro extension for '\
|
69
|
+
"'#{call}'.")
|
70
|
+
else
|
71
|
+
@report.logger.debug('ValueAsVariableIncludeProcessor: Calling sub-method.')
|
72
|
+
item = ext.process_method.call(doc, target, attrs)
|
73
|
+
if !item.text.to_s.empty?
|
74
|
+
result = ":#{attribute}: #{item.text}"
|
75
|
+
@report.logger.debug("ValueAsVariableIncludeProcessor: Adding '#{result}' to document.")
|
76
|
+
reader.unshift_line(result)
|
77
|
+
else
|
78
|
+
@report.logger.debug("ValueAsVariableIncludeProcessor: Not adding variable '#{attribute}'"\
|
79
|
+
' as query result was empty.')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
reader
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,435 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module GrafanaReporter
|
6
|
+
module Asciidoctor
|
7
|
+
class Help
|
8
|
+
def asciidoctor(headline_level = 2)
|
9
|
+
help_text(asciidoctor_options.merge(level: headline_level))
|
10
|
+
end
|
11
|
+
|
12
|
+
def github(headline_level = 2)
|
13
|
+
"#{toc}\n\n#{help_text(github_options.merge(level: headline_level))}"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def github_options
|
19
|
+
{ headline_separator: '#', code_begin: '`', code_end: '`', table_begin: "\n", head_postfix_col: '| -- ' }
|
20
|
+
end
|
21
|
+
|
22
|
+
def asciidoctor_options
|
23
|
+
{ headline_separator: '=', code_begin: '`+', code_end: '+`', table_begin: "\n[%autowidth.stretch, options=\"header\"]\n|===\n", table_end: "\n|===" }
|
24
|
+
end
|
25
|
+
|
26
|
+
def help_text(opts)
|
27
|
+
%(#{opts[:headline_separator] * opts[:level]} Global options
|
28
|
+
#{global_options_as_text(opts.merge(level: opts[:level] + 1))}
|
29
|
+
#{opts[:headline_separator] * opts[:level]} Functions
|
30
|
+
#{functions_as_text(opts.merge(level: opts[:level] + 1))})
|
31
|
+
end
|
32
|
+
|
33
|
+
def toc
|
34
|
+
result = []
|
35
|
+
|
36
|
+
result << "Table of contents"
|
37
|
+
result << "* [Global options](#global-options)"
|
38
|
+
prepared_help[:global_options].sort.map do |k, _v|
|
39
|
+
result << " * [#{k}](##{k.downcase})"
|
40
|
+
end
|
41
|
+
|
42
|
+
result << "* [Functions](#functions)"
|
43
|
+
prepared_help[:functions].sort.map do |k, _v|
|
44
|
+
result << " * [#{k}](##{k.downcase})"
|
45
|
+
end
|
46
|
+
|
47
|
+
result.join("\n")
|
48
|
+
end
|
49
|
+
|
50
|
+
def global_options_as_text(opts = {})
|
51
|
+
opts = { level: 3 }.merge(opts)
|
52
|
+
result = []
|
53
|
+
|
54
|
+
prepared_help[:global_options].sort.map do |k, v|
|
55
|
+
result << %(
|
56
|
+
#{opts[:headline_separator] * opts[:level]} #{opts[:code_begin]}#{k}#{opts[:code_end]}
|
57
|
+
Usage: #{opts[:code_begin]}#{v['call']}#{opts[:code_end]}
|
58
|
+
|
59
|
+
#{v['description']}
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
result.join
|
64
|
+
end
|
65
|
+
|
66
|
+
def functions_as_text(opts = {})
|
67
|
+
opts = { level: 3, headline_separator: '=' }.merge(opts)
|
68
|
+
result = []
|
69
|
+
|
70
|
+
prepared_help[:functions].sort.map do |k, v|
|
71
|
+
result << %(
|
72
|
+
#{opts[:headline_separator] * opts[:level]} #{opts[:code_begin]}#{k}#{opts[:code_end]}
|
73
|
+
Usage: #{opts[:code_begin]}#{v[:call]}#{opts[:code_end]}
|
74
|
+
|
75
|
+
#{v[:description]}#{"\n\nSee also: #{v[:see]}" if v[:see]}#{unless v[:options].empty?
|
76
|
+
%(
|
77
|
+
#{opts[:table_begin]}| Option | Description#{"\n#{opts[:head_postfix_col] * 2}" if opts[:head_postfix_col]}
|
78
|
+
#{v[:options].sort.map { |_opt_k, opt_v| "| #{opts[:code_begin]}#{opt_v[:call]}#{opts[:code_end]} | #{opt_v[:description].gsub('|', '\|')}" }.join("\n") }#{opts[:table_end]})
|
79
|
+
end}
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
result.join
|
84
|
+
end
|
85
|
+
|
86
|
+
def prepared_help
|
87
|
+
yaml = YAML.safe_load(raw_help_yaml)
|
88
|
+
|
89
|
+
result = {}
|
90
|
+
result[:functions] = {}
|
91
|
+
result[:global_options] = yaml['global_options']
|
92
|
+
|
93
|
+
functions = result[:functions]
|
94
|
+
std_opts = yaml['standard_options']
|
95
|
+
yaml.reject { |k, _v| k =~ /.*_options$/ }.each_key do |key|
|
96
|
+
functions[key] = {}
|
97
|
+
res_item = functions[key]
|
98
|
+
res_item[:options] = {}
|
99
|
+
|
100
|
+
item = yaml[key]
|
101
|
+
res_item[:call] = item['call']
|
102
|
+
res_item[:description] = item['description']
|
103
|
+
res_item[:see] = item['see']
|
104
|
+
|
105
|
+
opts = ((item['options'] ? item['options'].keys : []) + (item['standard_options'] ? item['standard_options'].keys : [])).sort
|
106
|
+
opts.each do |opt_key|
|
107
|
+
res_item[:options][opt_key] = {}
|
108
|
+
|
109
|
+
if item['standard_options'].key?(opt_key)
|
110
|
+
res_item[:options][opt_key][:call] = std_opts[opt_key]['call']
|
111
|
+
res_item[:options][opt_key][:description] = "#{std_opts[opt_key]['description']} #{item['standard_options'][opt_key]}".chop
|
112
|
+
res_item[:options][opt_key][:see] = std_opts[opt_key]['see'] if std_opts[opt_key]['see']
|
113
|
+
else
|
114
|
+
res_item[:options][opt_key][:call] = item['options'][opt_key]['call']
|
115
|
+
res_item[:options][opt_key][:description] = item['options'][opt_key]['description']
|
116
|
+
res_item[:options][opt_key][:see] = item['options'][opt_key]['see'] if item['options'][opt_key]['see']
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
result
|
122
|
+
end
|
123
|
+
|
124
|
+
def raw_help_yaml
|
125
|
+
<<YAML_HELP
|
126
|
+
global_options:
|
127
|
+
grafana_default_instance:
|
128
|
+
call: ":grafana_default_instance: <instance_name>"
|
129
|
+
description: >-
|
130
|
+
Specifies which grafana instance shall be used. If not set, the grafana instance names `default`
|
131
|
+
will be used.
|
132
|
+
|
133
|
+
grafana_default_dashboard:
|
134
|
+
call: ":grafana_default_dashboard: <dashboard_uid>"
|
135
|
+
description: >-
|
136
|
+
Specifies to which dashboard the queries shall be targeted by default.
|
137
|
+
|
138
|
+
grafana_default_from_timezone:
|
139
|
+
call: ":grafana_default_from_timezone: <timezone>"
|
140
|
+
description: Specifies which timezone shall be used for the `from` time, e.g. `CET` or `CEST`.
|
141
|
+
|
142
|
+
grafana_default_to_timezone:
|
143
|
+
call: ":grafana_default_to_timezone: <timezone>"
|
144
|
+
description: Specifies which timezone shall be used for the `to` time, e.g. `CET` or `CEST`.
|
145
|
+
|
146
|
+
from:
|
147
|
+
call: ":from: <from_timestamp>"
|
148
|
+
description: >-
|
149
|
+
Overrides the time setting from grafana. It may contain dates as `now-1M/M`, which will be translated
|
150
|
+
properly to timestamps relative to the called time.
|
151
|
+
|
152
|
+
to:
|
153
|
+
call: ":to: <to_timestamp>"
|
154
|
+
description: >-
|
155
|
+
Overrides the time setting from grafana. It may contain dates as `now-1M/M`, which will be translated
|
156
|
+
properly to timestamps relative to the called time.
|
157
|
+
|
158
|
+
standard_options:
|
159
|
+
instance:
|
160
|
+
call: instance="<instance_name>"
|
161
|
+
description: >-
|
162
|
+
can be used to override global grafana instance, set in the report with `grafana_default_instance`.
|
163
|
+
If nothing is set, the configured grafana instance with name `default` will be used.
|
164
|
+
|
165
|
+
dashboard:
|
166
|
+
call: dashboard="<dashboard_uid>"
|
167
|
+
description: >-
|
168
|
+
Specifies the dashboard to be used. If `grafana_default_dashboard` is specified in the report template,
|
169
|
+
this value can be overridden with this option.
|
170
|
+
|
171
|
+
from:
|
172
|
+
call: from="<timestamp>"
|
173
|
+
description: can be used to override default `from` time
|
174
|
+
|
175
|
+
from_timezone:
|
176
|
+
call: from_timezone="<timezone>"
|
177
|
+
description: can be used to override system timezone for `from` time and will also override `grafana_default_from_timezone` option
|
178
|
+
|
179
|
+
to_timezone:
|
180
|
+
call: to_timezone="<timezone>"
|
181
|
+
description: can be used to override system timezone for `to` time and will also override `grafana_default_to_timezone` option
|
182
|
+
|
183
|
+
to:
|
184
|
+
call: to="<timestamp>"
|
185
|
+
description: can be used to override default `to` time
|
186
|
+
|
187
|
+
format:
|
188
|
+
call: format="<format_col1>,<format_col2>,..."
|
189
|
+
description: >-
|
190
|
+
Specify format in which the results shall be returned, e.g. `%.2f` for only two digit decimals of a
|
191
|
+
float. Several columns are separated by `,`. Execution is applied in the following order `format`,
|
192
|
+
`replace_values`, `filter_columns`, `transpose`.
|
193
|
+
see: 'https://ruby-doc.org/core-2.4.0/Kernel.html#method-i-sprintf'
|
194
|
+
|
195
|
+
replace_values:
|
196
|
+
call: replace_values="<replace_1>:<with_1>,<replace_2>:<with_2>,..."
|
197
|
+
description: >-
|
198
|
+
Specify result values which shall be replaced, e.g. `2:OK` will replace query values `2` with value `OK`.
|
199
|
+
Replacing several values is possible by separating by `,`. Matches with regular expressions are also
|
200
|
+
supported, but must be full matches, i.e. have to start with `^` and end with `$`, e.g. `^[012]$:OK`.
|
201
|
+
Number replacements can also be performed, e.g. `<8.2` or `<>3`. Execution is applied in the following order `format`,
|
202
|
+
`replace_values`, `filter_columns`, `transpose`.
|
203
|
+
see: https://ruby-doc.org/core-2.7.1/Regexp.html#class-Regexp-label-Character+Classes
|
204
|
+
|
205
|
+
filter_columns:
|
206
|
+
call: filter_columns="<column_name_1>,<column_name_2>,..."
|
207
|
+
description: >-
|
208
|
+
Removes specified columns from result. Execution is applied in the following order `format`, `replace_values`,
|
209
|
+
`filter_columns`, `transpose`.
|
210
|
+
|
211
|
+
transpose:
|
212
|
+
call: transpose="true"
|
213
|
+
description: >-
|
214
|
+
Transposes the query result, i.e. columns become rows and rows become columnns. Execution is applied in the
|
215
|
+
following order `format`, `replace_values`, `filter_columns`, `transpose`.
|
216
|
+
|
217
|
+
column_divider:
|
218
|
+
call: column_divider="<divider>"
|
219
|
+
description: >-
|
220
|
+
Replace the default column divider with another one. Defaults to ` | ` for being interpreted as a asciidoctor column.
|
221
|
+
|
222
|
+
row_divider:
|
223
|
+
call: row_divider="<divider>"
|
224
|
+
description: >-
|
225
|
+
Replace the default row divider with another one. Defaults to `| ` for being interpreted as a asciidoctor row.
|
226
|
+
|
227
|
+
timeout:
|
228
|
+
call: timeout="<timeout_in_seconds>"
|
229
|
+
description: >-
|
230
|
+
Set a timeout for the current query. If not overridden with `grafana-default-timeout` in the report template,
|
231
|
+
this defaults to 60 seconds.
|
232
|
+
|
233
|
+
# ----------------------------------
|
234
|
+
# FUNCTION DOCUMENTATION STARTS HERE
|
235
|
+
# ----------------------------------
|
236
|
+
|
237
|
+
grafana_help:
|
238
|
+
description: Show all available grafana calls within the asciidoctor templates, including available options.
|
239
|
+
call: 'include::grafana_help[]'
|
240
|
+
|
241
|
+
grafana_environment:
|
242
|
+
description: Shows all available variables in the rendering context which can be used in the asciidoctor template.
|
243
|
+
call: 'include::grafana_environment[]'
|
244
|
+
|
245
|
+
grafana_alerts:
|
246
|
+
description: >-
|
247
|
+
Returns a table of active alert states including the specified columns and the connected information. Supports
|
248
|
+
all query parameters from the Grafana Alerting API, such as `query`, `state`, `limit`, `folderId` and others.
|
249
|
+
call: grafana_alerts[columns="<column_name_1>,<column_name_2>,...",options]
|
250
|
+
see: https://grafana.com/docs/grafana/latest/http_api/alerting/#get-alerts
|
251
|
+
options:
|
252
|
+
columns:
|
253
|
+
description: >-
|
254
|
+
Specifies columns that shall be returned. Valid columns are `id`, `dashboardId`, `dashboardUId`, `dashboardSlug`,
|
255
|
+
`panelId`, `name`, `state`, `newStateDate`, `evalDate`, `evalData` and `executionError`.
|
256
|
+
call: columns="<column_name_1>,<columns_name_2>,..."
|
257
|
+
panel:
|
258
|
+
description: >-
|
259
|
+
If specified, the resulting alerts are filtered for this panel. This option will only work, if a `dashboard`
|
260
|
+
or `grafana_default_dashboard` is set.
|
261
|
+
call: panel="<panel_id>"
|
262
|
+
standard_options:
|
263
|
+
column_divider:
|
264
|
+
dashboard: >-
|
265
|
+
If this option, or the global option `grafana_default_dashboard` is set, the resulting alerts will be limited to
|
266
|
+
this dashboard. To show all alerts in this case, specify `dashboard=""` as option.
|
267
|
+
filter_columns:
|
268
|
+
format:
|
269
|
+
from:
|
270
|
+
instance:
|
271
|
+
replace_values:
|
272
|
+
row_divider:
|
273
|
+
timeout:
|
274
|
+
to:
|
275
|
+
transpose:
|
276
|
+
from_timezone:
|
277
|
+
to_timezone:
|
278
|
+
|
279
|
+
grafana_annotations:
|
280
|
+
description: >-
|
281
|
+
Returns a table of all annotations, matching the specified filter criteria and the specified columns. Supports all
|
282
|
+
query parameters from the Grafana Alerting API, such as `limit`, `alertId`, `panelId` and others.
|
283
|
+
call: grafana_annotations[columns="<column_name_1>,<column_name_2>,...",options]
|
284
|
+
see: https://grafana.com/docs/grafana/latest/http_api/annotations/#find_annotations
|
285
|
+
options:
|
286
|
+
columns:
|
287
|
+
description: >-
|
288
|
+
Specified the columns that shall be returned. Valid columns are `id`, `alertId`, `dashboardId`, `panelId`, `userId`,
|
289
|
+
`userName`, `newState`, `prevState, `time`, `timeEnd`, `text`, `metric` and `type`.
|
290
|
+
call: columns="<column_name_1>,<columns_name_2>,..."
|
291
|
+
panel:
|
292
|
+
description: >-
|
293
|
+
If specified, the resulting alerts are filtered for this panel. This option will only work, if a `dashboard` or
|
294
|
+
`grafana_default_dashboard` is set.
|
295
|
+
call: panel="<panel_id>"
|
296
|
+
standard_options:
|
297
|
+
column_divider:
|
298
|
+
dashboard: >-
|
299
|
+
If this option, or the global option `grafana_default_dashboard` is set, the resulting alerts will be limited to this
|
300
|
+
dashboard. To show all alerts in this case, specify `dashboard=""` as option.
|
301
|
+
filter_columns:
|
302
|
+
format:
|
303
|
+
from:
|
304
|
+
instance:
|
305
|
+
replace_values:
|
306
|
+
row_divider:
|
307
|
+
timeout:
|
308
|
+
to:
|
309
|
+
transpose:
|
310
|
+
from_timezone:
|
311
|
+
to_timezone:
|
312
|
+
|
313
|
+
grafana_panel_description:
|
314
|
+
description: >-
|
315
|
+
Returns a description field for the specified panel. `<type>` can either be `title` or `description`.
|
316
|
+
Grafana variables will be replaced in the returned value.
|
317
|
+
call: 'grafana_panel_description:<panel_id>["<type>",options]'
|
318
|
+
see: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax
|
319
|
+
standard_options:
|
320
|
+
dashboard:
|
321
|
+
instance:
|
322
|
+
|
323
|
+
grafana_panel_image:
|
324
|
+
description: Includes a panel image as an image in the document. Can be called for inline-images as well as for blocks.
|
325
|
+
call: 'grafana_panel_image:<panel_id>[options] or grafana_panel_image::<panel_id>[options]'
|
326
|
+
options:
|
327
|
+
render-height:
|
328
|
+
description: can be used to override default `height` in which the panel shall be rendered
|
329
|
+
call: render-height="<height>"
|
330
|
+
render-width:
|
331
|
+
description: can be used to override default `width` in which the panel shall be rendered
|
332
|
+
call: render-width="<width>"
|
333
|
+
render-theme:
|
334
|
+
description: can be used to override default `theme` in which the panel shall be rendered (light by default)
|
335
|
+
call: render-theme="<theme>"
|
336
|
+
render-timeout:
|
337
|
+
description: can be used to override default `timeout` in which the panel shall be rendered (60 seconds by default)
|
338
|
+
call: render-timeout="<timeout>"
|
339
|
+
standard_options:
|
340
|
+
dashboard:
|
341
|
+
from:
|
342
|
+
instance:
|
343
|
+
timeout:
|
344
|
+
to:
|
345
|
+
from_timezone:
|
346
|
+
to_timezone:
|
347
|
+
|
348
|
+
grafana_panel_query_table:
|
349
|
+
description: >-
|
350
|
+
Returns the results of a query, which is configured in a grafana panel, as a table in asciidoctor.
|
351
|
+
Grafana variables will be replaced in the panel's SQL statement.
|
352
|
+
call: 'include::grafana_panel_query_table:<panel_id>[query="<query_letter>",options]'
|
353
|
+
see: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax
|
354
|
+
options:
|
355
|
+
query:
|
356
|
+
call: query="<query_letter>"
|
357
|
+
description: +<query_letter>+ needs to point to the grafana query which shall be evaluated, e.g. +A+ or +B+.
|
358
|
+
standard_options:
|
359
|
+
column_divider:
|
360
|
+
dashboard:
|
361
|
+
filter_columns:
|
362
|
+
format:
|
363
|
+
from:
|
364
|
+
instance:
|
365
|
+
replace_values:
|
366
|
+
row_divider:
|
367
|
+
timeout:
|
368
|
+
to:
|
369
|
+
transpose:
|
370
|
+
from_timezone:
|
371
|
+
to_timezone:
|
372
|
+
|
373
|
+
grafana_panel_query_value:
|
374
|
+
call: 'grafana_panel_query_value:<panel_id>[query="<query_letter>",options]'
|
375
|
+
description: >-
|
376
|
+
Returns the value in the first column and the first row of a query, which is configured in a grafana panel.
|
377
|
+
Grafana variables will be replaced in the panel's SQL statement.
|
378
|
+
see: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax
|
379
|
+
options:
|
380
|
+
query:
|
381
|
+
call: query="<query_letter>"
|
382
|
+
description: +<query_letter>+ needs to point to the grafana query which shall be evaluated, e.g. +A+ or +B+.
|
383
|
+
standard_options:
|
384
|
+
dashboard:
|
385
|
+
filter_columns:
|
386
|
+
format:
|
387
|
+
from:
|
388
|
+
instance:
|
389
|
+
replace_values:
|
390
|
+
timeout:
|
391
|
+
to:
|
392
|
+
from_timezone:
|
393
|
+
to_timezone:
|
394
|
+
|
395
|
+
grafana_sql_table:
|
396
|
+
call: 'include::grafana_sql_table:<datasource_id>[sql="<sql_query>",options]'
|
397
|
+
description: >-
|
398
|
+
Returns a table with all results of the given query.
|
399
|
+
Grafana variables will be replaced in the SQL statement.
|
400
|
+
see: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax
|
401
|
+
standard_options:
|
402
|
+
column_divider:
|
403
|
+
filter_columns:
|
404
|
+
format:
|
405
|
+
from:
|
406
|
+
instance:
|
407
|
+
replace_values:
|
408
|
+
row_divider:
|
409
|
+
timeout:
|
410
|
+
to:
|
411
|
+
transpose:
|
412
|
+
from_timezone:
|
413
|
+
to_timezone:
|
414
|
+
|
415
|
+
grafana_sql_value:
|
416
|
+
call: 'grafana_sql_value:<datasource_id>[sql="<sql_query>",options]'
|
417
|
+
description: >-
|
418
|
+
Returns the value in the first column and the first row of the given query.
|
419
|
+
Grafana variables will be replaced in the SQL statement.
|
420
|
+
see: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax
|
421
|
+
standard_options:
|
422
|
+
filter_columns:
|
423
|
+
format:
|
424
|
+
from:
|
425
|
+
instance:
|
426
|
+
replace_values:
|
427
|
+
timeout:
|
428
|
+
to:
|
429
|
+
from_timezone:
|
430
|
+
to_timezone:
|
431
|
+
YAML_HELP
|
432
|
+
end
|
433
|
+
end
|
434
|
+
end
|
435
|
+
end
|