Class: GrafanaReporter::Asciidoctor::AlertsTableIncludeProcessor
- Inherits:
-
Asciidoctor::Extensions::IncludeProcessor
- Object
- Asciidoctor::Extensions::IncludeProcessor
- GrafanaReporter::Asciidoctor::AlertsTableIncludeProcessor
- Includes:
- ProcessorMixin
- Defined in:
- lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb
Overview
Implements the hook
include::grafana_alerts[<options>]
Returns the results of alerts query as a asciidoctor table.
Used document parameters
grafana_default_instance
- name of grafana instance, ‘default’ if not specified
grafana_default_dashboard
- uid of grafana default dashboard to use
from
- ‘from’ time for the sql query
to
- ‘to’ time for the sql query
Supported options
columns
- see GrafanaReporter::AlertsTableQuery#pre_process (mandatory)
instance
- name of grafana instance, ‘default’ if not specified
dashboard
- uid of grafana dashboard to query for, empty string if no filter is wanted
panel
- id of the panel to query for
from
- ‘from’ time for the sql query
to
- ‘to’ time for the sql query
format
- see GrafanaReporter::AbstractQuery#format_columns
replace_values
- see GrafanaReporter::AbstractQuery#replace_values
filter_columns
- see GrafanaReporter::AbstractQuery#filter_columns
Instance Method Summary collapse
- #build_demo_entry(_panel) ⇒ Object
-
#handles?(target) ⇒ Boolean
:nodoc:.
-
#process(doc, reader, _target, attrs) ⇒ Object
:nodoc:.
Methods included from ProcessorMixin
#build_attribute_hash, #current_report
Instance Method Details
#build_demo_entry(_panel) ⇒ Object
87 88 89 |
# File 'lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb', line 87 def build_demo_entry(_panel) "|===\ninclude::grafana_alerts[columns=\"panelId,name,state\"]\n|===" end |
#handles?(target) ⇒ Boolean
:nodoc:
43 44 45 |
# File 'lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb', line 43 def handles?(target) target.start_with? 'grafana_alerts' end |
#process(doc, reader, _target, attrs) ⇒ Object
:nodoc:
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 79 80 81 82 83 84 |
# File 'lib/grafana_reporter/asciidoctor/alerts_table_include_processor.rb', line 48 def process(doc, reader, _target, attrs) return if @report.cancel @report.next_step instance = attrs['instance'] || doc.attr('grafana_default_instance') || 'default' dashboard_id = attrs['dashboard'] || doc.attr('grafana_default_dashboard') panel_id = attrs['panel'] @report.logger.debug("Processing AlertsTableIncludeProcessor (instance: #{instance},"\ " dashboard: #{dashboard_id}, panel: #{panel_id})") grafana_obj = @report.grafana(instance) grafana_obj = @report.grafana(instance).dashboard(dashboard_id) if dashboard_id grafana_obj = grafana_obj.panel(panel_id) if panel_id vars = { 'table_formatter' => 'adoc_plain' }.merge(build_attribute_hash(doc.attributes, attrs)) query = AlertsTableQuery.new(grafana_obj, variables: vars) defaults = {} defaults['dashboardId'] = dashboard_id if dashboard_id defaults['panelId'] = panel_id if panel_id selected_attrs = attrs.select do |k, _v| k =~ /(?:columns|limit|folderId|dashboardId|panelId|dahboardTag|dashboardQuery|state|query)/x end query.raw_query = defaults.merge(selected_attrs.each_with_object({}) { |(k, v), h| h[k] = v }) begin reader.unshift_lines query.execute.split("\n") rescue GrafanaReporterError => e @report.logger.error(e.) reader.unshift_line "|#{e.}" rescue StandardError => e @report.logger.fatal("#{e.}\n#{e.backtrace.join("\n")}") reader.unshift_line "|#{e.}\n#{e.backtrace.join("\n")}" end reader end |