Class: Grafana::GrafanaAnnotationsDatasource

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

Overview

Implements the datasource interface to grafana annotations.

Instance Attribute Summary

Attributes inherited from AbstractDatasource

#model

Instance Method Summary collapse

Methods inherited from AbstractDatasource

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

Constructor Details

This class inherits a constructor from Grafana::AbstractDatasource

Instance Method Details

#request(query_description) ⇒ Object

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

{
  dashboardId: Dashboard ID as String or nil
  panelId:     Panel ID as String or nil
  columns:
  limit:
  alertId:
  userId:
  type:
  tags:
}


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/grafana/grafana_annotations_datasource.rb', line 19

def request(query_description)
  webrequest = query_description[:prepared_request]
  webrequest.relative_url = "/api/annotations#{url_parameters(query_description)}"

  result = webrequest.execute(query_description[:timeout])
  return unless result

  json = JSON.parse(result.body)

  content = []
  begin
    json.each { |item| content << item.fetch_values(*query_description[:raw_query]['columns'].split(',')) }
  rescue KeyError => e
    raise MalformedAttributeContentError.new(e.message, 'columns', query_description[:raw_query]['columns'])
  end

  result = {}
  result[:header] = [query_description[:raw_query]['columns'].split(',')]
  result[:content] = content

  result
end