Class: Wavefront::Alert
Overview
View and manage alerts. Alerts are identified by their millisecond epoch timestamp. Returns a Wavefront::Response::Alert object.
Instance Attribute Summary
Attributes inherited from CoreApi
Instance Method Summary collapse
-
#alerts_in_state(state) ⇒ Wavfront::Response
Use a search to get all alerts in the given state.
-
#all ⇒ Wavefront::Response
All your alerts.
-
#checking ⇒ Wavefront::Response
All alerts being checked.
-
#create(body) ⇒ Wavefront::Response
POST /api/v2/alert Create a specific alert.
-
#delete(id) ⇒ Wavefront::Response
DELETE /api/v2/alert/id Delete a specific alert.
-
#describe(id, version = nil) ⇒ Wavefront::Response
GET /api/v2/alert/id GET /api/v2/alert/id/history/version Get a specific alert / Get a specific historical version of a specific alert.
-
#firing ⇒ Wavefront::Response
(also: #active)
All currently firing alerts.
-
#history(id, offset = nil, limit = nil) ⇒ Wavefront::Response
GET /api/v2/alert/id/history Get the version history of a specific alert.
-
#in_maintenance ⇒ Wavefront::Response
(also: #affected_by_maintenance)
All alerts currently in a maintenance window.
-
#install(id) ⇒ Object
POST /api/v2/alert/id/install Unhide a specific integration alert.
-
#invalid ⇒ Wavefront::Response
All alerts which have an invalid query.
-
#list(offset = 0, limit = 100) ⇒ Wavefront::Response
GET /api/v2/alert Get all alerts for a customer.
-
#no_data ⇒ Wavefront::Response
All alerts reporting NO_DATA.
-
#none ⇒ Wavefront::Response
I honestly don’t know what the NONE state denotes, but this will fetch alerts which have it.
-
#snooze(id, seconds = nil) ⇒ Wavefront::Response
POST /api/v2/alert/id/snooze Snooze a specific alert for some number of seconds.
-
#snoozed ⇒ Wavefront::Response
All alerts currently snoozed.
-
#summary ⇒ Wavefront::Response
GET /api/v2/alert/summary Count alerts of various statuses for a customer.
-
#tag_add(id, tag) ⇒ Wavefront::Response
PUT /api/v2/alert/id/tag/tagValue Add a tag to a specific alert.
-
#tag_delete(id, tag) ⇒ Wavefront::Response
DELETE /api/v2/alert/id/tag/tagValue Remove a tag from a specific alert.
-
#tag_set(id, tags) ⇒ Wavefront::Response
POST /api/v2/alert/id/tag Set all tags associated with a specific alert.
-
#tags(id) ⇒ Wavefront::Response
GET /api/v2/alert/id/tag Get all tags associated with a specific alert.
-
#trash ⇒ Wavefront::Response
All alerts in the trash.
-
#undelete(id) ⇒ Wavefront::Response
POST /api/v2/alert/id/undelete Undelete a specific alert.
-
#uninstall(id) ⇒ Object
POST /api/v2/alert/id/uninstall Hide a specific integration alert.
-
#unsnooze(id) ⇒ Wavefront::Response
POST /api/v2/alert/id/unsnooze Unsnooze a specific alert.
-
#update(id, body, modify = true) ⇒ Wavefront::Response
PUT /api/v2/alert/id Update a specific alert.
- #update_keys ⇒ Object
Methods inherited from CoreApi
#api_base, #api_path, #hash_for_update, #initialize, #setup_api, #time_to_ms
Methods included from Mixins
#log, #parse_relative_time, #parse_time, #relative_time, #time_multiplier, #valid_relative_time?
Methods included from Validators
#uuid?, #wf_alert_id?, #wf_alert_severity?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_derivedmetric_id?, #wf_distribution?, #wf_distribution_count?, #wf_distribution_interval?, #wf_distribution_values?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_source_id?, #wf_string?, #wf_tag?, #wf_ts?, #wf_user_id?, #wf_usergroup_id?, #wf_value?, #wf_version?, #wf_webhook_id?
Constructor Details
This class inherits a constructor from Wavefront::CoreApi
Instance Method Details
#alerts_in_state(state) ⇒ Wavfront::Response
Use a search to get all alerts in the given state. You would be better to use one of the wrapper methods like #firing, #snoozed etc, but I’ve left this method public in case new states are added before the SDK supports them.
296 297 298 299 300 301 |
# File 'lib/wavefront-sdk/alert.rb', line 296 def alerts_in_state(state) require_relative 'search' wfs = Wavefront::Search.new(creds, opts) query = { key: 'status', value: state, matchingMethod: 'EXACT' } wfs.search(:alert, query, limit: :all, offset: PAGE_SIZE) end |
#all ⇒ Wavefront::Response
Returns all your alerts.
284 285 286 |
# File 'lib/wavefront-sdk/alert.rb', line 284 def all list(PAGE_SIZE, :all) end |
#checking ⇒ Wavefront::Response
Returns all alerts being checked.
266 267 268 |
# File 'lib/wavefront-sdk/alert.rb', line 266 def checking alerts_in_state(:checking) end |
#create(body) ⇒ Wavefront::Response
POST /api/v2/alert Create a specific alert. We used to validate input here, but this couples the SDK too tightly to the API. Now it’s just a generic POST of a hash.
34 35 36 37 |
# File 'lib/wavefront-sdk/alert.rb', line 34 def create(body) raise ArgumentError unless body.is_a?(Hash) api.post('', body, 'application/json') end |
#delete(id) ⇒ Wavefront::Response
DELETE /api/v2/alert/id Delete a specific alert.
Deleting an active alert moves it to ‘trash’, from where it can be restored with an #undelete operation. Deleting an alert in ‘trash’ removes it for ever.
49 50 51 52 |
# File 'lib/wavefront-sdk/alert.rb', line 49 def delete(id) wf_alert_id?(id) api.delete(id) end |
#describe(id, version = nil) ⇒ Wavefront::Response
GET /api/v2/alert/id GET /api/v2/alert/id/history/version Get a specific alert / Get a specific historical version of a specific alert.
63 64 65 66 67 68 69 |
# File 'lib/wavefront-sdk/alert.rb', line 63 def describe(id, version = nil) wf_alert_id?(id) wf_version?(version) if version fragments = [id] fragments += ['history', version] if version api.get(fragments.uri_concat) end |
#firing ⇒ Wavefront::Response Also known as: active
Returns all currently firing alerts.
243 244 245 |
# File 'lib/wavefront-sdk/alert.rb', line 243 def firing alerts_in_state(:firing) end |
#history(id, offset = nil, limit = nil) ⇒ Wavefront::Response
GET /api/v2/alert/id/history Get the version history of a specific alert.
98 99 100 101 102 103 104 105 |
# File 'lib/wavefront-sdk/alert.rb', line 98 def history(id, offset = nil, limit = nil) wf_alert_id?(id) qs = {} qs[:offset] = offset if offset qs[:limit] = limit if limit api.get([id, 'history'].uri_concat, qs) end |
#in_maintenance ⇒ Wavefront::Response Also known as: affected_by_maintenance
Returns all alerts currently in a maintenance window.
251 252 253 |
# File 'lib/wavefront-sdk/alert.rb', line 251 def in_maintenance alerts_in_state(:in_maintenance) end |
#install(id) ⇒ Object
POST /api/v2/alert/id/install Unhide a specific integration alert
110 111 112 113 |
# File 'lib/wavefront-sdk/alert.rb', line 110 def install(id) wf_alert_id?(id) api.post([id, 'install'].uri_concat, nil) end |
#invalid ⇒ Wavefront::Response
Returns all alerts which have an invalid query.
228 229 230 |
# File 'lib/wavefront-sdk/alert.rb', line 228 def invalid alerts_in_state(:invalid) end |
#list(offset = 0, limit = 100) ⇒ Wavefront::Response
GET /api/v2/alert Get all alerts for a customer
22 23 24 |
# File 'lib/wavefront-sdk/alert.rb', line 22 def list(offset = 0, limit = 100) api.get('', offset: offset, limit: limit) end |
#no_data ⇒ Wavefront::Response
Returns all alerts reporting NO_DATA.
278 279 280 |
# File 'lib/wavefront-sdk/alert.rb', line 278 def no_data alerts_in_state(:no_data) end |
#none ⇒ Wavefront::Response
Returns I honestly don’t know what the NONE state denotes, but this will fetch alerts which have it.
260 261 262 |
# File 'lib/wavefront-sdk/alert.rb', line 260 def none alerts_in_state(:none) end |
#snooze(id, seconds = nil) ⇒ Wavefront::Response
POST /api/v2/alert/id/snooze Snooze a specific alert for some number of seconds.
123 124 125 126 127 |
# File 'lib/wavefront-sdk/alert.rb', line 123 def snooze(id, seconds = nil) wf_alert_id?(id) qs = seconds ? "?seconds=#{seconds}" : '' api.post([id, "snooze#{qs}"].uri_concat, nil) end |
#snoozed ⇒ Wavefront::Response
Returns all alerts currently snoozed.
237 238 239 |
# File 'lib/wavefront-sdk/alert.rb', line 237 def snoozed alerts_in_state(:snoozed) end |
#summary ⇒ Wavefront::Response
GET /api/v2/alert/summary Count alerts of various statuses for a customer
215 216 217 |
# File 'lib/wavefront-sdk/alert.rb', line 215 def summary api.get('summary') end |
#tag_add(id, tag) ⇒ Wavefront::Response
PUT /api/v2/alert/id/tag/tagValue Add a tag to a specific alert.
174 175 176 177 178 |
# File 'lib/wavefront-sdk/alert.rb', line 174 def tag_add(id, tag) wf_alert_id?(id) wf_string?(tag) api.put([id, 'tag', tag].uri_concat) end |
#tag_delete(id, tag) ⇒ Wavefront::Response
DELETE /api/v2/alert/id/tag/tagValue Remove a tag from a specific alert.
161 162 163 164 165 |
# File 'lib/wavefront-sdk/alert.rb', line 161 def tag_delete(id, tag) wf_alert_id?(id) wf_string?(tag) api.delete([id, 'tag', tag].uri_concat) end |
#tag_set(id, tags) ⇒ Wavefront::Response
POST /api/v2/alert/id/tag Set all tags associated with a specific alert.
147 148 149 150 151 152 |
# File 'lib/wavefront-sdk/alert.rb', line 147 def tag_set(id, ) wf_alert_id?(id) = Array() .each { |t| wf_string?(t) } api.post([id, 'tag'].uri_concat, .to_json, 'application/json') end |
#tags(id) ⇒ Wavefront::Response
GET /api/v2/alert/id/tag Get all tags associated with a specific alert.
135 136 137 138 |
# File 'lib/wavefront-sdk/alert.rb', line 135 def (id) wf_alert_id?(id) api.get([id, 'tag'].uri_concat) end |
#trash ⇒ Wavefront::Response
Returns all alerts in the trash.
272 273 274 |
# File 'lib/wavefront-sdk/alert.rb', line 272 def trash alerts_in_state(:trash) end |
#undelete(id) ⇒ Wavefront::Response
POST /api/v2/alert/id/undelete Undelete a specific alert.
186 187 188 189 |
# File 'lib/wavefront-sdk/alert.rb', line 186 def undelete(id) wf_alert_id?(id) api.post([id, 'undelete'].uri_concat) end |
#uninstall(id) ⇒ Object
POST /api/v2/alert/id/uninstall Hide a specific integration alert
194 195 196 197 |
# File 'lib/wavefront-sdk/alert.rb', line 194 def uninstall(id) wf_alert_id?(id) api.post([id, 'uninstall'].uri_concat, nil) end |
#unsnooze(id) ⇒ Wavefront::Response
POST /api/v2/alert/id/unsnooze Unsnooze a specific alert.
205 206 207 208 |
# File 'lib/wavefront-sdk/alert.rb', line 205 def unsnooze(id) wf_alert_id?(id) api.post([id, 'unsnooze'].uri_concat) end |
#update(id, body, modify = true) ⇒ Wavefront::Response
PUT /api/v2/alert/id Update a specific alert.
82 83 84 85 86 87 88 89 90 |
# File 'lib/wavefront-sdk/alert.rb', line 82 def update(id, body, modify = true) wf_alert_id?(id) raise ArgumentError unless body.is_a?(Hash) return api.put(id, body, 'application/json') unless modify api.put(id, hash_for_update(describe(id).response, body), 'application/json') end |
#update_keys ⇒ Object
10 11 12 13 |
# File 'lib/wavefront-sdk/alert.rb', line 10 def update_keys %i[id name target condition displayExpression minutes resolveAfterMinutes severity additionalInformation] end |