Module: Grafana::Modules::Alert

Included in:
Alerts
Defined in:
lib/grafana/modules/alert.rb

Instance Method Summary collapse

Instance Method Details

#alert(id:) ⇒ Object



26
27
28
# File 'lib/grafana/modules/alert.rb', line 26

def alert(id:)
  get("/api/alerts/#{id}")
end

#alerts(**options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/grafana/modules/alert.rb', line 6

def alerts(**options)
  options = options.slice(:folder_id, :dashboard_id, :panel_id, :query, :state, 
                          :limit, :dashboard_query, :dasboard_tag).compact

  valid_alert_states = ['ALL', 'no_data', 'paused', 'alerting', 'ok', 'pending']

  options[:panelId] = options.delete(:panel_id) if options[:panel_id].present?
  options[:folderId] = Array.wrap(options.delete(:folder_id)) if options[:folder_id].present?
  options[:dashboardId] = Array.wrap(options.delete(:dashboard_id)) if options[:dashboard_id].present?
  options[:dasboardQuery] = options.delete(:dahsboard_query) if options[:dashboard_query].present?
  options[:dashboardTag] = Array.wrap(options.delete(:dashboard_tag)) if options[:dashboard_tag].present?
  options[:state] = Array.wrap(options[:state] || 'ALL') & valid_alert_states

  options.delete(:limit) unless options[:limit].is_a?(Integer)

  alert_url = '/api/alerts'
  alert_url += "?#{URI.encode_www_form(options)}" if options.any?
  get(alert_url)
end

#pause_alert(id:, paused: true) ⇒ Object

CRUD actions are done in alerts via modifying the associated dashboard TODO: create CRUD actions in client that will do the appropriate lookups and changes more directly



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

def pause_alert(id:, paused: true)
  post("/api/alerts/#{id}/pause", { paused: paused })
end

#unpause_alert(id:) ⇒ Object

Helper method to unpause an alert as passing paused: false is not as intuitive



39
40
41
# File 'lib/grafana/modules/alert.rb', line 39

def unpause_alert(id:)
  pause_alert(id: id, paused: false)
end