Class: Grafana::GrafanaAlertsDatasource
- Inherits:
-
AbstractDatasource
- Object
- AbstractDatasource
- Grafana::GrafanaAlertsDatasource
- Defined in:
- lib/grafana/grafana_alerts_datasource.rb
Overview
Implements the datasource interface to grafana alerts.
Instance Attribute Summary
Attributes inherited from AbstractDatasource
Instance Method Summary collapse
-
#request(query_description) ⇒ Object
:raw_query
needs to contain a Hash with the following structure:.
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:
query:
state:
folderId:
dashboardQuery:
dashboardTag:
}
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/grafana/grafana_alerts_datasource.rb', line 20 def request(query_description) webrequest = query_description[:prepared_request] webrequest.relative_url = "/api/alerts#{url_parameters(query_description)}" result = webrequest.execute(query_description[:timeout]) return unless result return result.body unless result.code.to_s == "200" 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., 'columns', query_description[:raw_query]['columns']) end result = {} result[:header] = [query_description[:raw_query]['columns'].split(',')] result[:content] = content result end |