Class: Wavefront::Alert

Inherits:
CoreApi show all
Includes:
Mixin::Acl, Mixin::Tag
Defined in:
lib/wavefront-sdk/alert.rb

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

#api, #creds, #logger, #opts

Instance Method Summary collapse

Methods included from Mixin::Tag

#tag_add, #tag_delete, #tag_set, #tags

Methods included from Mixin::Acl

#acl_add, #acl_delete, #acl_set, #acls

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_account_id?, #wf_alert_id?, #wf_alert_severity?, #wf_apitoken_id?, #wf_aws_external_id?, #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_ingestionpolicy_id?, #wf_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_metricspolicy_id?, #wf_monitoredapplication_id?, #wf_monitoredcluster_id?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_permission?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_role_id?, #wf_sampling_value?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_serviceaccount_id?, #wf_source_id?, #wf_spansamplingpolicy_id?, #wf_string?, #wf_tag?, #wf_trace?, #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.

Parameters:

  • state (Symbol)

    state such as :firing, :snoozed etc. See the Alert Swagger documentation for a full list

Returns:

  • (Wavfront::Response)


307
308
309
310
311
312
# File 'lib/wavefront-sdk/alert.rb', line 307

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

#allWavefront::Response

Returns all your alerts.

Returns:



295
296
297
# File 'lib/wavefront-sdk/alert.rb', line 295

def all
  list(PAGE_SIZE, :all)
end

#check_query(query) ⇒ Wavefront::Response

POST /api/v2/alert/checkQuery Return the type of provided query.

Parameters:

  • query (Hash)

    description of query

Returns:



208
209
210
# File 'lib/wavefront-sdk/alert.rb', line 208

def check_query(query)
  api.post('checkQuery', query, 'application/json')
end

#checkingWavefront::Response

Returns all alerts being checked.

Returns:



277
278
279
# File 'lib/wavefront-sdk/alert.rb', line 277

def checking
  alerts_in_state(:checking)
end

#clone(id, version = nil) ⇒ Wavefront::Response

POST /api/v2/alert/id/clone Clones the specified alert

Parameters:

  • id (String)

    ID of the alert

  • version (Integer) (defaults to: nil)

    version of alert

Returns:



122
123
124
125
126
127
128
129
130
# File 'lib/wavefront-sdk/alert.rb', line 122

def clone(id, version = nil)
  wf_alert_id?(id)
  wf_version?(version) if version

  api.post([id, 'clone'].uri_concat,
           { id: id,
             name: nil,
             v: version }, 'application/json')
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.

Parameters:

  • body (Hash)

    description of alert

Returns:

Raises:

  • (ArgumentError)


41
42
43
44
45
# File 'lib/wavefront-sdk/alert.rb', line 41

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.

Parameters:

  • id (String)

    ID of the alert

Returns:



57
58
59
60
# File 'lib/wavefront-sdk/alert.rb', line 57

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.

Parameters:

  • id (String)

    ID of the alert

  • version (Integer) (defaults to: nil)

    version of alert

Returns:



71
72
73
74
75
76
77
# File 'lib/wavefront-sdk/alert.rb', line 71

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

#firingWavefront::Response Also known as: active

Returns all currently firing alerts.

Returns:



254
255
256
# File 'lib/wavefront-sdk/alert.rb', line 254

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.

Parameters:

  • id (String)

    ID of the alert

Returns:



138
139
140
141
142
143
144
145
# File 'lib/wavefront-sdk/alert.rb', line 138

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_maintenanceWavefront::Response Also known as: affected_by_maintenance

Returns all alerts currently in a maintenance window.

Returns:



262
263
264
# File 'lib/wavefront-sdk/alert.rb', line 262

def in_maintenance
  alerts_in_state(:in_maintenance)
end

#install(id) ⇒ Object

POST /api/v2/alert/id/install Unhide a specific integration alert



150
151
152
153
# File 'lib/wavefront-sdk/alert.rb', line 150

def install(id)
  wf_alert_id?(id)
  api.post([id, 'install'].uri_concat, nil)
end

#invalidWavefront::Response

Returns all alerts which have an invalid query.

Returns:



239
240
241
# File 'lib/wavefront-sdk/alert.rb', line 239

def invalid
  alerts_in_state(:invalid)
end

#list(offset = 0, limit = 100) ⇒ Wavefront::Response

GET /api/v2/alert Get all alerts for a customer

