dogapi 1.22.0 → 1.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -1
  4. data/.rubocop.yml +13 -0
  5. data/.travis.yml +3 -1
  6. data/CHANGELOG.md +16 -1
  7. data/Gemfile +6 -3
  8. data/README.rdoc +1 -1
  9. data/Rakefile +8 -15
  10. data/lib/capistrano/datadog.rb +12 -12
  11. data/lib/capistrano/datadog/v2.rb +5 -5
  12. data/lib/capistrano/datadog/v3.rb +9 -4
  13. data/lib/dogapi/common.rb +43 -39
  14. data/lib/dogapi/event.rb +4 -4
  15. data/lib/dogapi/facade.rb +57 -54
  16. data/lib/dogapi/metric.rb +2 -2
  17. data/lib/dogapi/v1/alert.rb +17 -80
  18. data/lib/dogapi/v1/comment.rb +8 -39
  19. data/lib/dogapi/v1/dash.rb +20 -67
  20. data/lib/dogapi/v1/embed.rb +11 -57
  21. data/lib/dogapi/v1/event.rb +37 -72
  22. data/lib/dogapi/v1/metric.rb +17 -46
  23. data/lib/dogapi/v1/monitor.rb +54 -194
  24. data/lib/dogapi/v1/screenboard.rb +8 -77
  25. data/lib/dogapi/v1/search.rb +5 -11
  26. data/lib/dogapi/v1/service_check.rb +6 -15
  27. data/lib/dogapi/v1/snapshot.rb +10 -15
  28. data/lib/dogapi/v1/tag.rb +39 -99
  29. data/lib/dogapi/v1/user.rb +15 -69
  30. data/lib/dogapi/version.rb +1 -1
  31. data/spec/integration/alert_spec.rb +48 -0
  32. data/spec/integration/comment_spec.rb +32 -0
  33. data/spec/integration/common_spec.rb +32 -0
  34. data/spec/integration/dash_spec.rb +60 -0
  35. data/spec/integration/embed_spec.rb +43 -0
  36. data/spec/integration/event_spec.rb +73 -0
  37. data/spec/integration/metric_spec.rb +96 -0
  38. data/spec/integration/monitor_spec.rb +106 -0
  39. data/spec/integration/screenboard_spec.rb +61 -0
  40. data/spec/integration/search_spec.rb +11 -0
  41. data/spec/integration/service_check_spec.rb +12 -0
  42. data/spec/integration/snapshot_spec.rb +24 -0
  43. data/spec/integration/tag_spec.rb +66 -0
  44. data/spec/integration/user_spec.rb +46 -0
  45. data/spec/spec_helper.rb +85 -16
  46. data/spec/unit/common_spec.rb +101 -0
  47. data/spec/unit/facade_spec.rb +79 -0
  48. metadata +55 -52
  49. data/spec/alerts_spec.rb +0 -33
  50. data/spec/common_spec.rb +0 -37
  51. data/spec/facade_spec.rb +0 -166
  52. data/spec/support/cassettes/Alerts/create/returns_HTTP_code_200.yml +0 -114
  53. data/spec/support/cassettes/Alerts/create/returns_a_valid_event_ID.yml +0 -114
  54. data/spec/support/cassettes/Alerts/create/returns_the_same_query_as_sent.yml +0 -114
  55. data/spec/support/cassettes/Facade/Events/emits_aggregate_events.yml +0 -193
  56. data/spec/support/cassettes/Facade/Events/emits_events_and_retrieves_them.yml +0 -100
  57. data/spec/support/cassettes/Facade/Events/emits_events_with_specified_priority.yml +0 -98
  58. data/spec/support/cassettes/Facade/Tags/adds_updates_and_detaches_tags.yml +0 -442
  59. data/tests/test_alerts.rb +0 -38
  60. data/tests/test_base.rb +0 -30
  61. data/tests/test_client.rb +0 -23
  62. data/tests/test_comments.rb +0 -39
  63. data/tests/test_dashes.rb +0 -85
  64. data/tests/test_embed.rb +0 -194
  65. data/tests/test_monitors.rb +0 -192
  66. data/tests/test_screenboard.rb +0 -90
  67. data/tests/test_search.rb +0 -20
  68. data/tests/test_snapshot.rb +0 -28
  69. data/tests/test_users.rb +0 -65
