Class: GrafanaReporter::Asciidoctor::ShowEnvironmentIncludeProcessor

Inherits:
Asciidoctor::Extensions::IncludeProcessor
  • Object
show all
Includes:
ProcessorMixin
Defined in:
lib/grafana_reporter/asciidoctor/show_environment_include_processor.rb

Overview

Implements the hook

include::grafana_environment[]

Shows all available variables, which are accessible during this run of the asciidoctor grafana reporter in a asciidoctor readable form.

This processor is very helpful during report template design, to find out the available variables, that can be accessed.

Used document parameters

All, to be listed as the available environment.

Supported options

instance - grafana instance name, if extended information about the grafana instance shall be printed

Instance Method Summary collapse

Methods included from ProcessorMixin

#build_attribute_hash, #current_report

Instance Method Details

#build_demo_entry(_panel) ⇒ Object



72
73
74
# File 'lib/grafana_reporter/asciidoctor/show_environment_include_processor.rb', line 72

def build_demo_entry(_panel)
  'include::grafana_environment[]'
end

#handles?(target) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


23
24
25
# File 'lib/grafana_reporter/asciidoctor/show_environment_include_processor.rb', line 23

def handles?(target)
  target.start_with? 'grafana_environment'
end

#process(doc, reader, _target, attrs) ⇒ Object

:nodoc:



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
# File 'lib/grafana_reporter/asciidoctor/show_environment_include_processor.rb', line 28

def process(doc, reader, _target, attrs)
  # return if @report.cancel
  @report.next_step
  instance = attrs['instance'] || doc.attr('grafana_default_instance') || 'default'
  attrs['result_type'] = 'sql_table'
  @report.logger.debug('Processing ShowEnvironmentIncludeProcessor')
  grafana = @report.grafana(instance)

  vars = { 'table_formatter' => 'adoc_plain', 'include_headline' => 'true'}
  vars = vars.merge(build_attribute_hash(doc.attributes, attrs))

  # query reporter environment
  result = ['== Reporter', '|===']
  query = QueryValueQuery.new(grafana, variables: vars.merge({'transpose' => 'true'}))
  query.datasource = ::GrafanaReporter::ReporterEnvironmentDatasource.new(nil)
  result += query.execute.split("\n")

  # query grafana environment
  result += ['|===', '',
             '== Grafana Instance', '|===']
  query = QueryValueQuery.new(grafana, variables: vars.merge({'transpose' => 'true'}))
  query.raw_query = {grafana: grafana, mode: 'general'}
  query.datasource = ::Grafana::GrafanaEnvironmentDatasource.new(nil)
  result += query.execute.split("\n")

  result += ['|===', '',
             '== Accessible Dashboards', '|===']
  query = QueryValueQuery.new(grafana, variables: vars)
  query.raw_query = {grafana: grafana, mode: 'dashboards'}
  query.datasource = Grafana::GrafanaEnvironmentDatasource.new(nil)
  result += query.execute.split("\n")

  result += ['|===', '',
             '== Accessible Variables',
             '|===']
  doc.attributes.sort.each do |k, v|
    result << "| `+{#{k}}+` | #{v}"
  end
  result << '|==='

  reader.unshift_lines result
end