Module: Grafana::Modules::Alert
- Included in:
- Alerts
- Defined in:
- lib/grafana/modules/alert.rb
Instance Method Summary collapse
- #alert(id:) ⇒ Object
- #alerts(**options) ⇒ Object
-
#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.
-
#unpause_alert(id:) ⇒ Object
Helper method to unpause an alert as passing paused: false is not as intuitive.
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(**) = .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'] [:panelId] = .delete(:panel_id) if [:panel_id].present? [:folderId] = Array.wrap(.delete(:folder_id)) if [:folder_id].present? [:dashboardId] = Array.wrap(.delete(:dashboard_id)) if [:dashboard_id].present? [:dasboardQuery] = .delete(:dahsboard_query) if [:dashboard_query].present? [:dashboardTag] = Array.wrap(.delete(:dashboard_tag)) if [:dashboard_tag].present? [:state] = Array.wrap([:state] || 'ALL') & valid_alert_states .delete(:limit) unless [:limit].is_a?(Integer) alert_url = '/api/alerts' alert_url += "?#{URI.encode_www_form()}" if .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 |