@@ -10,8 +10,7 @@ module Dogapi
10
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/wiki].
11
11
  class Client
12
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)
13
+ def initialize(api_key, application_key=nil, host=nil, device=nil, silent=true, timeout=nil, endpoint=nil)
15
14
 
16
15
  if api_key
17
16
  @api_key = api_key
@@ -20,27 +19,24 @@ module Dogapi
20
19
  end
21
20
 
22
21
  @application_key = application_key
23
-
24
- @datadog_host = Dogapi.find_datadog_host()
25
-
26
- @host = host ||= Dogapi.find_localhost()
27
-
22
+ @datadog_host = endpoint || Dogapi.find_datadog_host()
23
+ @host = host || Dogapi.find_localhost()
28
24
  @device = device
29
25
 
30
26
  # FIXME: refactor to avoid all this code duplication
31
- @metric_svc = Dogapi::V1::MetricService.new(@api_key, @application_key, silent, timeout)
32
- @event_svc = Dogapi::V1::EventService.new(@api_key, @application_key, silent, timeout)
33
- @tag_svc = Dogapi::V1::TagService.new(@api_key, @application_key, silent, timeout)
34
- @comment_svc = Dogapi::V1::CommentService.new(@api_key, @application_key, silent, timeout)
35
- @search_svc = Dogapi::V1::SearchService.new(@api_key, @application_key, silent, timeout)
36
- @dash_service = Dogapi::V1::DashService.new(@api_key, @application_key, silent, timeout)
37
- @alert_svc = Dogapi::V1::AlertService.new(@api_key, @application_key, silent, timeout)
38
- @user_svc = Dogapi::V1::UserService.new(@api_key, @application_key, silent, timeout)
39
- @snapshot_svc = Dogapi::V1::SnapshotService.new(@api_key, @application_key, silent, timeout)
40
- @embed_svc = Dogapi::V1::EmbedService.new(@api_key, @application_key, silent, timeout)
41
- @screenboard_svc = Dogapi::V1::ScreenboardService.new(@api_key, @application_key, silent, timeout)
42
- @monitor_svc = Dogapi::V1::MonitorService.new(@api_key, @application_key, silent, timeout)
43
- @service_check_svc = Dogapi::V1::ServiceCheckService.new(@api_key, @application_key, silent, timeout)
27
+ @metric_svc = Dogapi::V1::MetricService.new(@api_key, @application_key, silent, timeout, @datadog_host)
28
+ @event_svc = Dogapi::V1::EventService.new(@api_key, @application_key, silent, timeout, @datadog_host)
29
+ @tag_svc = Dogapi::V1::TagService.new(@api_key, @application_key, silent, timeout, @datadog_host)
30
+ @comment_svc = Dogapi::V1::CommentService.new(@api_key, @application_key, silent, timeout, @datadog_host)
31
+ @search_svc = Dogapi::V1::SearchService.new(@api_key, @application_key, silent, timeout, @datadog_host)
32
+ @dash_service = Dogapi::V1::DashService.new(@api_key, @application_key, silent, timeout, @datadog_host)
33
+ @alert_svc = Dogapi::V1::AlertService.new(@api_key, @application_key, silent, timeout, @datadog_host)
34
+ @user_svc = Dogapi::V1::UserService.new(@api_key, @application_key, silent, timeout, @datadog_host)
35
+ @snapshot_svc = Dogapi::V1::SnapshotService.new(@api_key, @application_key, silent, timeout, @datadog_host)
36
+ @embed_svc = Dogapi::V1::EmbedService.new(@api_key, @application_key, silent, timeout, @datadog_host)
37
+ @screenboard_svc = Dogapi::V1::ScreenboardService.new(@api_key, @application_key, silent, timeout, @datadog_host)
38
+ @monitor_svc = Dogapi::V1::MonitorService.new(@api_key, @application_key, silent, timeout, @datadog_host)
39
+ @service_check_svc = Dogapi::V1::ServiceCheckService.new(@api_key, @application_key, silent, timeout, @datadog_host)
44
40
  @legacy_event_svc = Dogapi::EventService.new(@datadog_host)
