Class: Wavefront::Events
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_INFILE_FORMAT, Constants::DEFAULT_OBSOLETE_METRICS, Constants::DEFAULT_PERIOD_SECONDS, Constants::DEFAULT_PREFIX_LENGTH, Constants::DEFAULT_PROXY, Constants::DEFAULT_PROXY_PORT, Constants::DEFAULT_STRICT, Constants::EVENT_LEVELS, Constants::EVENT_STATE_DIR, Constants::FORMATS, Constants::GRANULARITIES
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Mixins
#hash_to_qs, #interpolate_schema, #parse_time, #time_to_ms, #uri_concat
Constructor Details
#initialize(token) ⇒ Events
Returns a new instance of Events.
28
29
30
|
# File 'lib/wavefront/events.rb', line 28
def initialize(token)
= { :'X-AUTH-TOKEN' => token }
end
|
Instance Attribute Details
Returns the value of attribute headers.
26
27
28
|
# File 'lib/wavefront/events.rb', line 26
def
end
|
Instance Method Details
#close(payload = {}, options = {}) ⇒ Object
36
37
38
|
# File 'lib/wavefront/events.rb', line 36
def close(payload = {}, options = {})
make_call(close_uri(options), hash_to_qs(payload))
end
|
#close_uri(options = {}) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/wavefront/events.rb', line 83
def close_uri(options = {})
options[:host] ||= DEFAULT_HOST
options[:path] ||= DEFAULT_PATH
URI::HTTPS.build(
host: options[:host],
path: options[:path] + 'close',
)
end
|
#create(payload = {}, options = {}) ⇒ Object
32
33
34
|
# File 'lib/wavefront/events.rb', line 32
def create(payload = {}, options = {})
make_call(create_uri(options), create_qs(payload))
end
|
#create_qs(payload = {}) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/wavefront/events.rb', line 64
def create_qs(payload = {})
if payload[:h].is_a?(Array)
hosts = payload[:h]
elsif payload[:h].is_a?(String)
hosts = [payload[:h]]
else
hosts = []
end
payload.delete(:h)
query = hash_to_qs(payload)
hosts.each { |host| query.<< "&h=#{host}" }
query
end
|
#create_uri(options = {}) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/wavefront/events.rb', line 51
def create_uri(options = {})
options[:host] ||= DEFAULT_HOST
options[:path] ||= DEFAULT_PATH
URI::HTTPS.build(
host: options[:host],
path: options[:path],
)
end
|
#debug(enabled) ⇒ Object
100
101
102
|
# File 'lib/wavefront/events.rb', line 100
def debug(enabled)
RestClient.log = 'stdout' if enabled
end
|
#delete(payload = {}, options = {}) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/wavefront/events.rb', line 40
def delete(payload = {}, options = {})
unless payload.has_key?(:startTime) && payload.has_key?(:name)
raise 'invalid payload'
end
uri = create_uri(path: [DEFAULT_PATH, payload[:startTime],
payload[:name]].join('/').squeeze('/'))
RestClient.delete(uri.to_s, )
end
|
#make_call(uri, query) ⇒ Object
96
97
98
|
# File 'lib/wavefront/events.rb', line 96
def make_call(uri, query)
RestClient.post(uri.to_s, query, )
end
|