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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +86 -245
  3. data/bin/ruby-grafana-reporter +3 -2
  4. data/lib/VERSION.rb +6 -3
  5. data/lib/grafana/abstract_datasource.rb +116 -0
  6. data/lib/grafana/dashboard.rb +75 -66
  7. data/lib/grafana/errors.rb +81 -61
  8. data/lib/grafana/grafana.rb +130 -131
  9. data/lib/grafana/grafana_alerts_datasource.rb +57 -0
  10. data/lib/grafana/grafana_annotations_datasource.rb +56 -0
  11. data/lib/grafana/grafana_property_datasource.rb +25 -0
  12. data/lib/grafana/graphite_datasource.rb +44 -0
  13. data/lib/grafana/image_rendering_datasource.rb +44 -0
  14. data/lib/grafana/panel.rb +47 -39
  15. data/lib/grafana/prometheus_datasource.rb +39 -0
  16. data/lib/grafana/sql_datasource.rb +65 -0
  17. data/lib/grafana/variable.rb +218 -259
  18. data/lib/grafana/webrequest.rb +71 -0
  19. data/lib/grafana_reporter/abstract_query.rb +401 -0
  20. data/lib/grafana_reporter/abstract_report.rb +163 -109
  21. data/lib/grafana_reporter/alerts_table_query.rb +44 -0
  22. data/lib/grafana_reporter/annotations_table_query.rb +43 -0
  23. data/lib/grafana_reporter/application/application.rb +162 -229
  24. data/lib/grafana_reporter/application/errors.rb +33 -30
  25. data/lib/grafana_reporter/application/webservice.rb +242 -0
  26. data/lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb +90 -0
  27. data/lib/grafana_reporter/asciidoctor/annotations_table_include_processor.rb +89 -0
  28. data/lib/grafana_reporter/asciidoctor/panel_image_block_macro.rb +76 -0
  29. data/lib/grafana_reporter/asciidoctor/panel_image_inline_macro.rb +77 -0
  30. data/lib/grafana_reporter/asciidoctor/panel_property_inline_macro.rb +72 -0
  31. data/lib/grafana_reporter/asciidoctor/panel_query_table_include_processor.rb +98 -0
  32. data/lib/grafana_reporter/asciidoctor/panel_query_value_inline_macro.rb +93 -0
  33. data/lib/grafana_reporter/asciidoctor/processor_mixin.rb +23 -0
  34. data/lib/grafana_reporter/asciidoctor/report.rb +172 -159
  35. data/lib/grafana_reporter/asciidoctor/show_environment_include_processor.rb +46 -0
  36. data/lib/grafana_reporter/asciidoctor/show_help_include_processor.rb +35 -0
  37. data/lib/grafana_reporter/asciidoctor/sql_table_include_processor.rb +92 -0
  38. data/lib/grafana_reporter/asciidoctor/sql_value_inline_macro.rb +88 -0
  39. data/lib/grafana_reporter/asciidoctor/value_as_variable_include_processor.rb +90 -0
  40. data/lib/grafana_reporter/configuration.rb +310 -326
  41. data/lib/grafana_reporter/console_configuration_wizard.rb +319 -0
  42. data/lib/grafana_reporter/demo_report_wizard.rb +87 -0
  43. data/lib/grafana_reporter/errors.rb +81 -38
  44. data/lib/grafana_reporter/help.rb +447 -0
  45. data/lib/grafana_reporter/logger/two_way_logger.rb +58 -52
  46. data/lib/grafana_reporter/panel_image_query.rb +29 -0
  47. data/lib/grafana_reporter/panel_property_query.rb +22 -0
  48. data/lib/grafana_reporter/query_value_query.rb +79 -0
  49. data/lib/grafana_reporter/report_webhook.rb +35 -0
  50. data/lib/{ruby-grafana-reporter.rb → ruby_grafana_reporter.rb} +29 -27
  51. metadata +48 -60
  52. data/lib/grafana/abstract_panel_query.rb +0 -20
  53. data/lib/grafana/abstract_query.rb +0 -127
  54. data/lib/grafana/abstract_sql_query.rb +0 -42
  55. data/lib/grafana/panel_image_query.rb +0 -49
  56. data/lib/grafana_reporter/asciidoctor/alerts_table_query.rb +0 -99
  57. data/lib/grafana_reporter/asciidoctor/annotations_table_query.rb +0 -96
  58. data/lib/grafana_reporter/asciidoctor/errors.rb +0 -37
  59. data/lib/grafana_reporter/asciidoctor/extensions/alerts_table_include_processor.rb +0 -86
  60. data/lib/grafana_reporter/asciidoctor/extensions/annotations_table_include_processor.rb +0 -86
  61. data/lib/grafana_reporter/asciidoctor/extensions/panel_image_block_macro.rb +0 -67
  62. data/lib/grafana_reporter/asciidoctor/extensions/panel_image_inline_macro.rb +0 -65
  63. data/lib/grafana_reporter/asciidoctor/extensions/panel_property_inline_macro.rb +0 -58
  64. data/lib/grafana_reporter/asciidoctor/extensions/panel_query_table_include_processor.rb +0 -75
  65. data/lib/grafana_reporter/asciidoctor/extensions/panel_query_value_inline_macro.rb +0 -70
  66. data/lib/grafana_reporter/asciidoctor/extensions/processor_mixin.rb +0 -18
  67. data/lib/grafana_reporter/asciidoctor/extensions/show_environment_include_processor.rb +0 -41
  68. data/lib/grafana_reporter/asciidoctor/extensions/show_help_include_processor.rb +0 -202
  69. data/lib/grafana_reporter/asciidoctor/extensions/sql_table_include_processor.rb +0 -67
  70. data/lib/grafana_reporter/asciidoctor/extensions/sql_value_inline_macro.rb +0 -65
  71. data/lib/grafana_reporter/asciidoctor/extensions/value_as_variable_include_processor.rb +0 -57
  72. data/lib/grafana_reporter/asciidoctor/panel_first_value_query.rb +0 -32
  73. data/lib/grafana_reporter/asciidoctor/panel_image_query.rb +0 -23
  74. data/lib/grafana_reporter/asciidoctor/panel_property_query.rb +0 -43
  75. data/lib/grafana_reporter/asciidoctor/panel_table_query.rb +0 -36
  76. data/lib/grafana_reporter/asciidoctor/query_mixin.rb +0 -309
  77. data/lib/grafana_reporter/asciidoctor/sql_first_value_query.rb +0 -34
  78. data/lib/grafana_reporter/asciidoctor/sql_table_query.rb +0 -32