45
41
  end
46
42
 
@@ -57,7 +53,7 @@ module Dogapi
57
53
  #
58
54
  # options[:type] = "counter" to specify a counter metric
59
55
  # options[:tags] = ["tag1", "tag2"] to tag the point
60
- def emit_point(metric, value, options = {})
56
+ def emit_point(metric, value, options= {})
61
57
  defaults = { :timestamp => Time.now }
62
58
  options = defaults.merge(options)
63
59
 
@@ -79,11 +75,11 @@ module Dogapi
79
75
  #
80
76
  # options[:type] = "counter" to specify a counter metric
81
77
  # options[:tags] = ["tag1", "tag2"] to tag the point
82
- def emit_points(metric, points, options = {})
78
+ def emit_points(metric, points, options= {})
83
79
  scope = override_scope options
84
80
 
85
81
  points.each do |p|
86
- p[0].kind_of? Time or raise "Not a Time"
82
+ p[0].kind_of? Time or raise 'Not a Time'
87
83
  p[0] = p[0].to_i
88
84
  p[1] = p[1].to_f # TODO: stupid to_f will never raise an exception
89
85
  end
@@ -119,7 +115,7 @@ module Dogapi
119
115
  # Optional arguments:
120
116
  # :host => String
121
117
  # :device => String
122
- def emit_event(event, options = {})
118
+ def emit_event(event, options= {})
123
119
  scope = override_scope options
124
120
 
125
121
  @event_svc.post(event, scope)
@@ -132,6 +128,13 @@ module Dogapi
132
128
  @event_svc.get(id)
133
129
  end
134
130
 
131
+ # Delete an event
132
+ #
133
+ # +id+ of the event to delete
134
+ def delete_event(id)
135
+ @event_svc.delete(id)
136
+ end
137
+
135
138
  # Get an optionally filtered event stream
136
139
  #
137
140
  # +start+ is a Time object for when to start the stream
@@ -142,14 +145,14 @@ module Dogapi
142
145
  # :priority => "normal" or "low"
143
146
  # :sources => String, see https://github.com/DataDog/dogapi/wiki/Event for a current list of sources
144
147
  # :tags => Array of Strings
145
- def stream(start, stop, options = {})
148
+ def stream(start, stop, options= {})
146
149
  @event_svc.stream(start, stop, options)
147
150
  end
148
151
 
149
152
  # <b>DEPRECATED:</b> Recording events with a duration has been deprecated.
150
153
  # The functionality will be removed in a later release.
151
- def start_event(event, options = {})
152
- warn "[DEPRECATION] Dogapi::Client.start_event() is deprecated. Use `emit_event` instead."
154
+ def start_event(event, options= {})
155
+ warn '[DEPRECATION] Dogapi::Client.start_event() is deprecated. Use `emit_event` instead.'
153
156
  defaults = { :source_type => nil }
154
157
  options = defaults.merge(options)
155
158
 
@@ -165,12 +168,12 @@ module Dogapi
165
168
  #
166
169
 
167
170
  # Post a comment
168
- def comment(message, options = {})
171
+ def comment(message, options= {})
169
172
  @comment_svc.comment(message, options)
170
173
  end
171
174
 
172
175
  # Post a comment
173
- def update_comment(comment_id, options = {})
176
+ def update_comment(comment_id, options= {})
174
177
  @comment_svc.update_comment(comment_id, options)
175
178
  end
176
179
 
@@ -193,14 +196,14 @@ module Dogapi
193
196
  #
194
197
 
195
198
  # Get all tags and their associated hosts at your org
196
- def all_tags(source = nil)
199
+ def all_tags(source=nil)
197
200
  @tag_svc.get_all(source)
