Class: Wavefront::Events

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/wavefront/events.rb

Overview

These methods expect to be called with a hash whose keys are as defined in the Wavefront API Console. That is, ‘n’ as ‘name for the event’, ‘s’ as ‘start time for the event’ and so-on.

Constant Summary collapse

DEFAULT_PATH =
'/api/events/'

Constants included from Constants

Constants::ALERT_FORMATS, Constants::DEFAULT_ALERT_FORMAT, Constants::DEFAULT_FORMAT, Constants::DEFAULT_HOST, Constants::DEFAULT_OBSOLETE_METRICS, Constants::DEFAULT_PERIOD_SECONDS, Constants::DEFAULT_PREFIX_LENGTH, Constants::DEFAULT_STRICT, Constants::EVENT_LEVELS, Constants::EVENT_STATE_DIR, Constants::FORMATS, Constants::GRANULARITIES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Events

Returns a new instance of Events.



26
27
28
29
30
# File 'lib/wavefront/events.rb', line 26

def initialize(token)
  @headers = {
    'X-AUTH-TOKEN': token,
  }
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



24
25
26
# File 'lib/wavefront/events.rb', line 24

def headers
  @headers
end

Instance Method Details

#close(payload = {}, options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/wavefront/events.rb', line 51

def close(payload = {}, options = {})
  options[:host] ||= DEFAULT_HOST
  options[:path] ||= DEFAULT_PATH

  # This request seems to need the data as a query string. I was
  # getting a 500 when I posted a hash. A map will do the
  # needful.

  uri = URI::HTTPS.build(
    host:  options[:host],
    path:  options[:path] + 'close',

  )

  RestClient.post(uri.to_s, mk_qs(payload), headers)
end

#create(payload = {}, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wavefront/events.rb', line 32

def create(payload = {}, options = {})
  options[:host] ||= DEFAULT_HOST
  options[:path] ||= DEFAULT_PATH

  uri = URI::HTTPS.build(
    host:  options[:host],
    path:  options[:path],
  )

  # It seems that posting the hash means the 'host' data is
  # lost. Making a query string works though, so let's do that.
  #
  hosts = payload[:h]
  payload.delete(:h)
  query = mk_qs(payload)
  hosts.each { |host| query.<< "&h=#{host}" }
  RestClient.post(uri.to_s, query, headers)
end