Parameters:

  • offset (Int) (defaults to: 0)

    alert at which the list begins

  • limit (Int) (defaults to: 100)

    the number of alerts to return

Returns:



29
30
31
# File 'lib/wavefront-sdk/alert.rb', line 29

def list(offset = 0, limit = 100)
  api.get('', offset: offset, limit: limit)
end

#no_dataWavefront::Response

Returns all alerts reporting NO_DATA.

Returns:



289
290
291
# File 'lib/wavefront-sdk/alert.rb', line 289

def no_data
  alerts_in_state(:no_data)
end

#noneWavefront::Response

Returns I honestly don’t know what the NONE state denotes, but this will fetch alerts which have it.

Returns:

  • (Wavefront::Response)

    I honestly don’t know what the NONE state denotes, but this will fetch alerts which have it.



271
272
273
# File 'lib/wavefront-sdk/alert.rb', line 271

def none
  alerts_in_state(:none)
end

#preview(alert) ⇒ Wavefront::Response

POST /api/v2/alert/preview Get all the notification preview for a specific alert

Parameters:

  • alert (Hash)

    description of alert

Returns:



217
218
219
# File 'lib/wavefront-sdk/alert.rb', line 217

def preview(alert)
  api.post('preview', alert, 'application/json')
end

#snooze(id, seconds = nil) ⇒ Wavefront::Response

POST /api/v2/alert/id/snooze Snooze a specific alert for some number of seconds.

Parameters:

  • id (String)

    ID of the alert

  • seconds (Integer) (defaults to: nil)

    how many seconds to snooze for. Nil is indefinite.

Returns:



163
164
165
166
167
# File 'lib/wavefront-sdk/alert.rb', line 163

def snooze(id, seconds = nil)
  wf_alert_id?(id)
  qs = seconds ? "?seconds=#{seconds}" : ''
  api.post([id, "snooze#{qs}"].uri_concat, nil)
end

#snoozedWavefront::Response

Returns all alerts currently snoozed.

Returns:



248
249
250
# File 'lib/wavefront-sdk/alert.rb', line 248

def snoozed
  alerts_in_state(:snoozed)
end

#summaryWavefront::Response

GET /api/v2/alert/summary Count alerts of various statuses for a customer

Returns:



226
227
228
# File 'lib/wavefront-sdk/alert.rb', line 226

def summary
  api.get('summary')
end

#trashWavefront::Response

Returns all alerts in the trash.

Returns:



283
284
285
# File 'lib/wavefront-sdk/alert.rb', line 283

def trash
  alerts_in_state(:trash)
end

#undelete(id) ⇒ Wavefront::Response

POST /api/v2/alert/id/undelete Undelete a specific alert.

Parameters:

  • id (String)

    ID of the alert

Returns:



179
180
181
182
# File 'lib/wavefront-sdk/alert.rb', line 179

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



187
188
189
190
# File 'lib/wavefront-sdk/alert.rb', line 187

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.

Parameters:

  • id (String)

    ID of the alert

Returns:



198
199
200
201
# File 'lib/wavefront-sdk/alert.rb', line 198

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.

Parameters:

  • id (String)

    a Wavefront alert ID

  • body (Hash)

    key-value hash of the parameters you wish to change

  • modify (true, false) (defaults to: true)

    if true, use #describe() to get a hash describing the existing object, and modify that with the new body. If false, pass the new body straight through.

Returns:

Raises:

  • (ArgumentError)


106
107
108
109
110
111
112
113
114
# File 'lib/wavefront-sdk/alert.rb', line 106

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_keysObject



17
18
19
20
# File 'lib/wavefront-sdk/alert.rb', line 17

def update_keys
  %i[id name target condition displayExpression minutes tag
     resolveAfterMinutes severity additionalInformation]
end

#valid_id?(id) ⇒ Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/wavefront-sdk/alert.rb', line 169

def valid_id?(id)
  wf_alert_id?(id)
end

#versions(id) ⇒ Wavefront::Response

GET /api/v2/alert/id/history Get the version history of a specific alert

Parameters:

  • id (String)

    ID of the alert

Returns:



84
85
86
87
88
89
90
91
92
93
# File 'lib/wavefront-sdk/alert.rb', line 84

def versions(id)
  wf_alert_id?(id)
  resp = api.get([id, 'history'].uri_concat)

  return if opts[:noop]

  versions = resp.response.items.map(&:version)
  resp.response[:items] = versions
  resp
end