dogapi-demo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.tailor +106 -0
  5. data/.travis.yml +8 -0
  6. data/CHANGELOG.md +157 -0
  7. data/Gemfile +16 -0
  8. data/LICENSE +25 -0
  9. data/README.rdoc +143 -0
  10. data/Rakefile +50 -0
  11. data/dogapi-demo.gemspec +32 -0
  12. data/examples/Capfile +19 -0
  13. data/examples/custom_event.rb +37 -0
  14. data/examples/custom_metric.rb +35 -0
  15. data/lib/capistrano/README.md +13 -0
  16. data/lib/capistrano/datadog.rb +125 -0
  17. data/lib/capistrano/datadog/v2.rb +74 -0
  18. data/lib/capistrano/datadog/v3.rb +64 -0
  19. data/lib/dogapi-demo.rb +5 -0
  20. data/lib/dogapi-demo/common.rb +168 -0
  21. data/lib/dogapi-demo/event.rb +129 -0
  22. data/lib/dogapi-demo/facade.rb +475 -0
  23. data/lib/dogapi-demo/metric.rb +34 -0
  24. data/lib/dogapi-demo/v1.rb +13 -0
  25. data/lib/dogapi-demo/v1/alert.rb +112 -0
  26. data/lib/dogapi-demo/v1/comment.rb +62 -0
  27. data/lib/dogapi-demo/v1/dash.rb +94 -0
  28. data/lib/dogapi-demo/v1/embed.rb +106 -0
  29. data/lib/dogapi-demo/v1/event.rb +101 -0
  30. data/lib/dogapi-demo/v1/metric.rb +118 -0
  31. data/lib/dogapi-demo/v1/monitor.rb +264 -0
  32. data/lib/dogapi-demo/v1/screenboard.rb +110 -0
  33. data/lib/dogapi-demo/v1/search.rb +27 -0
  34. data/lib/dogapi-demo/v1/service_check.rb +32 -0
  35. data/lib/dogapi-demo/v1/snapshot.rb +30 -0
  36. data/lib/dogapi-demo/v1/tag.rb +141 -0
  37. data/lib/dogapi-demo/v1/user.rb +113 -0
  38. data/lib/dogapi-demo/version.rb +3 -0
  39. data/spec/alerts_spec.rb +33 -0
  40. data/spec/common_spec.rb +37 -0
  41. data/spec/facade_spec.rb +166 -0
  42. data/spec/spec_helper.rb +30 -0
  43. data/spec/support/cassettes/Alerts/create/returns_HTTP_code_200.yml +114 -0
  44. data/spec/support/cassettes/Alerts/create/returns_a_valid_event_ID.yml +114 -0
  45. data/spec/support/cassettes/Alerts/create/returns_the_same_query_as_sent.yml +114 -0
  46. data/spec/support/cassettes/Facade/Events/emits_aggregate_events.yml +193 -0
  47. data/spec/support/cassettes/Facade/Events/emits_events_and_retrieves_them.yml +100 -0
  48. data/spec/support/cassettes/Facade/Events/emits_events_with_specified_priority.yml +98 -0
  49. data/spec/support/cassettes/Facade/Tags/adds_updates_and_detaches_tags.yml +442 -0
  50. data/tests/test_alerts.rb +38 -0
  51. data/tests/test_base.rb +30 -0
  52. data/tests/test_client.rb +23 -0
  53. data/tests/test_comments.rb +39 -0
  54. data/tests/test_dashes.rb +85 -0
  55. data/tests/test_embed.rb +194 -0
  56. data/tests/test_monitors.rb +192 -0
  57. data/tests/test_screenboard.rb +90 -0
  58. data/tests/test_search.rb +20 -0
  59. data/tests/test_snapshot.rb +28 -0
  60. data/tests/test_users.rb +65 -0
  61. metadata +178 -0