198
201
  end
199
202
 
200
203
  # Get all tags for the given host
201
204
  #
202
205
  # +host_id+ can be the host's numeric id or string name
203
- def host_tags(host_id, source = nil, by_source = false)
206
+ def host_tags(host_id, source=nil, by_source=false)
204
207
  @tag_svc.get(host_id, source, by_source)
205
208
  end
206
209
 
@@ -209,7 +212,7 @@ module Dogapi
209
212
  # +host_id+ can be the host's numeric id or string name
210
213
  #
211
214
  # +tags+ is and Array of Strings
212
- def add_tags(host_id, tags, source = nil)
215
+ def add_tags(host_id, tags, source=nil)
213
216
  @tag_svc.add(host_id, tags, source)
214
217
  end
215
218
 
@@ -218,20 +221,20 @@ module Dogapi
218
221
  # +host_id+ can be the host's numeric id or string name
219
222
  #
220
223
  # +tags+ is and Array of Strings
221
- def update_tags(host_id, tags, source = nil)
224
+ def update_tags(host_id, tags, source=nil)
222
225
  @tag_svc.update(host_id, tags, source)
223
226
  end
224
227
 
225
228
  # <b>DEPRECATED:</b> Spelling mistake temporarily preserved as an alias.
226
229
  def detatch_tags(host_id)
227
- warn "[DEPRECATION] Dogapi::Client.detatch() is deprecated. Use `detach` instead."
230
+ warn '[DEPRECATION] Dogapi::Client.detatch() is deprecated. Use `detach` instead.'
228
231
  detach_tags(host_id)
229
232
  end
230
233
 
231
234
  # Remove all tags from the given host
232
235
  #
233
236
  # +host_id+ can be the host's numeric id or string name
234
- def detach_tags(host_id, source = nil)
237
+ def detach_tags(host_id, source=nil)
235
238
  @tag_svc.detach(host_id, source)
236
239
  end
237
240
 
@@ -240,12 +243,12 @@ module Dogapi
240
243
  #
241
244
 
242
245
  # Create a dashboard.
243
- def create_dashboard(title, description, graphs, template_variables = nil)
246
+ def create_dashboard(title, description, graphs, template_variables=nil)
244
247
  @dash_service.create_dashboard(title, description, graphs, template_variables)
245
248
  end
246
249
 
247
250
  # Update a dashboard.
248
- def update_dashboard(dash_id, title, description, graphs, template_variables = nil)
251
+ def update_dashboard(dash_id, title, description, graphs, template_variables=nil)
249
252
  @dash_service.update_dashboard(dash_id, title, description, graphs, template_variables)
250
253
  end
251
254
 
@@ -268,11 +271,11 @@ module Dogapi
268
271
  # ALERTS
269
272
  #
270
273
 
271
- def alert(query, options = {})
274
+ def alert(query, options= {})
272
275
  @alert_svc.alert(query, options)
273
276
  end
274
277
 
275
- def update_alert(alert_id, query, options = {})
278
+ def update_alert(alert_id, query, options= {})
276
279
  @alert_svc.update_alert(alert_id, query, options)
277
280
  end
278
281
 
@@ -297,11 +300,11 @@ module Dogapi
297
300
  end
298
301
 
299
302
  # User invite
300
- def invite(emails, options = {})
303
+ def invite(emails, options= {})
301
304
  @user_svc.invite(emails, options)
302
305
  end
303
306
 
304
- def create_user(description = {})
307
+ def create_user(description= {})
305
308
  @user_svc.create_user(description)
306
309
  end
307
310
 
@@ -313,7 +316,7 @@ module Dogapi
313
316
  @user_svc.get_user(handle)
314
317
  end
315
318
 
316
- def update_user(handle, description = {})
319
+ def update_user(handle, description= {})
317
320
  @user_svc.update_user(handle, description)
318
321
  end
319
322
 
@@ -322,7 +325,7 @@ module Dogapi
322
325
  end
323
326
 
324
327
  # Graph snapshot