@@ -0,0 +1,447 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module GrafanaReporter
6
+ # This class generates the functional help documentation for the reporter.
7
+ # It can create the documentation for github markdown, as well as in asciidoctor.
8
+ class Help
9
+ # @param headline_level [Integer] top level of headline
10
+ # @return [String] asciidoctor compatible documentation
11
+ def asciidoctor(headline_level = 2)
12
+ help_text(asciidoctor_options.merge(level: headline_level))
13
+ end
14
+
15
+ # @param headline_level [Integer] top level of headline
16
+ # @return [String] github markdown compatible documentation
17
+ def github(headline_level = 2)
18
+ "#{toc}\n\n#{help_text(github_options.merge(level: headline_level))}"
19
+ end
20
+
21
+ # @see AbstractQuery#self.build_demo_entry
22
+ def self.build_demo_entry(_panel)
23
+ 'include::grafana_help[]'
24
+ end
25
+
26
+ private
27
+
28
+ def github_options
29
+ { headline_separator: '#', code_begin: '`', code_end: '`', table_begin: "\n", head_postfix_col: '| -- ' }
30
+ end
31
+
32
+ def asciidoctor_options
33
+ { headline_separator: '=', code_begin: '`+', code_end: '+`', table_begin: "\n[%autowidth.stretch, "\
34
+ "options=\"header\"]\n|===\n", table_end: "\n|===" }
35
+ end
36
+
37
+ def help_text(opts)
38
+ %(#{opts[:headline_separator] * opts[:level]} Global options
39
+ #{global_options_as_text(opts.merge(level: opts[:level] + 1))}
40
+ #{opts[:headline_separator] * opts[:level]} Functions
41
+ #{functions_as_text(opts.merge(level: opts[:level] + 1))})
42
+ end
43
+
44
+ def toc
45
+ result = []
46
+
47
+ result << 'Table of contents'
48
+ result << '* [Global options](#global-options)'
49
+ prepared_help[:global_options].sort.map do |k, _v|
50
+ result << " * [#{k}](##{k.downcase})"
51
+ end
52
+
53
+ result << '* [Functions](#functions)'
54
+ prepared_help[:functions].sort.map do |k, _v|
55
+ result << " * [#{k}](##{k.downcase})"
56
+ end
57
+
58
+ result.join("\n")
59
+ end
60
+
61
+ def global_options_as_text(opts = {})
62
+ opts = { level: 3 }.merge(opts)
63
+ result = []
64
+
65
+ prepared_help[:global_options].sort.map do |k, v|
66
+ result << %(
67
+ #{opts[:headline_separator] * opts[:level]} #{opts[:code_begin]}#{k}#{opts[:code_end]}
68
+ Usage: #{opts[:code_begin]}#{v['call']}#{opts[:code_end]}
69
+
70
+ #{v['description']}
71
+ )
72
+ end
73
+
74
+ result.join
75
+ end
76
+
77
+ def functions_as_text(opts = {})
78
+ opts = { level: 3, headline_separator: '=' }.merge(opts)
79
+ result = []
80
+
81
+ prepared_help[:functions].sort.map do |k, v|
82
+ result << %(
83
+ #{opts[:headline_separator] * opts[:level]} #{opts[:code_begin]}#{k}#{opts[:code_end]}
84
+ Usage: #{opts[:code_begin]}#{v[:call]}#{opts[:code_end]}
85
+
86
+ #{v[:description]}#{"\n\nSee also: #{v[:see]}" if v[:see]}#{unless v[:options].empty?
87
+ %(
88
+ #{opts[:table_begin]}| Option | Description#{"\n#{opts[:head_postfix_col] * 2}" if opts[:head_postfix_col]}
89
+ #{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]})
90
+ end}
91
+ )
92
+ end
93
+
94
+ result.join
95
+ end
96
+
97
+ def prepared_help
98
+ yaml = YAML.safe_load(raw_help_yaml)
99
+
100
+ result = {}
101
+ result[:functions] = {}
102
+ result[:global_options] = yaml['global_options']
103
+
104
+ functions = result[:functions]
105
+ std_opts = yaml['standard_options']
106
+ yaml.reject { |k, _v| k =~ /.*_options$/ }.each_key do |key|
107
+ functions[key] = {}
108
+ res_item = functions[key]
109
+ res_item[:options] = {}
110
+
111
+ item = yaml[key]
112
+ res_item[:call] = item['call']
113
+ res_item[:description] = item['description']
114
+ res_item[:see] = item['see']
115
+
116
+ opts = ((item['options'] ? item['options'].keys : [])
117
+ (item['standard_options'] ? item['standard_options'].keys : [])).sort
118
+ opts.each do |opt_key|
119
+ res_item[:options][opt_key] = {}
120
+
121
+ if item['standard_options'].key?(opt_key)
122
+ res_item[:options][opt_key][:call] = std_opts[opt_key]['call']
123
+ res_item[:options][opt_key][:description] = "#{std_opts[opt_key]['description']} "\
124
+ "#{item['standard_options'][opt_key]}".chop
125
+ res_item[:options][opt_key][:see] = std_opts[opt_key]['see'] if std_opts[opt_key]['see']
126
+ else
127
+ res_item[:options][opt_key][:call] = item['options'][opt_key]['call']
128
+ res_item[:options][opt_key][:description] = item['options'][opt_key]['description']
129
+ res_item[:options][opt_key][:see] = item['options'][opt_key]['see'] if item['options'][opt_key]['see']
130
+ end
131
+ end
132
+ end
133
+
134
+ result
135
+ end
136
+
137
+ def raw_help_yaml
138
+ <<~YAML_HELP
139
+ global_options:
140
+ grafana_default_instance:
141
+ call: ":grafana_default_instance: <instance_name>"
142
+ description: >-
143
+ Specifies which grafana instance shall be used. If not set, the grafana instance names `default`
144
+ will be used.
145
+
146
+ grafana_default_dashboard:
147
+ call: ":grafana_default_dashboard: <dashboard_uid>"
148
+ description: >-
149
+ Specifies to which dashboard the queries shall be targeted by default.
150
+
151
+ grafana_default_from_timezone:
152
+ call: ":grafana_default_from_timezone: <timezone>"
153
+ description: Specifies which timezone shall be used for the `from` time, e.g. `CET` or `CEST`.
154
+
155
+ grafana_default_to_timezone:
156
+ call: ":grafana_default_to_timezone: <timezone>"
157
+ description: Specifies which timezone shall be used for the `to` time, e.g. `CET` or `CEST`.
158
+
159
+ from:
160
+ call: ":from: <from_timestamp>"
161
+ description: >-
162
+ Overrides the time setting from grafana. It may contain dates as `now-1M/M`, which will be translated
163
+ properly to timestamps relative to the called time.
164
+
165
+ to:
166
+ call: ":to: <to_timestamp>"
167
+ description: >-
168
+ Overrides the time setting from grafana. It may contain dates as `now-1M/M`, which will be translated
169
+ properly to timestamps relative to the called time.
170
+
171
+ standard_options:
172
+ instance:
173
+ call: instance="<instance_name>"
174
+ description: >-
175
+ can be used to override global grafana instance, set in the report with `grafana_default_instance`.
176
+ If nothing is set, the configured grafana instance with name `default` will be used.
177
+
178
+ dashboard:
179
+ call: dashboard="<dashboard_uid>"
180
+ description: >-
181
+ Specifies the dashboard to be used. If `grafana_default_dashboard` is specified in the report template,
182
+ this value can be overridden with this option.
183
+
184
+ from:
185
+ call: from="<timestamp>"
186
+ description: can be used to override default `from` time
187
+
188
+ from_timezone:
189
+ call: from_timezone="<timezone>"
190
+ description: can be used to override system timezone for `from` time and will also override `grafana_default_from_timezone` option
191
+
192
+ to_timezone:
193
+ call: to_timezone="<timezone>"
194
+ description: can be used to override system timezone for `to` time and will also override `grafana_default_to_timezone` option
195
+
196
+ to:
197
+ call: to="<timestamp>"
198
+ description: can be used to override default `to` time
199
+
200
+ format:
201
+ call: format="<format_col1>,<format_col2>,..."
202
+ description: >-
203
+ Specify format in which the results shall be returned, e.g. `%.2f` for only two digit decimals of a
204
+ float. Several columns are separated by `,`. Execution is applied in the following order `format`,
205
+ `replace_values`, `filter_columns`, `transpose`.
206
+ see: 'https://ruby-doc.org/core-2.4.0/Kernel.html#method-i-sprintf'
207
+
208
+ replace_values:
209
+ call: replace_values="<replace_1>:<with_1>,<replace_2>:<with_2>,..."
210
+ description: >-
211
+ Specify result values which shall be replaced, e.g. `2:OK` will replace query values `2` with value `OK`.
212
+ Replacing several values is possible by separating by `,`. Matches with regular expressions are also
213
+ supported, but must be full matches, i.e. have to start with `^` and end with `$`, e.g. `^[012]$:OK`.
214
+ Number replacements can also be performed, e.g. `<8.2` or `<>3`. Execution is applied in the following order `format`,
215
+ `replace_values`, `filter_columns`, `transpose`.
216
+ see: https://ruby-doc.org/core-2.7.1/Regexp.html#class-Regexp-label-Character+Classes
217
+
218
+ filter_columns:
219
+ call: filter_columns="<column_name_1>,<column_name_2>,..."
220
+ description: >-
221
+ Removes specified columns from result. Execution is applied in the following order `format`, `replace_values`,
222
+ `filter_columns`, `transpose`.
223
+
224
+ transpose:
225
+ call: transpose="true"
226
+ description: >-
227
+ Transposes the query result, i.e. columns become rows and rows become columnns. Execution is applied in the
228
+ following order `format`, `replace_values`, `filter_columns`, `transpose`.
229
+
230
+ column_divider:
231
+ call: column_divider="<divider>"
232
+ description: >-
233
+ Replace the default column divider with another one. Defaults to ` | ` for being interpreted as a asciidoctor column.
234
+
235
+ row_divider:
236
+ call: row_divider="<divider>"
237
+ description: >-
238
+ Replace the default row divider with another one. Defaults to `| ` for being interpreted as a asciidoctor row.
239
+
240
+ timeout:
241
+ call: timeout="<timeout_in_seconds>"
242
+ description: >-
243
+ Set a timeout for the current query. If not overridden with `grafana-default-timeout` in the report template,
244
+ this defaults to 60 seconds.
245
+
246
+ # ----------------------------------
247
+ # FUNCTION DOCUMENTATION STARTS HERE
248
+ # ----------------------------------
249
+
250
+ grafana_help:
251
+ description: Show all available grafana calls within the asciidoctor templates, including available options.
252
+ call: 'include::grafana_help[]'
253
+
254
+ grafana_environment:
255
+ description: Shows all available variables in the rendering context which can be used in the asciidoctor template.
256
+ call: 'include::grafana_environment[]'
257
+
258
+ grafana_alerts:
259
+ description: >-
260
+ Returns a table of active alert states including the specified columns and the connected information. Supports
261
+ all query parameters from the Grafana Alerting API, such as `query`, `state`, `limit`, `folderId` and others.
262
+ call: 'include::grafana_alerts[columns="<column_name_1>,<column_name_2>,...",options]'
263
+ see: https://grafana.com/docs/grafana/latest/http_api/alerting/#get-alerts
264
+ options:
265
+ columns:
266
+ description: >-
267
+ Specifies columns that shall be returned. Valid columns are `id`, `dashboardId`, `dashboardUId`, `dashboardSlug`,
268
+ `panelId`, `name`, `state`, `newStateDate`, `evalDate`, `evalData` and `executionError`.
269
+ call: columns="<column_name_1>,<columns_name_2>,..."
270
+ panel:
271
+ description: >-
272
+ If specified, the resulting alerts are filtered for this panel. This option will only work, if a `dashboard`
273
+ or `grafana_default_dashboard` is set.
274
+ call: panel="<panel_id>"
275
+ standard_options:
276
+ column_divider:
277
+ dashboard: >-
278
+ If this option, or the global option `grafana_default_dashboard` is set, the resulting alerts will be limited to
279
+ this dashboard. To show all alerts in this case, specify `dashboard=""` as option.
280
+ filter_columns:
281
+ format:
282
+ from:
283
+ instance:
284
+ replace_values:
285
+ row_divider:
286
+ timeout:
287
+ to:
288
+ transpose:
289
+ from_timezone:
290
+ to_timezone:
291
+
292
+ grafana_annotations:
293
+ description: >-
294
+ Returns a table of all annotations, matching the specified filter criteria and the specified columns. Supports all
295
+ query parameters from the Grafana Alerting API, such as `limit`, `alertId`, `panelId` and others.
296
+ call: 'include::grafana_annotations[columns="<column_name_1>,<column_name_2>,...",options]'
297
+ see: https://grafana.com/docs/grafana/latest/http_api/annotations/#find_annotations
298
+ options:
299
+ columns:
300
+ description: >-
301
+ Specified the columns that shall be returned. Valid columns are `id`, `alertId`, `dashboardId`, `panelId`, `userId`,
302
+ `userName`, `newState`, `prevState`, `time`, `timeEnd`, `text`, `metric` and `type`.
303
+ call: columns="<column_name_1>,<columns_name_2>,..."
304
+ panel:
305
+ description: >-
306
+ If specified, the resulting alerts are filtered for this panel. This option will only work, if a `dashboard` or
307
+ `grafana_default_dashboard` is set.
308
+ call: panel="<panel_id>"
309
+ standard_options:
310
+ column_divider:
311
+ dashboard: >-
312
+ If this option, or the global option `grafana_default_dashboard` is set, the resulting alerts will be limited to this
313
+ dashboard. To show all alerts in this case, specify `dashboard=""` as option.
314
+ filter_columns:
315
+ format:
316
+ from:
317
+ instance:
318
+ replace_values:
319
+ row_divider:
320
+ timeout:
321
+ to:
322
+ transpose:
323
+ from_timezone:
324
+ to_timezone:
325
+
326
+ grafana_panel_property:
327
+ description: >-
328
+ Returns a property field for the specified panel. `<type>` can either be `title` or `description`.
329
+ Grafana variables will be replaced in the returned value.
330
+ call: 'grafana_panel_property:<panel_id>["<type>",options]'
331
+ see: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax
332
+ standard_options:
333
+ dashboard:
334
+ instance:
335
+
336
+ grafana_panel_image:
337
+ description: Includes a panel image as an image in the document. Can be called for inline-images as well as for blocks.
338
+ call: 'grafana_panel_image:<panel_id>[options] or grafana_panel_image::<panel_id>[options]'
339
+ options:
340
+ render-height:
341
+ description: can be used to override default `height` in which the panel shall be rendered
342
+ call: render-height="<height>"
343
+ render-width:
344
+ description: can be used to override default `width` in which the panel shall be rendered
345
+ call: render-width="<width>"
346
+ render-theme:
347
+ description: can be used to override default `theme` in which the panel shall be rendered (light by default)
348
+ call: render-theme="<theme>"
349
+ render-timeout:
350
+ description: can be used to override default `timeout` in which the panel shall be rendered (60 seconds by default)
351
+ call: render-timeout="<timeout>"
352
+ standard_options:
353
+ dashboard:
354
+ from:
355
+ instance:
356
+ timeout:
357
+ to:
358
+ from_timezone:
359
+ to_timezone:
360
+
361
+ grafana_panel_query_table:
362
+ description: >-
363
+ Returns the results of a query, which is configured in a grafana panel, as a table in asciidoctor.
364
+ Grafana variables will be replaced in the panel's SQL statement.
365
+ call: 'include::grafana_panel_query_table:<panel_id>[query="<query_letter>",options]'
366
+ see: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax
367
+ options:
368
+ query:
369
+ call: query="<query_letter>"
370
+ description: +<query_letter>+ needs to point to the grafana query which shall be evaluated, e.g. +A+ or +B+.
371
+ standard_options:
372
+ column_divider:
373
+ dashboard:
374
+ filter_columns:
375
+ format:
376
+ from:
377
+ instance:
378
+ replace_values:
379
+ row_divider:
380
+ timeout:
381
+ to:
382
+ transpose:
383
+ from_timezone:
384
+ to_timezone:
385
+
386
+ grafana_panel_query_value:
387
+ call: 'grafana_panel_query_value:<panel_id>[query="<query_letter>",options]'
388
+ description: >-
389
+ Returns the value in the first column and the first row of a query, which is configured in a grafana panel.
390
+ Grafana variables will be replaced in the panel's SQL statement.
391
+ see: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax
392
+ options:
393
+ query:
394
+ call: query="<query_letter>"
395
+ description: +<query_letter>+ needs to point to the grafana query which shall be evaluated, e.g. +A+ or +B+.
396
+ standard_options:
397
+ dashboard:
398
+ filter_columns:
399
+ format:
400
+ from:
401
+ instance:
402
+ replace_values:
403
+ timeout:
404
+ to:
405
+ from_timezone:
406
+ to_timezone:
407
+
408
+ grafana_sql_table:
409
+ call: 'include::grafana_sql_table:<datasource_id>[sql="<sql_query>",options]'
410
+ description: >-
411
+ Returns a table with all results of the given query.
412
+ Grafana variables will be replaced in the SQL statement.
413
+ see: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax
414
+ standard_options:
415
+ column_divider:
416
+ filter_columns:
417
+ format:
418
+ from:
419
+ instance:
420
+ replace_values:
421
+ row_divider:
422
+ timeout:
423
+ to:
424
+ transpose:
425
+ from_timezone:
426
+ to_timezone:
427
+
428
+ grafana_sql_value:
429
+ call: 'grafana_sql_value:<datasource_id>[sql="<sql_query>",options]'
430
+ description: >-
431
+ Returns the value in the first column and the first row of the given query.
432
+ Grafana variables will be replaced in the SQL statement.
433
+ see: https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#variable-syntax
434
+ standard_options:
435
+ filter_columns:
436
+ format:
437
+ from:
438
+ instance:
439
+ replace_values:
440
+ timeout:
441
+ to:
442
+ from_timezone:
443
+ to_timezone:
444
+ YAML_HELP
445
+ end
446
+ end
447
+ end
@@ -1,52 +1,58 @@
1
- module GrafanaReporter
2
-
3
- # This module contains special extensions for use in the reporter.
4
- module Logger
5
-
6
- # This logger enables a special use case, so that one and the same log
7
- # will automatically be send to two different logger destinations.
8
- #
9
- # One destination is the set {#additional_logger=} which respects the
10
- # configured severity. The other destination is an internal logger, which
11
- # will always log all messages in mode Logger::Severity::Debug. All messages
12
- # of the internal logger can easily be retrieved, by using the
13
- # {#internal_messages} method.
14
- #
15
- # Except the {#level=} setting, all calls to the logger will immediately
16
- # be delegated to the internal logger and the configured {#additional_logger=}.
17
- # By having this behavior, the class can be used wherever the standard Logger
18
- # can also be used.
19
- class TwoWayDelegateLogger
20
- def initialize
21
- @internal_messages = StringIO.new
22
- @internal_logger = ::Logger.new(@internal_messages)
23
- @internal_logger.level = ::Logger::Severity::DEBUG
24
- @additional_logger = ::Logger.new(nil)
25
- end
26
-
27
- # Sets the severity level of the additional logger to the given severity.
28
- # @param severity one of {Logger::Severity}
29
- def level=(severity)
30
- @additional_logger.level = severity
31
- end
32
-
33
- # @return [String] all messages of the internal logger.
34
- def internal_messages
35
- @internal_messages.string
36
- end
37
-
38
- # Used to set the additional logger in this class to an already existing
39
- # logger.
40
- # @param logger [Logger] sets the additional logger to the given value.
41
- def additional_logger=(logger)
42
- @additional_logger = logger || ::Logger.new(nil)
43
- end
44
-
45
- # Delegates all not configured calls to the internal and the additional logger.
46
- def method_missing(method, *args)
47
- @internal_logger.send(method, *args)
48
- @additional_logger.send(method, *args)
49
- end
50
- end
51
- end
52
- end
1
+ # frozen_string_literal: true
2
+
3
+ module GrafanaReporter
4
+ # This module contains special extensions for use in the reporter.
5
+ module Logger
6
+ # This logger enables a special use case, so that one and the same log
7
+ # will automatically be send to two different logger destinations.
8
+ #
9
+ # One destination is the set {#additional_logger=} which respects the
10
+ # configured severity. The other destination is an internal logger, which
11
+ # will always log all messages in mode Logger::Severity::Debug. All messages
12
+ # of the internal logger can easily be retrieved, by using the
13
+ # {#internal_messages} method.
14
+ #
15
+ # Except the {#level=} setting, all calls to the logger will immediately
16
+ # be delegated to the internal logger and the configured {#additional_logger=}.
17
+ # By having this behavior, the class can be used wherever the standard Logger
18
+ # can also be used.
19
+ class TwoWayDelegateLogger
20
+ def initialize
21
+ @internal_messages = StringIO.new
22
+ @internal_logger = ::Logger.new(@internal_messages)
23
+ @internal_logger.level = ::Logger::Severity::DEBUG
24
+ @additional_logger = ::Logger.new(nil)
25
+ end
26
+
27
+ # Sets the severity level of the additional logger to the given severity.
28
+ # @param severity one of Logger::Severity
29
+ def level=(severity)
30
+ @additional_logger.level = severity
31
+ end
32
+
33
+ # @return [String] all messages of the internal logger.
34
+ def internal_messages
35
+ @internal_messages.string
36
+ end
37
+
38
+ # Used to set the additional logger in this class to an already existing
39
+ # logger.
40
+ # @param logger [Logger] sets the additional logger to the given value.
41
+ def additional_logger=(logger)
42
+ @additional_logger = logger || ::Logger.new(nil)
43
+ end
44
+
45
+ # Delegates all not configured calls to the internal and the additional logger.
46
+ def method_missing(method, *args)
47
+ @internal_logger.send(method, *args)
48
+ @additional_logger.send(method, *args)
49
+ end
50
+
51
+ # Registers all methods to which the internal logger responds.
52
+ def respond_to_missing?(method, *_args)
53
+ super
54
+ @internal_logger.respond_to?(method)
55
+ end
56
+ end
57
+ end
58
+ end