Class: Wavefront::Event

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

Overview

View and manage events. Events are identified by their millisecond epoch timestamp.

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 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_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_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

#alert_firing_details(id) ⇒ Wavefront::Response

GET /api/v2/event/id/alertFiringDetails Return details of a particular alert firing, including all the series that fired during the referred alert firing

Parameters:

  • id (String)

    ID of the event

Returns:



127
128
129
130
# File 'lib/wavefront-sdk/event.rb', line 127

def alert_firing_details(id)
  wf_event_id?(id)
  api.get([id, 'alertFiringDetails'].uri_concat)
end

#alert_firings(alert_id, opts = {}) ⇒ Wavefront::Response

GET /api/v2/event/alertFirings Get firings events of an alert within a time range

Parameters:

  • alert_id (String)

    ID of the alert

  • opts (Hash) (defaults to: {})

    containing one or more of earliest_start [Integer] epoch ms timestamp latest_start [Integer] epoch ms timestamp ascending [Bool] limit [Integer]

Returns:



172
173
174
175
176
177
178
179
180
181
# File 'lib/wavefront-sdk/event.rb', line 172

def alert_firings(alert_id, opts = {})
  wf_alert_id?(alert_id)

  api.get('alertFirings',
          { alertId: alert_id,
            earliestStartTimeEpochMillis: opts[:earliest_start] || nil,
            latestStartTimeEpochMillis: opts[:latest_start] || nil,
            limit: opts[:limit] || nil,
            asc: opts[:asc] || true }.compact)
end

#alert_queries_slug(id) ⇒ Wavefront::Response

GET /api/v2/event/id/alertQueriesSlug If the specified event is associated with an alert, returns a slug encoding the queries having to do with that alert firing or resolution

Parameters:

  • id (String)

    ID of the event

Returns:



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

def alert_queries_slug(id)
  wf_event_id?(id)
  api.get([id, 'alertQueriesSlug'].uri_concat)
end

#close(id) ⇒ Object

POST /api/v2/event/id/close Close a specific event.

Parameters:

  • id (String)

    the ID of the event



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

def close(id)
  wf_event_id?(id)
  api.post([id, 'close'].uri_concat)
end

#create(body) ⇒ Wavefront::Response

POST /api/v2/event Create a specific event.

We used to validate keys and provide helpers for time fields. Now ensuring a valid hash is entirely left up to the user. Refer to the Swagger docs for more information.

Parameters:

  • body (Hash)

    description of event

Returns:

Raises:

  • (ArgumentError)


53
54
55
56
57
# File 'lib/wavefront-sdk/event.rb', line 53

def create(body)
  raise ArgumentError unless body.is_a?(Hash)

  api.post('', body, 'application/json')
end

#delete(id) ⇒ Wavefront::Response

DELETE /api/v2/event/id Delete a specific event.

Parameters:

  • id (String)

    ID of the alert

Returns:



65
66
67
68
# File 'lib/wavefront-sdk/event.rb', line 65

def delete(id)
  wf_event_id?(id)
  api.delete(id)
end

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

GET /api/v2/event/id Get a specific event / Get a specific historical version of a specific event.

Parameters:

  • id (String)

    ID of the event

  • version (Integer) (defaults to: nil)

    version of event

Returns:



78
79
80
81
82
83
84
# File 'lib/wavefront-sdk/event.rb', line 78

def describe(id, version = nil)
  wf_event_id?(id)
  wf_version?(version) if version
  fragments = [id]
  fragments += ['history', version] if version
  api.get(fragments.uri_concat)
end

#events(id, opts = {}) ⇒ Wavefront::Response

GET /api/v2/event/id/events List all related events for a specific firing event with a time span of one hour

Parameters:

  • id (String)

    ID of the event

  • opts (Hash) (defaults to: {})

    containing one or more of is_overlapped [Bool] rendering_method [Symbol,String] one of :HOST, :METRIC, :SIMILARITY limit [Integer]

Returns:



153
154
155
156
157
158
159
160
# File 'lib/wavefront-sdk/event.rb', line 153

def events(id, opts = {})
  wf_event_id?(id)

  api.get([id, 'events'].uri_concat,
          { isOverlapped: opts[:is_overlapped] || false,
            renderingMethod: (opts[:rendering_method] || :HOST).to_s,
            limit: opts[:limit] || nil }.compact)
end

#list(from = nil, to = Time.now, limit = 100, cursor = nil) ⇒ Wavefront::Response

GET /api/v2/event List all the events for a customer within a time range.

rubocop:disable Metrics/ParameterLists

Parameters:

  • from (Time, Integer) (defaults to: nil)

    start of time range. The API requires this time as epoch milliseconds, but we will also accept it as a Ruby Time object.

  • to (Time, Integer) (defaults to: Time.now)

    end ot time range. Can be epoch millisecods or a Ruby time. If not supplied, defaults to the current time.

  • cursor (String) (defaults to: nil)

    event from which to start listing

  • limit (Integer) (defaults to: 100)

    the number of events to return

Returns:

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
40
# File 'lib/wavefront-sdk/event.rb', line 32

def list(from = nil, to = Time.now, limit = 100, cursor = nil)
  raise ArgumentError unless from && to

  body = list_body(from, to, limit, cursor)
  wf_event_id?(cursor) if cursor
  wf_ms_ts?(body[:earliestStartTimeEpochMillis])
  wf_ms_ts?(body[:latestStartTimeEpochMillis])
  api.get('', body.cleanse)
end

#update(id, body, modify = true) ⇒ Wavefront::Response

PUT /api/v2/event/id Update a specific event

This method helps you update one or more properties of an event.

Parameters:

  • id (String)

    a Wavefront Event ID

  • body (Hash)

    description of event.

  • modify (Bool) (defaults to: true)

    if this is true, then the existing event object will be fetched and merged with the user-supplied body. The resulting object will be passed to the API. If this is false, the body will be passed through unmodified.

Returns:

Raises:

  • (ArgumentError)


99
100
101
102
103
104
105
106
107
108
# File 'lib/wavefront-sdk/event.rb', line 99

def update(id, body, modify = true)
  wf_event_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



14
15
16
# File 'lib/wavefront-sdk/event.rb', line 14

def update_keys
  %i[id name]
end