module Grafana::Modules::Alert

Public Instance Methods

alert(id:) click to toggle source
# File lib/grafana/modules/alert.rb, line 26
def alert(id:)
  get("/api/alerts/#{id}")
end
alerts(**options) click to toggle source
# 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) click to toggle source

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

# 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:) click to toggle source

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

# File lib/grafana/modules/alert.rb, line 39
def unpause_alert(id:)
  pause_alert(id: id, paused: false)
end