Class: Wavefront::Alert

Inherits:
Base
  • Object
show all
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 Base

#api_base, #conn, #debug, #logger, #net, #noop, #opts, #verbose

Instance Method Summary collapse

Methods inherited from Base

#api_delete, #api_get, #api_post, #api_put, #hash_for_update, #initialize, #log, #mk_conn, #respond, #time_to_ms

Methods included from Mixins

#parse_time

Methods included from Validators

#wf_alert_id?, #wf_alert_severity?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_ms_ts?, #wf_name?, #wf_point?, #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_value?, #wf_version?, #wf_webhook_id?

Constructor Details

This class inherits a constructor from Wavefront::Base

Instance Method Details

#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)


33
34
35
36
# File 'lib/wavefront-sdk/alert.rb', line 33

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:



48
49
50
51
# File 'lib/wavefront-sdk/alert.rb', line 48

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:



62
63
64
65
66
67
68
# File 'lib/wavefront-sdk/alert.rb', line 62

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

#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:



97
98
99
100
101
102
103
104
# File 'lib/wavefront-sdk/alert.rb', line 97

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

#list(offset = 0, limit = 100) ⇒ Hash

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:



21
22
23
# File 'lib/wavefront-sdk/alert.rb', line 21

def list(offset = 0, limit = 100)
  api_get('', { offset: offset, limit: limit })
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:



114
115
116
117
118
# File 'lib/wavefront-sdk/alert.rb', line 114

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

#summaryWavefront::Response

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

Returns:



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

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.

Parameters:

  • id (String)

    ID of the alert

  • tag (String)

    tag to set.

Returns:



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

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.

Parameters:

  • id (String)

    ID of the alert

  • tag (String)

    tag to delete

Returns:



152
153
154
155
156
# File 'lib/wavefront-sdk/alert.rb', line 152

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.

Parameters:

  • id (String)

    ID of the alert

  • tags (Array)

    list of tags to set.

Returns:



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

def tag_set(id, tags)
  wf_alert_id?(id)
  tags = Array(tags)
  tags.each { |t| wf_string?(t) }
  api_post([id, 'tag'].uri_concat, tags.to_json, 'application/json')
end

#tags(id) ⇒ Wavefront::Response

GET /api/v2/alert/id/tag Get all tags associated with a specific alert.

Parameters:

  • id (String)

    ID of the alert

Returns:



126
127
128
129
# File 'lib/wavefront-sdk/alert.rb', line 126

def tags(id)
  wf_alert_id?(id)
  api_get([id, 'tag'].uri_concat)
end

#undelete(id) ⇒ Wavefront::Response

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

Parameters:

  • id (String)

    ID of the alert

Returns:



177
178
179
180
# File 'lib/wavefront-sdk/alert.rb', line 177

def undelete(id)
  wf_alert_id?(id)
  api_post([id, 'undelete'].uri_concat)
end

#unsnooze(id) ⇒ Wavefront::Response

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

Parameters:

  • id (String)

    ID of the alert

Returns:



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

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)


81
82
83
84
85
86
87
88
89
# File 'lib/wavefront-sdk/alert.rb', line 81

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



9
10
11
12
# File 'lib/wavefront-sdk/alert.rb', line 9

def update_keys
  %i(id name target condition displayExpression minutes
     resolveAfterMinutes severity additionalInformation)
end