class Wavefront::Alert

View and manage alerts. Alerts are identified by their millisecond epoch timestamp. Returns a Wavefront::Response::Alert object.

Public Instance Methods

active()
Alias for: firing
affected_by_maintenance()
Alias for: in_maintenance
alerts_in_state(state) click to toggle source

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. @param state [Symbol] state such as :firing, :snoozed etc. See

the Alert Swagger documentation for a full list

@return [Wavfront::Response]

# File lib/wavefront-sdk/alert.rb, line 288
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() click to toggle source

@return [Wavefront::Response] all your alerts

# File lib/wavefront-sdk/alert.rb, line 276
def all
  list(PAGE_SIZE, :all)
end
checking() click to toggle source

@return [Wavefront::Response] all alerts being checked.

# File lib/wavefront-sdk/alert.rb, line 258
def checking
  alerts_in_state(:checking)
end
clone(id, version = nil) click to toggle source

POST /api/v2/alert/{id}/clone Clones the specified alert @param id [String] ID of the alert @param version [Integer] version of alert @return [Wavefront::Response]

# File lib/wavefront-sdk/alert.rb, line 121
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) click to toggle source

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.

@param body [Hash] description of alert @return [Wavefront::Response]

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

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.

@param id [String] ID of the alert @return [Wavefront::Response]

# File lib/wavefront-sdk/alert.rb, line 57
def delete(id)
  wf_alert_id?(id)
  api.delete(id)
end
describe(id, version = nil) click to toggle source

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.

@param id [String] ID of the alert @param version [Integer] version of alert @return [Wavefront::Response]

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

@return [Wavefront::Response] all currently firing alerts.

# File lib/wavefront-sdk/alert.rb, line 235
def firing
  alerts_in_state(:firing)
end
Also aliased as: active
history(id, offset = nil, limit = nil) click to toggle source

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

@param id [String] ID of the alert @return [Wavefront::Response]

# File lib/wavefront-sdk/alert.rb, line 137
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() click to toggle source

@return [Wavefront::Response] all alerts currently in a

maintenance window.
# File lib/wavefront-sdk/alert.rb, line 243
def in_maintenance
  alerts_in_state(:in_maintenance)
end
Also aliased as: affected_by_maintenance
install(id) click to toggle source

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

# File lib/wavefront-sdk/alert.rb, line 149
def install(id)
  wf_alert_id?(id)
  api.post([id, 'install'].uri_concat, nil)
end
invalid() click to toggle source

@return [Wavefront::Response] all alerts which have an invalid

query.
# File lib/wavefront-sdk/alert.rb, line 220
def invalid
  alerts_in_state(:invalid)
end
list(offset = 0, limit = 100) click to toggle source

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

@param offset [Int] alert at which the list begins @param limit [Int] the number of alerts to return @return [Wavefront::Response]

# File lib/wavefront-sdk/alert.rb, line 29
def list(offset = 0, limit = 100)
  api.get('', offset: offset, limit: limit)
end
no_data() click to toggle source

@return [Wavefront::Response] all alerts reporting NO_DATA.

# File lib/wavefront-sdk/alert.rb, line 270
def no_data
  alerts_in_state(:no_data)
end
none() click to toggle source

@return [Wavefront::Response] I honestly don't know what the

NONE state denotes, but this will fetch alerts which have
it.
# File lib/wavefront-sdk/alert.rb, line 252
def none
  alerts_in_state(:none)
end
snooze(id, seconds = nil) click to toggle source

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

@param id [String] ID of the alert @param seconds [Integer] how many seconds to snooze for.

Nil is indefinite.

@return [Wavefront::Response]

# File lib/wavefront-sdk/alert.rb, line 162
def snooze(id, seconds = nil)
  wf_alert_id?(id)
  qs = seconds ? "?seconds=#{seconds}" : ''
  api.post([id, "snooze#{qs}"].uri_concat, nil)
end
snoozed() click to toggle source

@return [Wavefront::Response] all alerts currently snoozed

# File lib/wavefront-sdk/alert.rb, line 229
def snoozed
  alerts_in_state(:snoozed)
end
summary() click to toggle source

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

@return [Wavefront::Response]

# File lib/wavefront-sdk/alert.rb, line 207
def summary
  api.get('summary')
end
trash() click to toggle source

@return [Wavefront::Response] all alerts in the trash.

# File lib/wavefront-sdk/alert.rb, line 264
def trash
  alerts_in_state(:trash)
end
undelete(id) click to toggle source

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

@param id [String] ID of the alert @return [Wavefront::Response]

# File lib/wavefront-sdk/alert.rb, line 178
def undelete(id)
  wf_alert_id?(id)
  api.post([id, 'undelete'].uri_concat)
end
uninstall(id) click to toggle source

POST /api/v2/alert/{id}/uninstall Hide a specific integration alert

# File lib/wavefront-sdk/alert.rb, line 186
def uninstall(id)
  wf_alert_id?(id)
  api.post([id, 'uninstall'].uri_concat, nil)
end
unsnooze(id) click to toggle source

POST /api/v2/alert/id/unsnooze Unsnooze a specific alert.

@param id [String] ID of the alert @return [Wavefront::Response]

# File lib/wavefront-sdk/alert.rb, line 197
def unsnooze(id)
  wf_alert_id?(id)
  api.post([id, 'unsnooze'].uri_concat)
end
update(id, body, modify = true) click to toggle source

PUT /api/v2/alert/id Update a specific alert.

@param id [String] a Wavefront alert ID @param body [Hash] key-value hash of the parameters you wish

to change

@param modify [true, false] 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.

@return [Wavefront::Response]

# File lib/wavefront-sdk/alert.rb, line 105
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() click to toggle source
# 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) click to toggle source
# File lib/wavefront-sdk/alert.rb, line 168
def valid_id?(id)
  wf_alert_id?(id)
end
versions(id) click to toggle source

Gets all the versions of the given alert @param id [String] ID of the alert @reutrn [Wavefront::Resonse] where items is an array of integers

# File lib/wavefront-sdk/alert.rb, line 83
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