325
- def graph_snapshot(metric_query, start_ts, end_ts, event_query = nil)
328
+ def graph_snapshot(metric_query, start_ts, end_ts, event_query=nil)
326
329
  @snapshot_svc.snapshot(metric_query, start_ts, end_ts, event_query)
327
330
  end
328
331
 
@@ -384,15 +387,15 @@ module Dogapi
384
387
  # MONITORS
385
388
  #
386
389
 
387
- def monitor(type, query, options = {})
390
+ def monitor(type, query, options= {})
388
391
  @monitor_svc.monitor(type, query, options)
389
392
  end
390
393
 
391
- def update_monitor(monitor_id, query, options = {})
394
+ def update_monitor(monitor_id, query, options= {})
392
395
  @monitor_svc.update_monitor(monitor_id, query, options)
393
396
  end
394
397
 
395
- def get_monitor(monitor_id, options = {})
398
+ def get_monitor(monitor_id, options= {})
396
399
  @monitor_svc.get_monitor(monitor_id, options)
397
400
  end
398
401
 
@@ -400,7 +403,7 @@ module Dogapi
400
403
  @monitor_svc.delete_monitor(monitor_id)
401
404
  end
402
405
 
403
- def get_all_monitors(options = {})
406
+ def get_all_monitors(options= {})
404
407
  @monitor_svc.get_all_monitors(options)
405
408
  end
406
409
 
@@ -412,11 +415,11 @@ module Dogapi
412
415
  @monitor_svc.unmute_monitors()
413
416
  end
414
417
 
415
- def mute_monitor(monitor_id, options = {})
418
+ def mute_monitor(monitor_id, options= {})
416
419
  @monitor_svc.mute_monitor(monitor_id, options)
417
420
  end
418
421
 
419
- def unmute_monitor(monitor_id, options = {})
422
+ def unmute_monitor(monitor_id, options= {})
420
423
  @monitor_svc.unmute_monitor(monitor_id, options)
421
424
  end
422
425
 
@@ -424,11 +427,11 @@ module Dogapi
424
427
  # MONITOR DOWNTIME
425
428
  #
426
429
 
427
- def schedule_downtime(scope, options = {})
430
+ def schedule_downtime(scope, options= {})
428
431
  @monitor_svc.schedule_downtime(scope, options)
429
432
  end
430
433
 
431
- def update_downtime(downtime_id, options = {})
434
+ def update_downtime(downtime_id, options= {})
432
435
  @monitor_svc.update_downtime(downtime_id, options)
433
436
  end
434
437
 
@@ -440,7 +443,7 @@ module Dogapi
440
443
  @monitor_svc.cancel_downtime(downtime_id)
441
444
  end
442
445
 
443
- def get_all_downtimes(options = {})
446
+ def get_all_downtimes(options= {})
444
447
  @monitor_svc.get_all_downtimes(options)
445
448
  end
446
449
 
@@ -448,7 +451,7 @@ module Dogapi
448
451
  # HOST MUTING
449
452
  #
450
453
 
451
- def mute_host(hostname, options = {})
454
+ def mute_host(hostname, options= {})
452
455
  @monitor_svc.mute_host(hostname, options)
453
456
  end
454
457
 
@@ -460,7 +463,7 @@ module Dogapi
460
463
  # SERVICE CHECKS
461
464
  #
462
465
 
463
- def service_check(check, host, status, options = {})
466
+ def service_check(check, host, status, options= {})
464
467
  @service_check_svc.service_check(check, host, status, options)
465
468
  end
466
469
 
@@ -9,12 +9,12 @@ module Dogapi
9
9
  # removed in an upcoming release.
10
10
  class MetricService < Dogapi::Service
11
11
 
12
- API_VERSION = "1.0.0"
12
+ API_VERSION = '1.0.0'
13
13
 
14
14
  # <b>DEPRECATED:</b> Going forward, use the V1 services. This legacy service will be
15
15
  # removed in an upcoming release.
16
16
  def submit(api_key, scope, metric, points)
