Class: GrafanaReporter::ERB::DemoReportBuilder
- Inherits:
-
Object
- Object
- GrafanaReporter::ERB::DemoReportBuilder
- Defined in:
- lib/grafana_reporter/erb/demo_report_builder.rb
Overview
This class builds a demo report for ERB templates
Instance Method Summary collapse
-
#build_demo_entry(panel) ⇒ String
This method is called if a demo report shall be built for the given Grafana::Panel.
Instance Method Details
#build_demo_entry(panel) ⇒ String
This method is called if a demo report shall be built for the given Grafana::Panel.
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 |
# File 'lib/grafana_reporter/erb/demo_report_builder.rb', line 10 def build_demo_entry(panel) return nil unless panel return nil unless panel.model['type'].include?('table') ref_id = nil panel.model['targets'].each do |item| if !item['hide'] && !panel.query(item['refId']).to_s.empty? ref_id = item['refId'] break end end return nil unless ref_id <<~DEMO_ERB_TEMPLATE <% dashboard = '#{panel.dashboard.id}' instance = 'default' # load the panel object from grafana instance panel = @report.grafana(instance).dashboard(dashboard).panel(#{panel.id}) # build a complete attributes hash, including the variables set for this report call # e.g. including command line parameters etc. attrs = @attributes.merge({ 'result_type' => 'panel_table', 'query' => '#{ref_id}' }) query = QueryValueQuery.new(panel, variables: attrs) %> This is a test table for panel <%= panel.id %>: <%= query.execute %> For detailed API documentation you may start with: 1) the AbstractReport (https://rubydoc.info/gems/ruby-grafana-reporter/GrafanaReporter/AbstractReport), or 2) subclasses of the AbstractQuery (https://rubydoc.info/gems/ruby-grafana-reporter/GrafanaReporter/AbstractQuery) DEMO_ERB_TEMPLATE end |