Class: Wavefront::Event

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

#close(id) ⇒ Object

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

Parameters:

  • id (String)

    the ID of the event



110
111
112
113
# File 'lib/wavefront-sdk/event.rb', line 110

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)


51
52
53
54
# File 'lib/wavefront-sdk/event.rb', line 51

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:



62
63
64
65
# File 'lib/wavefront-sdk/event.rb', line 62

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:



75
76
77
78
79
80
81
# File 'lib/wavefront-sdk/event.rb', line 75

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

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

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

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: nil)

    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)

    I think this must start with a timestamp.

  • limit (Integer) (defaults to: 100)

    the number of events to return

Returns:

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wavefront-sdk/event.rb', line 26

def list(from = nil, to = nil, limit = 100, cursor = nil)
  raise ArgumentError unless from && to
  from = parse_time(from, true)
  to = parse_time(to, true)
  wf_ms_ts?(from)
  wf_ms_ts?(to)
  wf_event_id?(cursor) if cursor
  raise ArgumentError unless limit.is_a?(Integer)

  api_get('', { earliestStartTimeEpochMillis: from,
                latestStartTimeEpochMillis: to,
                cursor: cursor,
                limit: limit }.select { |_k, v| v })
end

#tag_add(id, tag) ⇒ Wavefront::Response

PUT /api/v2/event/id/tag/tagValue Add a tag to a specific event.

Parameters:

  • id (String)

    ID of the event

  • tag (String)

    tag to set.

Returns:



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

def tag_add(id, tag)
  wf_event_id?(id)
  wf_string?(tag)
  api_put([id, 'tag', tag].uri_concat)
end

#tag_delete(id, tag) ⇒ Wavefront::Response

DELETE /api/v2/event/id/tag/tagValue Remove a tag from a specific event.

Parameters:

  • id (String)

    ID of the event

  • tag (String)

    tag to delete

Returns:



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

def tag_delete(id, tag)
  wf_event_id?(id)
  wf_string?(tag)
  api_delete([id, 'tag', tag].uri_concat)
end

#tag_set(id, tags) ⇒ Wavefront::Response

POST /api/v2/event/id/tag Set all tags associated with a specific event.

Parameters:

  • id (String)

    ID of the event

  • tags (Array)

    list of tags to set.

Returns:



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

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

#tags(id) ⇒ Wavefront::Response

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

Parameters:

  • id (String)

    ID of the event

Returns:



122
123
124
125
# File 'lib/wavefront-sdk/event.rb', line 122

def tags(id)
  wf_event_id?(id)
  api_get([id, 'tag'].uri_concat)
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)


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

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), body), 'application/json')
end

#update_keysObject



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

def update_keys
  %i(startTime endTime name annotations)
end