17
- warn "[DEPRECATION] Dogapi::MetricService.submit() has been deprecated in favor of the newer V1 services"
17
+ warn '[DEPRECATION] Dogapi::MetricService.submit() has been deprecated in favor of the newer V1 services'
18
18
  series = [{
19
19
  :host => scope.host,
20
20
  :device => scope.device,
@@ -5,105 +5,42 @@ module Dogapi
5
5
 
6
6
  class AlertService < Dogapi::APIService
7
7
 
8
- API_VERSION = "v1"
8
+ API_VERSION = 'v1'
9
9
 
10
10
  def alert(query, options = {})
11
- begin
12
- params = {
13
- :api_key => @api_key,
14
- :application_key => @application_key
15
- }
11
+ body = {
12
+ 'query' => query,
13
+ }.merge options
16
14
 
17
- body = {
18
- 'query' => query,
19
- }.merge options
20
-
21
- request(Net::HTTP::Post, "/api/#{API_VERSION}/alert", params, body, true)
22
- rescue Exception => e
23
- suppress_error_if_silent e
24
- end
15
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/alert", nil, body, true)
25
16
  end
26
17
 
27
18
  def update_alert(alert_id, query, options)
28
- begin
29
- params = {
30
- :api_key => @api_key,
31
- :application_key => @application_key
32
- }
33
-
34
- body = {
35
- 'query' => query,
36
- }.merge options
19
+ body = {
20
+ 'query' => query,
21
+ }.merge options
37
22
 
38
- request(Net::HTTP::Put, "/api/#{API_VERSION}/alert/#{alert_id}", params, body, true)
39
- rescue Exception => e
40
- suppress_error_if_silent e
41
- end
23
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/alert/#{alert_id}", nil, body, true)
42
24
  end
43
25
 
44
26
  def get_alert(alert_id)
45
- begin
46
- params = {
47
- :api_key => @api_key,
48
- :application_key => @application_key
49
- }
50
-
51
- request(Net::HTTP::Get, "/api/#{API_VERSION}/alert/#{alert_id}", params, nil, false)
52
- rescue Exception => e
53
- suppress_error_if_silent e
54
- end
27
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/alert/#{alert_id}", nil, nil, false)
55
28
  end
56
29
 
57
30
  def delete_alert(alert_id)
58
- begin
59
- params = {
60
- :api_key => @api_key,
61
- :application_key => @application_key
62
- }
63
-
64
- request(Net::HTTP::Delete, "/api/#{API_VERSION}/alert/#{alert_id}", params, nil, false)
65
- rescue Exception => e
66
- suppress_error_if_silent e
67
- end
31
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/alert/#{alert_id}", nil, nil, false)
68
32
  end
69
33
 
70
- def get_all_alerts()
71
- begin
72
- params = {
73
- :api_key => @api_key,
74
- :application_key => @application_key
75
- }
76
-
77
- request(Net::HTTP::Get, "/api/#{API_VERSION}/alert", params, nil, false)
78
- rescue Exception => e
79
- suppress_error_if_silent e
80
- end
34
+ def get_all_alerts
35
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/alert", nil, nil, false)
81
36
  end
82
37
 
83
- def mute_alerts()
84
- begin
85
- params = {
86
- :api_key => @api_key,
87
- :application_key => @application_key
88
- }
89
-
90
- request(Net::HTTP::Post, "/api/#{API_VERSION}/mute_alerts", params, nil, false)
91
- rescue Exception => e
92
- suppress_error_if_silent e
93
- end
38
+ def mute_alerts
39
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/mute_alerts", nil, nil, false)
94
40
  end
95
41
 
96
- def unmute_alerts()
97
- begin
98
- params = {
99
- :api_key => @api_key,
100
- :application_key => @application_key
101
- }
102
-
103
- request(Net::HTTP::Post, "/api/#{API_VERSION}/unmute_alerts", params, nil, false)
104
- rescue Exception => e
105
- suppress_error_if_silent e
106
- end
42
+ def unmute_alerts
43
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/unmute_alerts", nil, nil, false)
107
44
  end
108
45
 
109
46
  end