Class: Grafana::GrafanaPropertyDatasource

Inherits:
AbstractDatasource show all
Defined in:
lib/grafana/grafana_property_datasource.rb

Overview

Implements the datasource interface to grafana model properties.

Instance Attribute Summary

Attributes inherited from AbstractDatasource

#model

Instance Method Summary collapse

Methods inherited from AbstractDatasource

build_instance, #category, handles?, #id, inherited, #initialize, #raw_query_from_panel_model, #replace_variables, #type, #uid

Constructor Details

This class inherits a constructor from Grafana::AbstractDatasource

Instance Method Details

#default_variable_formatObject



28
29
30
# File 'lib/grafana/grafana_property_datasource.rb', line 28

def default_variable_format
  'glob'
end

#nameObject



33
34
35
# File 'lib/grafana/grafana_property_datasource.rb', line 33

def name
  self.class.to_s
end

#request(query_description) ⇒ Object

:raw_query needs to contain a Hash with the following structure:

{
  property_name: Name of the queried property as String
  panel:         {Panel} object to query
}


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/grafana/grafana_property_datasource.rb', line 13

def request(query_description)
  raise MissingSqlQueryError if query_description[:raw_query].nil?

  panel = query_description[:raw_query][:panel]
  property_name = query_description[:raw_query][:property_name]

  return "Panel property '#{property_name}' does not exist for panel '#{panel.id}'" unless panel.field(property_name)

  {
    header: [query_description[:raw_query][:property_name]],
    content: [replace_variables(panel.field(property_name), query_description[:variables])]
  }
end