ruby-grafana-reporter 0.1.7 → 0.4.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/README.md +86 -245
- data/bin/ruby-grafana-reporter +3 -2
- data/lib/VERSION.rb +6 -3
- data/lib/grafana/abstract_datasource.rb +116 -0
- data/lib/grafana/dashboard.rb +75 -66
- data/lib/grafana/errors.rb +81 -61
- data/lib/grafana/grafana.rb +130 -131
- 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 +25 -0
- data/lib/grafana/graphite_datasource.rb +44 -0
- data/lib/grafana/image_rendering_datasource.rb +44 -0
- data/lib/grafana/panel.rb +47 -39
- data/lib/grafana/prometheus_datasource.rb +39 -0
- data/lib/grafana/sql_datasource.rb +65 -0
- data/lib/grafana/variable.rb +218 -259
- data/lib/grafana/webrequest.rb +71 -0
- data/lib/grafana_reporter/abstract_query.rb +401 -0
- data/lib/grafana_reporter/abstract_report.rb +163 -109
- data/lib/grafana_reporter/alerts_table_query.rb +44 -0
- data/lib/grafana_reporter/annotations_table_query.rb +43 -0
- data/lib/grafana_reporter/application/application.rb +162 -229
- data/lib/grafana_reporter/application/errors.rb +33 -30
- data/lib/grafana_reporter/application/webservice.rb +242 -0
- data/lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb +90 -0
- data/lib/grafana_reporter/asciidoctor/annotations_table_include_processor.rb +89 -0
- data/lib/grafana_reporter/asciidoctor/panel_image_block_macro.rb +76 -0
- data/lib/grafana_reporter/asciidoctor/panel_image_inline_macro.rb +77 -0
- data/lib/grafana_reporter/asciidoctor/panel_property_inline_macro.rb +72 -0
- data/lib/grafana_reporter/asciidoctor/panel_query_table_include_processor.rb +98 -0
- data/lib/grafana_reporter/asciidoctor/panel_query_value_inline_macro.rb +93 -0
- data/lib/grafana_reporter/asciidoctor/processor_mixin.rb +23 -0
- data/lib/grafana_reporter/asciidoctor/report.rb +172 -159
- 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 +92 -0
- data/lib/grafana_reporter/asciidoctor/sql_value_inline_macro.rb +88 -0
- data/lib/grafana_reporter/asciidoctor/value_as_variable_include_processor.rb +90 -0
- data/lib/grafana_reporter/configuration.rb +310 -326
- data/lib/grafana_reporter/console_configuration_wizard.rb +319 -0
- data/lib/grafana_reporter/demo_report_wizard.rb +87 -0
- data/lib/grafana_reporter/errors.rb +81 -38
- data/lib/grafana_reporter/help.rb +447 -0
- data/lib/grafana_reporter/logger/two_way_logger.rb +58 -52
- data/lib/grafana_reporter/panel_image_query.rb +29 -0
- data/lib/grafana_reporter/panel_property_query.rb +22 -0
- data/lib/grafana_reporter/query_value_query.rb +79 -0
- data/lib/grafana_reporter/report_webhook.rb +35 -0
- data/lib/{ruby-grafana-reporter.rb → ruby_grafana_reporter.rb} +29 -27
- metadata +48 -60
- data/lib/grafana/abstract_panel_query.rb +0 -20
- data/lib/grafana/abstract_query.rb +0 -127
- data/lib/grafana/abstract_sql_query.rb +0 -42
- data/lib/grafana/panel_image_query.rb +0 -49
- data/lib/grafana_reporter/asciidoctor/alerts_table_query.rb +0 -99
- data/lib/grafana_reporter/asciidoctor/annotations_table_query.rb +0 -96
- data/lib/grafana_reporter/asciidoctor/errors.rb +0 -37
- data/lib/grafana_reporter/asciidoctor/extensions/alerts_table_include_processor.rb +0 -86
- data/lib/grafana_reporter/asciidoctor/extensions/annotations_table_include_processor.rb +0 -86
- data/lib/grafana_reporter/asciidoctor/extensions/panel_image_block_macro.rb +0 -67
- data/lib/grafana_reporter/asciidoctor/extensions/panel_image_inline_macro.rb +0 -65
- data/lib/grafana_reporter/asciidoctor/extensions/panel_property_inline_macro.rb +0 -58
- data/lib/grafana_reporter/asciidoctor/extensions/panel_query_table_include_processor.rb +0 -75
- data/lib/grafana_reporter/asciidoctor/extensions/panel_query_value_inline_macro.rb +0 -70
- data/lib/grafana_reporter/asciidoctor/extensions/processor_mixin.rb +0 -18
- data/lib/grafana_reporter/asciidoctor/extensions/show_environment_include_processor.rb +0 -41
- data/lib/grafana_reporter/asciidoctor/extensions/show_help_include_processor.rb +0 -202
- data/lib/grafana_reporter/asciidoctor/extensions/sql_table_include_processor.rb +0 -67
- data/lib/grafana_reporter/asciidoctor/extensions/sql_value_inline_macro.rb +0 -65
- data/lib/grafana_reporter/asciidoctor/extensions/value_as_variable_include_processor.rb +0 -57
- data/lib/grafana_reporter/asciidoctor/panel_first_value_query.rb +0 -32
- data/lib/grafana_reporter/asciidoctor/panel_image_query.rb +0 -23
- data/lib/grafana_reporter/asciidoctor/panel_property_query.rb +0 -43
- data/lib/grafana_reporter/asciidoctor/panel_table_query.rb +0 -36
- data/lib/grafana_reporter/asciidoctor/query_mixin.rb +0 -309
- data/lib/grafana_reporter/asciidoctor/sql_first_value_query.rb +0 -34
- data/lib/grafana_reporter/asciidoctor/sql_table_query.rb +0 -32
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
# This class is used to create an image out of a {Grafana::Panel}.
|
5
|
+
class PanelImageQuery < AbstractQuery
|
6
|
+
# Sets the proper render variables.
|
7
|
+
def pre_process
|
8
|
+
@from = translate_date(@from, @variables['grafana-report-timestamp'], false, @variables['from_timezone'] ||
|
9
|
+
@variables['grafana_default_from_timezone'])
|
10
|
+
@to = translate_date(@to, @variables['grafana-report-timestamp'], true, @variables['to_timezone'] ||
|
11
|
+
@variables['grafana_default_to_timezone'])
|
12
|
+
# TODO: ensure that in case of timezones are specified, that they are also forwarded to the image renderer
|
13
|
+
# rename "render-" variables
|
14
|
+
@variables = @variables.each_with_object({}) { |(k, v), h| h[k.gsub(/^render-/, '')] = v }
|
15
|
+
@datasource = Grafana::ImageRenderingDatasource.new(nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns the body of the http query, which contains the raw image.
|
19
|
+
def post_process
|
20
|
+
@result = @result[:content].first
|
21
|
+
raise ImageCouldNotBeRenderedError, @panel if @result.include?('<html')
|
22
|
+
end
|
23
|
+
|
24
|
+
# @see AbstractQuery#raw_query
|
25
|
+
def raw_query
|
26
|
+
{ panel: @panel }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
# This class is used to query properties from a {Grafana::Panel}, such as +description+,
|
5
|
+
# +title+ etc.
|
6
|
+
class PanelPropertyQuery < AbstractQuery
|
7
|
+
# @see Grafana::AbstractQuery#pre_process
|
8
|
+
def pre_process
|
9
|
+
@datasource = Grafana::GrafanaPropertyDatasource.new(nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
# @see Grafana::AbstractQuery#post_process
|
13
|
+
def post_process
|
14
|
+
@result = @result[:content].first
|
15
|
+
end
|
16
|
+
|
17
|
+
# @see Grafana::AbstractQuery#raw_query
|
18
|
+
def raw_query
|
19
|
+
@raw_query.merge({ panel: @panel })
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
# This class provides a general query implementation for any kind of single value and table queries.
|
5
|
+
class QueryValueQuery < AbstractQuery
|
6
|
+
# Translates the from and to times.
|
7
|
+
# @see Grafana::AbstractQuery#pre_process
|
8
|
+
def pre_process
|
9
|
+
@datasource = @panel.datasource if @panel
|
10
|
+
|
11
|
+
@from = translate_date(@from, @variables['grafana-report-timestamp'], false, @variables['from_timezone'] ||
|
12
|
+
@variables['grafana_default_from_timezone'])
|
13
|
+
@to = translate_date(@to, @variables['grafana-report-timestamp'], true, @variables['to_timezone'] ||
|
14
|
+
@variables['grafana_default_to_timezone'])
|
15
|
+
@variables['result_type'] ||= Variable.new('')
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes {QueryMixin#format_columns}, {QueryMixin#replace_values} and
|
19
|
+
# {QueryMixin#filter_columns} on the query results.
|
20
|
+
#
|
21
|
+
# Finally the results are formatted as a asciidoctor table.
|
22
|
+
# @see Grafana::AbstractQuery#post_process
|
23
|
+
def post_process
|
24
|
+
modify_results
|
25
|
+
|
26
|
+
case @variables['result_type'].raw_value
|
27
|
+
when /(?:panel_table|sql_table)/
|
28
|
+
result_to_table
|
29
|
+
|
30
|
+
when /(?:panel_value|sql_value)/
|
31
|
+
tmp = @result[:content] || []
|
32
|
+
@result = tmp.flatten.first
|
33
|
+
|
34
|
+
else
|
35
|
+
raise StandardError, "Unsupported 'result_type' received: '#{@variables['result_type'].raw_value}'"
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# @see Grafana::AbstractQuery#raw_query
|
41
|
+
def raw_query
|
42
|
+
return @raw_query if @raw_query
|
43
|
+
|
44
|
+
case @variables['result_type'].raw_value
|
45
|
+
when /(?:panel_table|panel_value)/
|
46
|
+
@variables['query'] ? @panel.query(@variables['query'].raw_value) : @panel.query(nil)
|
47
|
+
|
48
|
+
when /(?:sql_table|sql_value)/
|
49
|
+
nil
|
50
|
+
|
51
|
+
else
|
52
|
+
raise StandardError, "Unsupported 'result_type' received: '#{@variables['result_type'].raw_value}'"
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def result_to_table
|
60
|
+
row_div = '| '
|
61
|
+
row_div = @variables['row_divider'].raw_value if @variables['row_divider'].is_a?(Grafana::Variable)
|
62
|
+
col_div = ' | '
|
63
|
+
col_div = @variables['column_divider'].raw_value if @variables['column_divider'].is_a?(Grafana::Variable)
|
64
|
+
|
65
|
+
@result = @result[:content].map do |row|
|
66
|
+
row_div + row.map do |item|
|
67
|
+
col_div == ' | ' ? item.to_s.gsub('|', '\\|') : item.to_s
|
68
|
+
end.join(col_div)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def modify_results
|
73
|
+
@result = format_columns(@result, @variables['format'])
|
74
|
+
@result = replace_values(@result, @variables.select { |k, _v| k =~ /^replace_values_\d+/ })
|
75
|
+
@result = filter_columns(@result, @variables['filter_columns'])
|
76
|
+
@result = transpose(@result, @variables['transpose'])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GrafanaReporter
|
4
|
+
# This class provides a default webhook implementation for report events. It sends out
|
5
|
+
# a webrequest to the configured +callback_url+ with all necessary information about the
|
6
|
+
# event and the report.
|
7
|
+
class ReportWebhook
|
8
|
+
def initialize(callback_url)
|
9
|
+
@callback_url = callback_url
|
10
|
+
end
|
11
|
+
|
12
|
+
# Implements the call of the configured webhook.
|
13
|
+
# Provides the following report information in JSON format:
|
14
|
+
#
|
15
|
+
# +object_id+ - id of the current report
|
16
|
+
# +path+ - file path to the report
|
17
|
+
# +status+ - report status as string, e.g. +cancelled+, +finished+ or +in progress+
|
18
|
+
# +execution_time+ - execution time of the report
|
19
|
+
# +template+ - name of the used template
|
20
|
+
# +start_time+ - time when the report creation started
|
21
|
+
# +end_time+ - time when the report creation ended
|
22
|
+
# +event+ - event, which has happened
|
23
|
+
def callback(event, report)
|
24
|
+
# build report information as JSON
|
25
|
+
data = { object_id: report.object_id, path: report.path, status: report.status,
|
26
|
+
execution_time: report.execution_time, template: report.template,
|
27
|
+
start_time: report.start_time, end_time: report.end_time, event: event }
|
28
|
+
|
29
|
+
request = { body: JSON.generate(data), accept: nil, content_type: nil }
|
30
|
+
res = ::Grafana::WebRequest.new(@callback_url, request).execute
|
31
|
+
|
32
|
+
"#{res} - Body: #{res.body}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,27 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require '
|
11
|
-
require '
|
12
|
-
require '
|
13
|
-
require '
|
14
|
-
require '
|
15
|
-
require 'asciidoctor
|
16
|
-
require '
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
%w[
|
23
|
-
%w[grafana_reporter
|
24
|
-
%w[grafana_reporter
|
25
|
-
%w[grafana_reporter
|
26
|
-
]
|
27
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'yaml'
|
6
|
+
require 'socket'
|
7
|
+
require 'uri'
|
8
|
+
require 'json'
|
9
|
+
require 'tempfile'
|
10
|
+
require 'cgi'
|
11
|
+
require 'optparse'
|
12
|
+
require 'date'
|
13
|
+
require 'time'
|
14
|
+
require 'logger'
|
15
|
+
require 'asciidoctor'
|
16
|
+
require 'asciidoctor/extensions'
|
17
|
+
require 'asciidoctor-pdf'
|
18
|
+
require 'zip'
|
19
|
+
require_relative 'VERSION'
|
20
|
+
|
21
|
+
folders = [
|
22
|
+
%w[grafana],
|
23
|
+
%w[grafana_reporter logger],
|
24
|
+
%w[grafana_reporter],
|
25
|
+
%w[grafana_reporter asciidoctor extensions],
|
26
|
+
%w[grafana_reporter asciidoctor],
|
27
|
+
%w[grafana_reporter application]
|
28
|
+
]
|
29
|
+
folders.each { |folder| Dir[File.join(__dir__, *folder, '*.rb')].sort.each { |file| require_relative file } }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-grafana-reporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Kohlmeyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
version: 1.1.1
|
48
48
|
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: '2.
|
50
|
+
version: '2.4'
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -57,49 +57,35 @@ dependencies:
|
|
57
57
|
version: 1.1.1
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '2.
|
60
|
+
version: '2.4'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '0.16'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0.16'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: coveralls
|
62
|
+
name: rspec
|
77
63
|
requirement: !ruby/object:Gem::Requirement
|
78
64
|
requirements:
|
79
65
|
- - "~>"
|
80
66
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
67
|
+
version: '3.9'
|
82
68
|
type: :development
|
83
69
|
prerelease: false
|
84
70
|
version_requirements: !ruby/object:Gem::Requirement
|
85
71
|
requirements:
|
86
72
|
- - "~>"
|
87
73
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
74
|
+
version: '3.9'
|
89
75
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
76
|
+
name: simplecov
|
91
77
|
requirement: !ruby/object:Gem::Requirement
|
92
78
|
requirements:
|
93
79
|
- - "~>"
|
94
80
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
81
|
+
version: '0.16'
|
96
82
|
type: :development
|
97
83
|
prerelease: false
|
98
84
|
version_requirements: !ruby/object:Gem::Requirement
|
99
85
|
requirements:
|
100
86
|
- - "~>"
|
101
87
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
88
|
+
version: '0.16'
|
103
89
|
- !ruby/object:Gem::Dependency
|
104
90
|
name: webmock
|
105
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,13 +100,9 @@ dependencies:
|
|
114
100
|
- - "~>"
|
115
101
|
- !ruby/object:Gem::Version
|
116
102
|
version: '3.9'
|
117
|
-
description:
|
118
|
-
|
119
|
-
|
120
|
-
captured from grafana.
|
121
|
-
|
122
|
-
By default the reports will be converted to PDF documents, whereas other
|
123
|
-
target formats can be used as well.
|
103
|
+
description: Build reports based on grafana dashboards in asciidoctor syntax. Runs
|
104
|
+
as webservice for easy integration with grafana, or as a standalone, command line
|
105
|
+
utility.
|
124
106
|
email: kohly@gmx.de
|
125
107
|
executables:
|
126
108
|
- ruby-grafana-reporter
|
@@ -130,46 +112,52 @@ extra_rdoc_files:
|
|
130
112
|
- LICENSE
|
131
113
|
files:
|
132
114
|
- "./lib/VERSION.rb"
|
133
|
-
- "./lib/grafana/
|
134
|
-
- "./lib/grafana/abstract_query.rb"
|
135
|
-
- "./lib/grafana/abstract_sql_query.rb"
|
115
|
+
- "./lib/grafana/abstract_datasource.rb"
|
136
116
|
- "./lib/grafana/dashboard.rb"
|
137
117
|
- "./lib/grafana/errors.rb"
|
138
118
|
- "./lib/grafana/grafana.rb"
|
119
|
+
- "./lib/grafana/grafana_alerts_datasource.rb"
|
120
|
+
- "./lib/grafana/grafana_annotations_datasource.rb"
|
121
|
+
- "./lib/grafana/grafana_property_datasource.rb"
|
122
|
+
- "./lib/grafana/graphite_datasource.rb"
|
123
|
+
- "./lib/grafana/image_rendering_datasource.rb"
|
139
124
|
- "./lib/grafana/panel.rb"
|
140
|
-
- "./lib/grafana/
|
125
|
+
- "./lib/grafana/prometheus_datasource.rb"
|
126
|
+
- "./lib/grafana/sql_datasource.rb"
|
141
127
|
- "./lib/grafana/variable.rb"
|
128
|
+
- "./lib/grafana/webrequest.rb"
|
129
|
+
- "./lib/grafana_reporter/abstract_query.rb"
|
142
130
|
- "./lib/grafana_reporter/abstract_report.rb"
|
131
|
+
- "./lib/grafana_reporter/alerts_table_query.rb"
|
132
|
+
- "./lib/grafana_reporter/annotations_table_query.rb"
|
143
133
|
- "./lib/grafana_reporter/application/application.rb"
|
144
134
|
- "./lib/grafana_reporter/application/errors.rb"
|
145
|
-
- "./lib/grafana_reporter/
|
146
|
-
- "./lib/grafana_reporter/asciidoctor/
|
147
|
-
- "./lib/grafana_reporter/asciidoctor/
|
148
|
-
- "./lib/grafana_reporter/asciidoctor/
|
149
|
-
- "./lib/grafana_reporter/asciidoctor/
|
150
|
-
- "./lib/grafana_reporter/asciidoctor/
|
151
|
-
- "./lib/grafana_reporter/asciidoctor/
|
152
|
-
- "./lib/grafana_reporter/asciidoctor/
|
153
|
-
- "./lib/grafana_reporter/asciidoctor/
|
154
|
-
- "./lib/grafana_reporter/asciidoctor/extensions/panel_query_value_inline_macro.rb"
|
155
|
-
- "./lib/grafana_reporter/asciidoctor/extensions/processor_mixin.rb"
|
156
|
-
- "./lib/grafana_reporter/asciidoctor/extensions/show_environment_include_processor.rb"
|
157
|
-
- "./lib/grafana_reporter/asciidoctor/extensions/show_help_include_processor.rb"
|
158
|
-
- "./lib/grafana_reporter/asciidoctor/extensions/sql_table_include_processor.rb"
|
159
|
-
- "./lib/grafana_reporter/asciidoctor/extensions/sql_value_inline_macro.rb"
|
160
|
-
- "./lib/grafana_reporter/asciidoctor/extensions/value_as_variable_include_processor.rb"
|
161
|
-
- "./lib/grafana_reporter/asciidoctor/panel_first_value_query.rb"
|
162
|
-
- "./lib/grafana_reporter/asciidoctor/panel_image_query.rb"
|
163
|
-
- "./lib/grafana_reporter/asciidoctor/panel_property_query.rb"
|
164
|
-
- "./lib/grafana_reporter/asciidoctor/panel_table_query.rb"
|
165
|
-
- "./lib/grafana_reporter/asciidoctor/query_mixin.rb"
|
135
|
+
- "./lib/grafana_reporter/application/webservice.rb"
|
136
|
+
- "./lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb"
|
137
|
+
- "./lib/grafana_reporter/asciidoctor/annotations_table_include_processor.rb"
|
138
|
+
- "./lib/grafana_reporter/asciidoctor/panel_image_block_macro.rb"
|
139
|
+
- "./lib/grafana_reporter/asciidoctor/panel_image_inline_macro.rb"
|
140
|
+
- "./lib/grafana_reporter/asciidoctor/panel_property_inline_macro.rb"
|
141
|
+
- "./lib/grafana_reporter/asciidoctor/panel_query_table_include_processor.rb"
|
142
|
+
- "./lib/grafana_reporter/asciidoctor/panel_query_value_inline_macro.rb"
|
143
|
+
- "./lib/grafana_reporter/asciidoctor/processor_mixin.rb"
|
166
144
|
- "./lib/grafana_reporter/asciidoctor/report.rb"
|
167
|
-
- "./lib/grafana_reporter/asciidoctor/
|
168
|
-
- "./lib/grafana_reporter/asciidoctor/
|
145
|
+
- "./lib/grafana_reporter/asciidoctor/show_environment_include_processor.rb"
|
146
|
+
- "./lib/grafana_reporter/asciidoctor/show_help_include_processor.rb"
|
147
|
+
- "./lib/grafana_reporter/asciidoctor/sql_table_include_processor.rb"
|
148
|
+
- "./lib/grafana_reporter/asciidoctor/sql_value_inline_macro.rb"
|
149
|
+
- "./lib/grafana_reporter/asciidoctor/value_as_variable_include_processor.rb"
|
169
150
|
- "./lib/grafana_reporter/configuration.rb"
|
151
|
+
- "./lib/grafana_reporter/console_configuration_wizard.rb"
|
152
|
+
- "./lib/grafana_reporter/demo_report_wizard.rb"
|
170
153
|
- "./lib/grafana_reporter/errors.rb"
|
154
|
+
- "./lib/grafana_reporter/help.rb"
|
171
155
|
- "./lib/grafana_reporter/logger/two_way_logger.rb"
|
172
|
-
- "./lib/
|
156
|
+
- "./lib/grafana_reporter/panel_image_query.rb"
|
157
|
+
- "./lib/grafana_reporter/panel_property_query.rb"
|
158
|
+
- "./lib/grafana_reporter/query_value_query.rb"
|
159
|
+
- "./lib/grafana_reporter/report_webhook.rb"
|
160
|
+
- "./lib/ruby_grafana_reporter.rb"
|
173
161
|
- LICENSE
|
174
162
|
- README.md
|
175
163
|
- bin/ruby-grafana-reporter
|
@@ -187,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
175
|
requirements:
|
188
176
|
- - ">="
|
189
177
|
- !ruby/object:Gem::Version
|
190
|
-
version:
|
178
|
+
version: 2.3.3
|
191
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
180
|
requirements:
|
193
181
|
- - ">="
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require_relative 'abstract_query'
|
2
|
-
|
3
|
-
module Grafana
|
4
|
-
# @abstract
|
5
|
-
#
|
6
|
-
# Used as a superclass for all queries, which rely on a {Panel} object.
|
7
|
-
#
|
8
|
-
# @see AbstractQuery
|
9
|
-
class AbstractPanelQuery < AbstractQuery
|
10
|
-
attr_reader :panel
|
11
|
-
|
12
|
-
# Initializes the variables of the query using {AbstractQuery#extract_dashboard_variables}.
|
13
|
-
# @param panel [Panel] panel for which the query shall be executed
|
14
|
-
def initialize(panel)
|
15
|
-
super()
|
16
|
-
@panel = panel
|
17
|
-
extract_dashboard_variables(@panel.dashboard)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
module Grafana
|
2
|
-
# @abstract Override {#url}, #{#request}, {#pre_process} and {#post_process} in subclass.
|
3
|
-
#
|
4
|
-
# Superclass containing everything for all queries towards grafana.
|
5
|
-
class AbstractQuery
|
6
|
-
attr_accessor :from, :to, :timeout, :result
|
7
|
-
attr_reader :variables
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@variables = {}
|
11
|
-
end
|
12
|
-
|
13
|
-
# Runs the whole process to receive values properly from this query:
|
14
|
-
# - calls {#pre_process}
|
15
|
-
# - executes this query against the given {Grafana} instance
|
16
|
-
# - calls {#post_process}
|
17
|
-
# - returns the result
|
18
|
-
#
|
19
|
-
# @param grafana [Grafana] {Grafana} object, against which the query is executed
|
20
|
-
# @return [Object] result of the query
|
21
|
-
def execute(grafana)
|
22
|
-
return @result unless @result.nil?
|
23
|
-
|
24
|
-
pre_process(grafana)
|
25
|
-
@result = grafana.execute_http_request(url, request, timeout)
|
26
|
-
post_process
|
27
|
-
@result
|
28
|
-
end
|
29
|
-
|
30
|
-
# Used to retrieve default configurations from the given {Dashboard} and store them as settings in the query.
|
31
|
-
#
|
32
|
-
# Following data is extracted:
|
33
|
-
# - +from+, by {Dashboard#from_time}
|
34
|
-
# - +to+, by {Dashboard#to_time}
|
35
|
-
# - and all variables as {Variable}, prefixed with +var-+, as grafana also does it
|
36
|
-
def extract_dashboard_variables(dashboard)
|
37
|
-
@from = dashboard.from_time
|
38
|
-
@to = dashboard.to_time
|
39
|
-
dashboard.variables.each { |item| merge_variables({ "var-#{item.name}": item }) }
|
40
|
-
self
|
41
|
-
end
|
42
|
-
|
43
|
-
# Merges the given Hash with the stored variables.
|
44
|
-
#
|
45
|
-
# Can be used to easily set many values at once in the local variables hash.
|
46
|
-
#
|
47
|
-
# Please note, that the values of the Hash need to be of type {Variable}.
|
48
|
-
#
|
49
|
-
# @param hash [Hash<String,Variable>] Hash containing variable name as key and {Variable} as value
|
50
|
-
# @return [AbstractQuery] this object
|
51
|
-
def merge_variables(hash)
|
52
|
-
hash.each do |k, v|
|
53
|
-
if @variables[k.to_s].nil?
|
54
|
-
@variables[k.to_s] = v
|
55
|
-
else
|
56
|
-
@variables[k.to_s].raw_value = v.raw_value
|
57
|
-
end
|
58
|
-
end
|
59
|
-
self
|
60
|
-
end
|
61
|
-
|
62
|
-
# @return [Hash<String, Variable>] all grafana variables stored in this query, i.e. the variable name is prefixed with +var-+
|
63
|
-
def grafana_variables
|
64
|
-
@variables.select { |k, _v| k =~ /^var-.+/ }
|
65
|
-
end
|
66
|
-
|
67
|
-
# Replaces the grafana variables in the given string with their replacement value.
|
68
|
-
#
|
69
|
-
# @param string [String] string in which the variables shall be replaced
|
70
|
-
# @param variables [Hash<String,Variable>] Hash containing the variables, which shall be replaced in the given string
|
71
|
-
# @return [String] string in which all variables are properly replaced
|
72
|
-
def replace_variables(string, variables = {})
|
73
|
-
res = string
|
74
|
-
repeat = true
|
75
|
-
repeat_count = 0
|
76
|
-
|
77
|
-
# TODO find a proper way to replace variables recursively instead of over and over again
|
78
|
-
# TODO add tests for recursive replacement of variable
|
79
|
-
while repeat and repeat_count < 3
|
80
|
-
repeat = false
|
81
|
-
repeat_count += 1
|
82
|
-
variables.each do |var_name, obj|
|
83
|
-
# only set ticks if value is string
|
84
|
-
variable = var_name.gsub(/^var-/, '')
|
85
|
-
res = res.gsub(/(?:\$\{#{variable}(?::(?<format>[\w]+))?\}|(?<!\.)\$#{variable}(?!\.))/) do
|
86
|
-
obj.value_formatted($~[:format])
|
87
|
-
end
|
88
|
-
end
|
89
|
-
repeat = true if res.include?('$')
|
90
|
-
end
|
91
|
-
|
92
|
-
res
|
93
|
-
end
|
94
|
-
|
95
|
-
# @abstract
|
96
|
-
#
|
97
|
-
# @return [String] String containing the relative URL to execute the query
|
98
|
-
def uri
|
99
|
-
raise NotImplementedError
|
100
|
-
end
|
101
|
-
|
102
|
-
# @abstract
|
103
|
-
#
|
104
|
-
# @return [Hash] Hash containing the request parameters, which shall be overwritten or extended in {Grafana#execute_http_request}
|
105
|
-
def request
|
106
|
-
raise NotImplementedError
|
107
|
-
end
|
108
|
-
|
109
|
-
# @abstract
|
110
|
-
#
|
111
|
-
# Use this function to perform all necessary actions, before the query is actually executed.
|
112
|
-
# Here you can e.g. set values of variables or similar.
|
113
|
-
#
|
114
|
-
# @param grafana [Grafana] {Grafana} object, against which the query shall be executed
|
115
|
-
def pre_process(grafana)
|
116
|
-
raise NotImplementedError
|
117
|
-
end
|
118
|
-
|
119
|
-
# @abstract
|
120
|
-
#
|
121
|
-
# Use this function to format the raw result of the @result variable to conform to the expected return value.
|
122
|
-
# You might also want to {#replace_variables} in the @result or similar.
|
123
|
-
def post_process
|
124
|
-
raise NotImplementedError
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|