@@ -0,0 +1,5 @@
1
+ require 'dogapi-demo/common'
2
+ require 'dogapi-demo/facade'
3
+ require 'dogapi-demo/event'
4
+ require 'dogapi-demo/metric'
5
+ require 'dogapi-demo/version'
@@ -0,0 +1,168 @@
1
+ require 'cgi'
2
+ require 'net/https'
3
+ require 'pp'
4
+ require 'socket'
5
+ require 'uri'
6
+
7
+ require 'rubygems'
8
+ require 'multi_json'
9
+
10
+ module DogapiDemo
11
+
12
+ # Metadata class to hold the scope of an API call
13
+ class Scope
14
+ attr_reader :host, :device
15
+ def initialize(host=nil, device=nil)
16
+ @host = host
17
+ @device = device
18
+ end
19
+ end
20
+
21
+ # <b>DEPRECATED:</b> Going forward, use the newer APIService.
22
+ class Service
23
+ # <b>DEPRECATED:</b> Going forward, use the newer APIService.
24
+ def initialize(api_key, api_host=DogapiDemo.find_datadog_host)
25
+ @api_key = api_key
26
+ @host = api_host
27
+ end
28
+
29
+ # <b>DEPRECATED:</b> Going forward, use the newer APIService.
30
+ def connect
31
+ warn "[DEPRECATION] DogapiDemo::Service has been deprecated in favor of the newer V1 services"
32
+ uri = URI.parse(@host)
33
+ session = Net::HTTP.new(uri.host, uri.port)
34
+ if 'https' == uri.scheme
35
+ session.use_ssl = true
36
+ end
37
+ session.start do |conn|
38
+ yield(conn)
39
+ end
40
+ end
41
+
42
+ # <b>DEPRECATED:</b> Going forward, use the newer APIService.
43
+ def request(method, url, params)
44
+ warn "[DEPRECATION] DogapiDemo::Service has been deprecated in favor of the newer V1 services"
45
+ if !params.has_key? :api_key
46
+ params[:api_key] = @api_key
47
+ end
48
+
49
+ resp_obj = nil
50
+ connect do |conn|
51
+ req = method.new(url)
52
+ req.set_form_data params
53
+ resp = conn.request(req)
54
+ begin
55
+ resp_obj = MultiJson.load(resp.body)
56
+ rescue
57
+ raise 'Invalid JSON Response: ' + resp.body
58
+ end
59
+
60
+ if resp_obj.has_key? 'error'
61
+ request_string = params.pretty_inspect
62
+ error_string = resp_obj['error']
63
+ raise "Failed request\n#{request_string}#{error_string}"
64
+ end
65
+ end
66
+ resp_obj
67
+ end
68
+ end
69
+
70
+ # Superclass that deals with the details of communicating with the DataDog API
71
+ class APIService
72
+ def initialize(api_key, application_key, silent=true, timeout=nil)
73
+ @api_key = api_key
74
+ @application_key = application_key
75
+ @api_host = DogapiDemo.find_datadog_host()
76
+ @silent = silent
77
+ @timeout = timeout || 5
78
+ end
79
+
80
+ # Manages the HTTP connection
81
+ def connect
82
+ connection = Net::HTTP
83
+
84
+ # After ruby 2.0 Net::HTTP looks for the env variable but not ruby 1.9
85
+ if RUBY_VERSION < "2.0.0"
86
+ proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"] || ENV["HTTP_PROXY"] || ENV["http_proxy"]
87
+ if proxy
88
+ proxy_uri = URI.parse(proxy)
89
+ connection = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
90
+ end
91
+ end
92
+
93
+ uri = URI.parse(@api_host)
94
+ session = connection.new(uri.host, uri.port)
95
+ session.open_timeout = @timeout
96
+ session.use_ssl = uri.scheme == 'https'
97
+ session.start do |conn|
98
+ conn.read_timeout = @timeout
99
+ yield(conn)
100
+ end
101
+ end
102
+
103
+ def suppress_error_if_silent(e)
104
+ if @silent
105
+ warn e
106
+ return -1, {}
107
+ else
108
+ raise e
109
+ end
110
+ end
111
+
112
+ # Prepares the request and handles the response
113
+ #
114
+ # +method+ is an implementation of Net::HTTP::Request (e.g. Net::HTTP::Post)
115
+ #
116
+ # +params+ is a Hash that will be converted to request parameters
117
+ def request(method, url, params, body, send_json)
118
+ resp_obj = nil
119
+ resp = nil
120
+ connect do |conn|
121
+ if params and params.size > 0
122
+ qs_params = params.map { |k, v| k.to_s + "=" + v.to_s }
123
+ qs = "?" + qs_params.join("&")
124
+ url = url + qs
125
+ end
126
+
127
+ req = method.new(url)
128
+
129
+ if send_json
130
+ req.content_type = 'application/json'
131
+ req.body = MultiJson.dump(body)
132
+ end
133
+
134
+ resp = conn.request(req)
135
+ resp_str = resp.body
136
+
137
+ if resp.code != 204 and resp.body != '' and resp.body != 'null' and resp.body != nil
138
+ begin
139
+ resp_obj = MultiJson.load(resp.body)
140
+ rescue
141
+ raise 'Invalid JSON Response: ' + resp.body
142
+ end
143
+ else
144
+ resp_obj = {}
145
+ end
146
+ end
147
+ return resp.code, resp_obj
148
+ end
149
+ end
150
+
151
+ def DogapiDemo.find_datadog_host
152
+ # allow env-based overriding, useful for tests
153
+ "https://app.datadoghq.com"
154
+ end
155
+
156
+ # Memoize the hostname as a module variable
157
+ @@hostname = nil
158
+
159
+ def DogapiDemo.find_localhost
160
+ begin
161
+ # prefer hostname -f over Socket.gethostname
162
+ @@hostname ||= %x[hostname -f].strip
163
+ rescue
164
+ raise "Cannot determine local hostname via hostname -f"
165
+ end
166
+ end
167
+
168
+ end
@@ -0,0 +1,129 @@
1
+ require 'net/http'
2
+
3
+ require 'rubygems'
4
+ require 'multi_json'
5
+
6
+ module DogapiDemo
7
+
8
+ # Metadata class for storing the details of an event
9
+ class Event
10
+ attr_reader :date_happened,
11
+ :msg_title,
12
+ :msg_text,
13
+ :priority,
14
+ :parent,
15
+ :tags,
16
+ :aggregation_key
17
+
18
+ # Optional arguments:
19
+ # :date_happened => time in seconds since the epoch (defaults to now)
20
+ # :msg_title => String
21
+ # :priority => String
22
+ # :parent => event ID (integer)
23
+ # :tags => array of Strings
24
+ # :event_object => String
25
+ # :alert_type => 'success', 'error'
26
+ # :event_type => String
27
+ # :source_type_name => String
28
+ # :aggregation_key => String
29
+ def initialize(msg_text, options = {})
30
+ defaults = {
31
+ :date_happened => Time.now.to_i,
32
+ :msg_title => '',
33
+ :priority => "normal",
34
+ :parent => nil,
35
+ :tags => [],
36
+ :aggregation_key => nil
37
+ }
38
+ options = defaults.merge(options)
39
+
40
+ @msg_text = msg_text
41
+ @date_happened = options[:date_happened]
42
+ @msg_title = options[:msg_title]
43
+ @priority = options[:priority]
44
+ @parent = options[:parent]
45
+ @tags = options[:tags]
46
+ @aggregation_key = options[:event_object] || options[:aggregation_key]
47
+ @alert_type = options[:alert_type]
48
+ @event_type = options[:event_type]
49
+ @source_type_name = options[:source_type_name]
50
+ end
51
+
52
+ # Copy and pasted from the internets
53
+ # http://stackoverflow.com/a/5031637/25276
54
+ def to_hash
55
+ hash = {}
56
+ instance_variables.each { |var| hash[var.to_s[1..-1].to_sym] = instance_variable_get(var) }
57
+ hash
58
+ end
59
+ end
60
+
61
+ # <b>DEPRECATED:</b> Going forward, use the V1 services. This legacy service will be
62
+ # removed in an upcoming release.
63
+ class EventService < DogapiDemo::Service
64
+
65
+ API_VERSION = "1.0.0"
66
+ MAX_BODY_LENGTH = 4000
67
+ MAX_TITLE_LENGTH = 100
68
+
69
+ # <b>DEPRECATED:</b> Going forward, use the V1 services. This legacy service will be
70
+ # removed in an upcoming release.
71
+ def submit(api_key, event, scope=nil, source_type=nil)
72
+ warn "[DEPRECATION] DogapiDemo::EventService.submit() has been deprecated in favor of the newer V1 services"
73
+ scope = scope || DogapiDemo::Scope.new()
74
+ params = {
75
+ :api_key => api_key,
76
+ :api_version => API_VERSION,
77
+
78
+ :host => scope.host,
79
+ :device => scope.device,
80
+
81
+ :metric => event.metric,
82
+ :date_detected => event.date_detected,
83
+ :date_happened => event.date_happened,
84
+ :alert_type => event.alert_type,
85
+ :event_type => event.event_type,
86
+ :event_object => event.event_object,
87
+ :msg_title => event.msg_title[0..MAX_TITLE_LENGTH - 1],
88
+ :msg_text => event.msg_text[0..MAX_BODY_LENGTH - 1],
89
+ :json_payload => event.json_payload,
90
+ }
91
+
92
+ if source_type
93
+ params[:source_type] = source_type
94
+ end
95
+
96
+ request Net::HTTP::Post, '/event/submit', params
97
+ end
98
+
99
+ # <b>DEPRECATED:</b> Going forward, use the V1 services. This legacy service will be
100
+ # removed in an upcoming release.
101
+ def start(api_key, event, scope, source_type=nil)
102
+ warn "[DEPRECATION] DogapiDemo::EventService.start() has been deprecated in favor of the newer V1 services"
103
+ response = submit api_key, event, scope, source_type
104
+ success = nil
105
+
106
+ begin
107
+ yield response
108
+ rescue
109
+ success = false
110
+ raise
111
+ else
112
+ success = true
113
+ ensure
114
+ return finish api_key, response['id'], success
115
+ end
116
+ end
117
+
118
+ private
119
+
120
+ def finish(api_key, event_id, successful=nil)
121
+ params = {
122
+ :api_key => api_key,
123
+ :event_id => event_id
124
+ }
125
+
126
+ request Net::HTTP::Post, '/event/ended', params
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,475 @@
1
+ require 'time'
2
+ require 'dogapi-demo/v1'
3
+
4
+ module DogapiDemo
5
+
6
+ # A simple DogAPI client
7
+ #
8
+ # See DogapiDemo::V1 for the thick underlying clients
9
+ #
10
+ # Class methods return a tuple of (+response_code+, +response_body+). Unless otherwise noted, the response body is deserialized JSON. Up-to-date information about the JSON object structure is available in the HTTP API documentation, here[https://github.com/DataDog/dogapi-demo/wiki].
11
+ class Client
12
+
13
+ # Create a new Client optionally specifying a default host and device
14
+ def initialize(api_key, application_key=nil, host=nil, device=nil, silent=true, timeout=nil)
15
+
16
+ if api_key
17
+ @api_key = api_key
18
+ else
19
+ raise 'Please provide an API key to submit your data'
20
+ end
21
+
22
+ @application_key = application_key
23
+
24
+ @datadog_host = DogapiDemo.find_datadog_host()
25
+
26
+ @host = host ||= DogapiDemo.find_localhost()
27
+
28
+ @device = device
29
+
30
+ # FIXME: refactor to avoid all this code duplication
31
+ @metric_svc = DogapiDemo::V1::MetricService.new(@api_key, @application_key, silent, timeout)
32
+ @event_svc = DogapiDemo::V1::EventService.new(@api_key, @application_key, silent, timeout)
33
+ @tag_svc = DogapiDemo::V1::TagService.new(@api_key, @application_key, silent, timeout)
34
+ @comment_svc = DogapiDemo::V1::CommentService.new(@api_key, @application_key, silent, timeout)
35
+ @search_svc = DogapiDemo::V1::SearchService.new(@api_key, @application_key, silent, timeout)
36
+ @dash_service = DogapiDemo::V1::DashService.new(@api_key, @application_key, silent, timeout)
37
+ @alert_svc = DogapiDemo::V1::AlertService.new(@api_key, @application_key, silent, timeout)
38
+ @user_svc = DogapiDemo::V1::UserService.new(@api_key, @application_key, silent, timeout)
39
+ @snapshot_svc = DogapiDemo::V1::SnapshotService.new(@api_key, @application_key, silent, timeout)
40
+ @embed_svc = DogapiDemo::V1::EmbedService.new(@api_key, @application_key, silent, timeout)
41
+ @screenboard_svc = DogapiDemo::V1::ScreenboardService.new(@api_key, @application_key, silent, timeout)
42
+ @monitor_svc = DogapiDemo::V1::MonitorService.new(@api_key, @application_key, silent, timeout)
43
+ @service_check_svc = DogapiDemo::V1::ServiceCheckService.new(@api_key, @application_key, silent, timeout)
44
+ @legacy_event_svc = DogapiDemo::EventService.new(@datadog_host)
45
+ end
46
+
47
+ #
48
+ # METRICS
49
+
50
+ # Record a single point of metric data
51
+ #
52
+ # Optional arguments:
53
+ # :timestamp => Ruby stdlib Time
54
+ # :host => String
55
+ # :device => String
56
+ # :options => Map
57
+ #
58
+ # options[:type] = "counter" to specify a counter metric
59
+ # options[:tags] = ["tag1", "tag2"] to tag the point
60
+ def emit_point(metric, value, options = {})
61
+ defaults = { :timestamp => Time.now }
62
+ options = defaults.merge(options)
63
+
64
+ self.emit_points(
65
+ metric,
66
+ [[options[:timestamp], value]],
67
+ options
68
+ )
69
+ end
70
+
71
+ # Record a set of points of metric data
72
+ #
73
+ # +points+ is an array of <tt>[Time, value]</tt> doubles
74
+ #
75
+ # Optional arguments:
76
+ # :host => String
77
+ # :device => String
78
+ # :options => Map
79
+ #
80
+ # options[:type] = "counter" to specify a counter metric
81
+ # options[:tags] = ["tag1", "tag2"] to tag the point
82
+ def emit_points(metric, points, options = {})
83
+ scope = override_scope options
84
+
85
+ points.each do |p|
86
+ p[0].kind_of? Time or raise "Not a Time"
87
+ p[0] = p[0].to_i
88
+ p[1] = p[1].to_f # TODO: stupid to_f will never raise an exception
89
+ end
90
+
91
+ @metric_svc.submit(metric, points, scope, options)
92
+ end
93
+
94
+ # Get a set of points by query between from and to
95
+ #
96
+ # +from+ The seconds since the unix epoch <tt>[Time, Integer]</tt>
97
+ # +to+ The seconds since the unix epoch <tt>[Time, Integer]</tt>
98
+ # +query+ The query string <tt>[String]</tt>
99
+ #
100
+ def get_points(query, from, to)
101
+ @metric_svc.get(query, from, to)
102
+ end
103
+
104
+ def batch_metrics()
105
+ @metric_svc.switch_to_batched
106
+ begin
107
+ yield
108
+ @metric_svc.flush_buffer # flush_buffer should returns the response from last API call
109
+ ensure
110
+ @metric_svc.switch_to_single
111
+ end
112
+ end
113
+
114
+ #
115
+ # EVENTS
116
+
117
+ # Record an event
118
+ #
119
+ # Optional arguments:
120
+ # :host => String
121
+ # :device => String
122
+ def emit_event(event, options = {})
123
+ scope = override_scope options
124
+
125
+ @event_svc.post(event, scope)
126
+ end
127
+
128
+ # Get the details of an event
129
+ #
130
+ # +id+ of the event to get
131
+ def get_event(id)
132
+ @event_svc.get(id)
133
+ end
134
+
135
+ # Get an optionally filtered event stream
136
+ #
137
+ # +start+ is a Time object for when to start the stream
138
+ #
139
+ # +stop+ is a Time object for when to end the stream
140
+ #
141
+ # Optional arguments:
142
+ # :priority => "normal" or "low"
143
+ # :sources => String, see https://github.com/DataDog/dogapi-demo/wiki/Event for a current list of sources
144
+ # :tags => Array of Strings
145
+ def stream(start, stop, options = {})
146
+ @event_svc.stream(start, stop, options)
147
+ end
148
+
149
+ # <b>DEPRECATED:</b> Recording events with a duration has been deprecated.
150
+ # The functionality will be removed in a later release.
151
+ def start_event(event, options = {})
152
+ warn "[DEPRECATION] DogapiDemo::Client.start_event() is deprecated. Use `emit_event` instead."
153
+ defaults = { :source_type => nil }
154
+ options = defaults.merge(options)
155
+
156
+ scope = override_scope options
157
+
158
+ @legacy_event_svc.start(@api_key, event, scope, options[:source_type]) do
159
+ yield
160
+ end
161
+ end
162
+
163
+ #
164
+ # COMMENTS
165
+ #
166
+
167
+ # Post a comment
168
+ def comment(message, options = {})
169
+ @comment_svc.comment(message, options)
170
+ end
171
+
172
+ # Post a comment
173
+ def update_comment(comment_id, options = {})
174
+ @comment_svc.update_comment(comment_id, options)
175
+ end
176
+
177
+ def delete_comment(comment_id)
178
+ @comment_svc.delete_comment(comment_id)
179
+ end
180
+
181
+ #
182
+ # SEARCH
183
+ #
184
+
185
+ # Run the given search query.
186
+ def search(query)
187
+ @search_svc.search query
188
+ end
189
+
190
+
191
+ #
192
+ # TAGS
193
+ #
194
+
195
+ # Get all tags and their associated hosts at your org
196
+ def all_tags(source = nil)
197
+ @tag_svc.get_all(source)
198
+ end
199
+
200
+ # Get all tags for the given host
201
+ #
202
+ # +host_id+ can be the host's numeric id or string name
203
+ def host_tags(host_id, source = nil, by_source = false)
204
+ @tag_svc.get(host_id, source, by_source)
205
+ end
206
+
207
+ # Add the tags to the given host
208
+ #
209
+ # +host_id+ can be the host's numeric id or string name
210
+ #
211
+ # +tags+ is and Array of Strings
212
+ def add_tags(host_id, tags, source = nil)
213
+ @tag_svc.add(host_id, tags, source)
214
+ end
215
+
216
+ # Replace the tags on the given host
217
+ #
218
+ # +host_id+ can be the host's numeric id or string name
219
+ #
220
+ # +tags+ is and Array of Strings
221
+ def update_tags(host_id, tags, source = nil)
222
+ @tag_svc.update(host_id, tags, source)
223
+ end
224
+
225
+ # <b>DEPRECATED:</b> Spelling mistake temporarily preserved as an alias.
226
+ def detatch_tags(host_id)
227
+ warn "[DEPRECATION] DogapiDemo::Client.detatch() is deprecated. Use `detach` instead."
228
+ detach_tags(host_id)
229
+ end
230
+
231
+ # Remove all tags from the given host
232
+ #
233
+ # +host_id+ can be the host's numeric id or string name
234
+ def detach_tags(host_id, source = nil)
235
+ @tag_svc.detach(host_id, source)
236
+ end
237
+
238
+ #
239
+ # DASHES
240
+ #
241
+
242
+ # Create a dashboard.
243
+ def create_dashboard(title, description, graphs, template_variables = nil)
244
+ @dash_service.create_dashboard(title, description, graphs, template_variables)
245
+ end
246
+
247
+ # Update a dashboard.
248
+ def update_dashboard(dash_id, title, description, graphs, template_variables = nil)
249
+ @dash_service.update_dashboard(dash_id, title, description, graphs, template_variables)
250
+ end
251
+
252
+ # Fetch the given dashboard.
253
+ def get_dashboard(dash_id)
254
+ @dash_service.get_dashboard(dash_id)
255
+ end
256
+
257
+ # Fetch all of the dashboards.
258
+ def get_dashboards
259
+ @dash_service.get_dashboards
260
+ end
261
+
262
+ # Delete the given dashboard.
263
+ def delete_dashboard(dash_id)
264
+ @dash_service.delete_dashboard(dash_id)
265
+ end
266
+
267
+ #
268
+ # ALERTS
269
+ #
270
+
271
+ def alert(query, options = {})
272
+ @alert_svc.alert(query, options)
273
+ end
274
+
275
+ def update_alert(alert_id, query, options = {})
276
+ @alert_svc.update_alert(alert_id, query, options)
277
+ end
278
+
279
+ def get_alert(alert_id)
280
+ @alert_svc.get_alert(alert_id)
281
+ end
282
+
283
+ def delete_alert(alert_id)
284
+ @alert_svc.delete_alert(alert_id)
285
+ end
286
+
287
+ def get_all_alerts()
288
+ @alert_svc.get_all_alerts()
289
+ end
290
+
291
+ def mute_alerts()
292
+ @alert_svc.mute_alerts()
293
+ end
294
+
295
+ def unmute_alerts()
296
+ @alert_svc.unmute_alerts()
297
+ end
298
+
299
+ # User invite
300
+ def invite(emails, options = {})
301
+ @user_svc.invite(emails, options)
302
+ end
303
+
304
+ def create_user(description = {})
305
+ @user_svc.create_user(description)
306
+ end
307
+
308
+ def get_all_users()
309
+ @user_svc.get_all_users()
310
+ end
311
+
312
+ def get_user(handle)
313
+ @user_svc.get_user(handle)
314
+ end
315
+
316
+ def update_user(handle, description = {})
317
+ @user_svc.update_user(handle, description)
318
+ end
319
+
320
+ def disable_user(handle)
321
+ @user_svc.disable_user(handle)
322
+ end
323
+
324
+ # Graph snapshot
325
+ def graph_snapshot(metric_query, start_ts, end_ts, event_query = nil)
326
+ @snapshot_svc.snapshot(metric_query, start_ts, end_ts, event_query)
327
+ end
328
+
329
+ #
330
+ # EMBEDS
331
+ #
332
+ def get_all_embeds()
333
+ @embed_svc.get_all_embeds()
334
+ end
335
+
336
+ def get_embed(embed_id, description= {})
337
+ @embed_svc.get_embed(embed_id, description)
338
+ end
339
+
340
+ def create_embed(graph_json, description= {})
341
+ @embed_svc.create_embed(graph_json, description)
342
+ end
343
+
344
+ def enable_embed(embed_id)
345
+ @embed_svc.enable_embed(embed_id)
346
+ end
347
+
348
+ def revoke_embed(embed_id)
349
+ @embed_svc.revoke_embed(embed_id)
350
+ end
351
+
352
+ #
353
+ # SCREENBOARD
354
+ #
355
+ def create_screenboard(description)
356
+ @screenboard_svc.create_screenboard(description)
357
+ end
358
+
359
+ def update_screenboard(board_id, description)
360
+ @screenboard_svc.update_screenboard(board_id, description)
361
+ end
362
+
363
+ def get_screenboard(board_id)
364
+ @screenboard_svc.get_screenboard(board_id)
365
+ end
366
+
367
+ def get_all_screenboards()
368
+ @screenboard_svc.get_all_screenboards()
369
+ end
370
+
371
+ def delete_screenboard(board_id)
372
+ @screenboard_svc.delete_screenboard(board_id)
373
+ end
374
+
375
+ def share_screenboard(board_id)
376
+ @screenboard_svc.share_screenboard(board_id)
377
+ end
378
+
379
+ def revoke_screenboard(board_id)
380
+ @screenboard_svc.revoke_screenboard(board_id)
381
+ end
382
+
383
+ #
384
+ # MONITORS
385
+ #
386
+
387
+ def monitor(type, query, options = {})
388
+ @monitor_svc.monitor(type, query, options)
389
+ end
390
+
391
+ def update_monitor(monitor_id, query, options = {})
392
+ @monitor_svc.update_monitor(monitor_id, query, options)
393
+ end
394
+
395
+ def get_monitor(monitor_id, options = {})
396
+ @monitor_svc.get_monitor(monitor_id, options)
397
+ end
398
+
399
+ def delete_monitor(monitor_id)
400
+ @monitor_svc.delete_monitor(monitor_id)
401
+ end
402
+
403
+ def get_all_monitors(options = {})
404
+ @monitor_svc.get_all_monitors(options)
405
+ end
406
+
407
+ def mute_monitors()
408
+ @monitor_svc.mute_monitors()
409
+ end
410
+
411
+ def unmute_monitors()
412
+ @monitor_svc.unmute_monitors()
413
+ end
414
+
415
+ def mute_monitor(monitor_id, options = {})
416
+ @monitor_svc.mute_monitor(monitor_id, options)
417
+ end
418
+
419
+ def unmute_monitor(monitor_id, options = {})
420
+ @monitor_svc.unmute_monitor(monitor_id, options)
421
+ end
422
+
423
+ #
424
+ # MONITOR DOWNTIME
425
+ #
426
+
427
+ def schedule_downtime(scope, options = {})
428
+ @monitor_svc.schedule_downtime(scope, options)
429
+ end
430
+
431
+ def update_downtime(downtime_id, options = {})
432
+ @monitor_svc.update_downtime(downtime_id, options)
433
+ end
434
+
435
+ def get_downtime(downtime_id)
436
+ @monitor_svc.get_downtime(downtime_id)
437
+ end
438
+
439
+ def cancel_downtime(downtime_id)
440
+ @monitor_svc.cancel_downtime(downtime_id)
441
+ end
442
+
443
+ def get_all_downtimes(options = {})
444
+ @monitor_svc.get_all_downtimes(options)
445
+ end
446
+
447
+ #
448
+ # HOST MUTING
449
+ #
450
+
451
+ def mute_host(hostname, options = {})
452
+ @monitor_svc.mute_host(hostname, options)
453
+ end
454
+
455
+ def unmute_host(hostname)
456
+ @monitor_svc.unmute_host(hostname)
457
+ end
458
+
459
+ #
460
+ # SERVICE CHECKS
461
+ #
462
+
463
+ def service_check(check, host, status, options = {})
464
+ @service_check_svc.service_check(check, host, status, options)
465
+ end
466
+
467
+ private
468
+
469
+ def override_scope(options= {})
470
+ defaults = { :host => @host, :device => @device }
471
+ options = defaults.merge(options)
472
+ Scope.new(options[:host], options[:device])
473
+ end
474
+ end
475
+ end