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
data/lib/grafana/dashboard.rb
CHANGED
@@ -1,66 +1,75 @@
|
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grafana
|
4
|
+
# Representation of one specific dashboard in a {Grafana} instance.
|
5
|
+
class Dashboard
|
6
|
+
# @return [Grafana] parent {Grafana} object
|
7
|
+
attr_reader :grafana
|
8
|
+
attr_reader :panels, :variables
|
9
|
+
|
10
|
+
# @param model [Hash] converted JSON Hash of the grafana dashboard
|
11
|
+
# @param grafana [Grafana] parent {Grafana} object
|
12
|
+
def initialize(model, grafana)
|
13
|
+
@grafana = grafana
|
14
|
+
@model = model
|
15
|
+
|
16
|
+
init_panels
|
17
|
+
init_variables
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [String] +from+ time configured in the dashboard.
|
21
|
+
def from_time
|
22
|
+
return @model['time']['from'] if @model['time']
|
23
|
+
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [String] +to+ time configured in the dashboard.
|
28
|
+
def to_time
|
29
|
+
@model['time']['to'] if @model['time']
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [String] dashboard UID
|
34
|
+
def id
|
35
|
+
@model['uid']
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [Panel] panel for the specified ID
|
39
|
+
def panel(id)
|
40
|
+
panels = @panels.select { |item| item.field('id') == id.to_i }
|
41
|
+
raise PanelDoesNotExistError.new(id, self) if panels.empty?
|
42
|
+
|
43
|
+
panels.first
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# store variables in array as objects of type Variable
|
49
|
+
def init_variables
|
50
|
+
@variables = []
|
51
|
+
return unless @model.key?('templating')
|
52
|
+
|
53
|
+
list = @model['templating']['list']
|
54
|
+
return unless list.is_a? Array
|
55
|
+
|
56
|
+
list.each { |item| @variables << Variable.new(item) }
|
57
|
+
end
|
58
|
+
|
59
|
+
# read panels
|
60
|
+
def init_panels
|
61
|
+
@panels = []
|
62
|
+
return unless @model.key?('panels')
|
63
|
+
|
64
|
+
@model['panels'].each do |panel|
|
65
|
+
if panel.key?('panels')
|
66
|
+
panel['panels'].each do |subpanel|
|
67
|
+
@panels << Panel.new(subpanel, self)
|
68
|
+
end
|
69
|
+
else
|
70
|
+
@panels << Panel.new(panel, self)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/grafana/errors.rb
CHANGED
@@ -1,61 +1,81 @@
|
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Grafana
|
4
|
+
# A top level alarm for all other errors in current module.
|
5
|
+
class GrafanaError < StandardError
|
6
|
+
def initialize(message)
|
7
|
+
super("GrafanaError: #{message} (#{self.class})")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Raised if a given dashboard does not exist in a specific {Grafana} instance.
|
12
|
+
class DashboardDoesNotExistError < GrafanaError
|
13
|
+
# @param dashboard_uid [String] dashboard uid, which could not be found
|
14
|
+
def initialize(dashboard_uid)
|
15
|
+
super("The specified dashboard '#{dashboard_uid}' does not exist.")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Raised if a given panel does not exist on a specific {Dashboard} in the current {Grafana} instance.
|
20
|
+
class PanelDoesNotExistError < GrafanaError
|
21
|
+
# @param panel_id [String] panel id, which could not be found on the dashboard
|
22
|
+
# @param dashboard [Dashboard] dashboard object on which the panel could not be found
|
23
|
+
def initialize(panel_id, dashboard)
|
24
|
+
super("The specified panel id '#{panel_id}' does not exist on the dashboard '#{dashboard.id}'.")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Raised if a given query letter does not exist on a specific {Panel}.
|
29
|
+
class QueryLetterDoesNotExistError < GrafanaError
|
30
|
+
# @param query_letter [String] query letter name, which could not be found on the panel
|
31
|
+
# @param panel [Panel] panel object on which the query could not be found
|
32
|
+
def initialize(query_letter, panel)
|
33
|
+
super("The specified query '#{query_letter}' does not exist in the panel '#{panel.id}' "\
|
34
|
+
"in dashboard '#{panel.dashboard}'.")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Raised if a given datasource does not exist in a specific {Grafana} instance.
|
39
|
+
class DatasourceDoesNotExistError < GrafanaError
|
40
|
+
# @param field [String] specifies, how the datasource has been searched, e.g. 'id' or 'name'
|
41
|
+
# @param datasource_identifier [String] identifier of the datasource, which could not be found,
|
42
|
+
# e.g. the specifiy id or name
|
43
|
+
def initialize(field, datasource_identifier)
|
44
|
+
super("Datasource with #{field} '#{datasource_identifier}' does not exist.")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Raised if a {Panel} could not be rendered as an image.
|
49
|
+
#
|
50
|
+
# Most likely this happens, because the image renderer is not configures properly in grafana,
|
51
|
+
# or the panel rendering ran into a timeout.
|
52
|
+
class ImageCouldNotBeRenderedError < GrafanaError
|
53
|
+
# @param panel [Panel] panel object, which could not be rendered
|
54
|
+
def initialize(panel)
|
55
|
+
super("The specified panel '#{panel.id}' from dashboard '#{panel.dashboard.id} could not be "\
|
56
|
+
'rendered to an image.')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Raised if no SQL query is specified in a {AbstractSqlQuery} object.
|
61
|
+
class MissingSqlQueryError < GrafanaError
|
62
|
+
def initialize
|
63
|
+
super('No SQL statement has been specified.')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Raised if a datasource shall be queried, which is not (yet) supported by the reporter
|
68
|
+
class DatasourceTypeNotSupportedError < GrafanaError
|
69
|
+
def initialize(name, type)
|
70
|
+
super("The configured datasource with name '#{name}' is of type '#{type}', which is currently "\
|
71
|
+
'not supported by ruby-grafana-reporter. It will only be usable in panel image queries.')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Raised if a datasource shall be queried, which is not (yet) supported by the reporter
|
76
|
+
class InvalidDatasourceQueryProvidedError < GrafanaError
|
77
|
+
def initialize(query)
|
78
|
+
super("The datasource query provided, does not look like a grafana datasource target (received: #{query}).")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/lib/grafana/grafana.rb
CHANGED
@@ -1,131 +1,130 @@
|
|
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
|
-
|
58
|
-
#
|
59
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
@dashboards
|
79
|
-
end
|
80
|
-
|
81
|
-
#
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
#
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Contains all objects for creating structured objects for interfacing grafana.
|
4
|
+
#
|
5
|
+
# The intention is, that these represent the business logic contained within grafana
|
6
|
+
# in an appropriate object model for the reporter to work with.
|
7
|
+
#
|
8
|
+
# For details, see also {https://grafana.com/docs/grafana/latest/http_api Grafana API}.
|
9
|
+
module Grafana
|
10
|
+
# Main class for handling the interaction with one specific Grafana instance.
|
11
|
+
class Grafana
|
12
|
+
# @param base_uri [String] full URI pointing to the specific grafana instance without
|
13
|
+
# trailing slash, e.g. +https://localhost:3000+.
|
14
|
+
# @param key [String] API key for the grafana instance, if required
|
15
|
+
# @param opts [Hash] additional options.
|
16
|
+
# Currently supporting +:logger+.
|
17
|
+
def initialize(base_uri, key = nil, opts = {})
|
18
|
+
@base_uri = base_uri
|
19
|
+
@key = key
|
20
|
+
@dashboards = {}
|
21
|
+
@logger = opts[:logger] || ::Logger.new(nil)
|
22
|
+
|
23
|
+
initialize_datasources unless @base_uri.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
# Used to test a connection to the grafana instance.
|
27
|
+
#
|
28
|
+
# Running this function also determines, if the API configured here has Admin or NON-Admin privileges,
|
29
|
+
# or even fails on connecting to grafana.
|
30
|
+
#
|
31
|
+
# @return [String] +Admin+, +NON-Admin+ or +Failed+ is returned, depending on the test results
|
32
|
+
def test_connection
|
33
|
+
if prepare_request({ relative_url: '/api/datasources' }).execute.is_a?(Net::HTTPOK)
|
34
|
+
# we have admin rights
|
35
|
+
@logger.warn('Reporter is running with Admin privileges on grafana. This is a potential security risk.')
|
36
|
+
return 'Admin'
|
37
|
+
end
|
38
|
+
# check if we have lower rights
|
39
|
+
return 'Failed' unless prepare_request({ relative_url: '/api/dashboards/home' }).execute.is_a?(Net::HTTPOK)
|
40
|
+
|
41
|
+
@logger.info('Reporter is running with NON-Admin privileges on grafana.')
|
42
|
+
'NON-Admin'
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns the datasource, which has been queried by the datasource name.
|
46
|
+
#
|
47
|
+
# @param datasource_name [String] name of the searched datasource
|
48
|
+
# @return [Datasource] Datasource for the specified datasource name
|
49
|
+
def datasource_by_name(datasource_name)
|
50
|
+
datasource_name = 'default' if datasource_name.to_s.empty?
|
51
|
+
raise DatasourceDoesNotExistError.new('name', datasource_name) unless @datasources[datasource_name]
|
52
|
+
|
53
|
+
@datasources[datasource_name]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the datasource, which has been queried by the datasource id.
|
57
|
+
#
|
58
|
+
# @param datasource_id [Integer] id of the searched datasource
|
59
|
+
# @return [Datasource] Datasource for the specified datasource id
|
60
|
+
def datasource_by_id(datasource_id)
|
61
|
+
datasource = @datasources.select { |_name, ds| ds.id == datasource_id.to_i }.values.first
|
62
|
+
raise DatasourceDoesNotExistError.new('id', datasource_id) unless datasource
|
63
|
+
|
64
|
+
datasource
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Array] Array of dashboard uids within the current grafana object
|
68
|
+
def dashboard_ids
|
69
|
+
response = prepare_request({ relative_url: '/api/search' }).execute
|
70
|
+
return [] unless response.is_a?(Net::HTTPOK)
|
71
|
+
|
72
|
+
dashboards = JSON.parse(response.body)
|
73
|
+
|
74
|
+
dashboards.each do |dashboard|
|
75
|
+
@dashboards[dashboard['uid']] = nil unless @dashboards[dashboard['uid']]
|
76
|
+
end
|
77
|
+
|
78
|
+
@dashboards.keys
|
79
|
+
end
|
80
|
+
|
81
|
+
# @param dashboard_uid [String] UID of the searched {Dashboard}
|
82
|
+
# @return [Dashboard] dashboard object, if it has been found
|
83
|
+
def dashboard(dashboard_uid)
|
84
|
+
return @dashboards[dashboard_uid] unless @dashboards[dashboard_uid].nil?
|
85
|
+
|
86
|
+
response = prepare_request({ relative_url: "/api/dashboards/uid/#{dashboard_uid}" }).execute
|
87
|
+
raise DashboardDoesNotExistError, dashboard_uid unless response.is_a?(Net::HTTPOK)
|
88
|
+
|
89
|
+
# cache dashboard for reuse
|
90
|
+
model = JSON.parse(response.body)['dashboard']
|
91
|
+
@dashboards[dashboard_uid] = Dashboard.new(model, self)
|
92
|
+
|
93
|
+
@dashboards[dashboard_uid]
|
94
|
+
end
|
95
|
+
|
96
|
+
# Prepares a {WebRequest} object for the current {Grafana} instance, which may be enriched
|
97
|
+
# with further properties and can then run {WebRequest#execute}.
|
98
|
+
#
|
99
|
+
# @option options [Hash] :relative_url relative URL with a leading slash, which shall be queried
|
100
|
+
# @option options [Hash] :accept
|
101
|
+
# @option options [Hash] :body
|
102
|
+
# @option options [Hash] :content_type
|
103
|
+
# @return [WebRequest] webrequest prepared for execution
|
104
|
+
def prepare_request(options = {})
|
105
|
+
auth = @key ? { authorization: "Bearer #{@key}" } : {}
|
106
|
+
WebRequest.new(@base_uri, auth.merge({ logger: @logger }).merge(options))
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def initialize_datasources
|
112
|
+
@datasources = {}
|
113
|
+
|
114
|
+
settings = prepare_request({ relative_url: '/api/frontend/settings' }).execute
|
115
|
+
return unless settings.is_a?(Net::HTTPOK)
|
116
|
+
|
117
|
+
json = JSON.parse(settings.body)
|
118
|
+
json['datasources'].select { |_k, v| v['id'].to_i.positive? }.each do |ds_name, ds_value|
|
119
|
+
begin
|
120
|
+
@datasources[ds_name] = AbstractDatasource.build_instance(ds_value)
|
121
|
+
rescue DatasourceTypeNotSupportedError => e
|
122
|
+
# an unsupported datasource type has been configured in the dashboard
|
123
|
+
# - no worries here
|
124
|
+
@logger.warn(e.message)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
@datasources['default'] = @datasources[json['defaultDatasource']]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|