dogapi 1.11.0 → 1.12.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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- N2Y1MzNkOWZlNzJmODkxZmY0OTczYmQxOTI1NGZlZGViODc2OTkyMg==
5
- data.tar.gz: !binary |-
6
- M2JkNGNhMTI2N2Y4NDczNzU0NDYyZmI3NGQyNjU1MzBkMWQxNjhmMw==
2
+ SHA1:
3
+ metadata.gz: 95f3c9690e24cc9136fa52d7ca188a37330772f6
4
+ data.tar.gz: 2e214f8924413926d12ba4880d296b89d3eb0190
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YjYzZTAyY2U2ZDU4ZjcxODZiNTRkY2Y2OGZkZTZlNTI2ZWQxNzZhY2I4ZTZi
10
- M2JmN2M2YmJhZDA0ODFkZDE2ZmE1YmMxM2YwZjQzNDUwOGRmNjk3OTRmZWM5
11
- MGI5MjU1N2UxZjllMzUyNGM3M2QwZjczNzNhZWUwMjAzN2FlYTU=
12
- data.tar.gz: !binary |-
13
- OTBkNTA4YTY5OWRjY2M0YmQ3MjMyZjUxYWM5MDcyODk3ZDcxNDhhZTY5ZGQ4
14
- Mjg2MzI4MjhiNmU3YTQwNTAxMDY2YzA2NjE2ZDQxMmI1ZGQyZDZhM2FkNGZk
15
- NDAzYjEyYWExZjQ3M2M5OWI0YzQ5NDQ1MjRkODFiOTk1YWM4ZDc=
6
+ metadata.gz: 84310c8ba834959fc039443a13792e17e51e65d9324914318eda49bef91cdd51fb1ad7121df30f69e782aa3cc154ebea95d3231c4dfadbb2345b0feac607c1aa
7
+ data.tar.gz: 55f84d609ad8db3a80a560d8ca977154b036a57be56c0597ef189bc8d62b95ec03b067ec86f12cdd895d1825b71c77236c358f4293c32284e4f5c7aa40c398c9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  Changes
2
2
  =======
3
+ # 1.12.0 / 2014-11-17
4
+ * Add support for the Monitor API [#51](https://github.com/DataDog/dogapi-rb/pull/51)
5
+ * Truncate event title and text before submission [#53](https://github.com/DataDog/dogapi-rb/pull/53)
6
+
3
7
  # 1.11.0 / 2014-07-03
4
8
  * Allow to send several metrics in the same http request
5
9
  * Add support for http proxy defined by the environment variables
data/lib/dogapi/event.rb CHANGED
@@ -63,6 +63,8 @@ module Dogapi
63
63
  class EventService < Dogapi::Service
64
64
 
65
65
  API_VERSION = "1.0.0"
66
+ MAX_BODY_LENGTH = 4000
67
+ MAX_TITLE_LENGTH = 100
66
68
 
67
69
  # <b>DEPRECATED:</b> Going forward, use the V1 services. This legacy service will be
68
70
  # removed in an upcoming release.
@@ -82,8 +84,8 @@ module Dogapi
82
84
  :alert_type => event.alert_type,
83
85
  :event_type => event.event_type,
84
86
  :event_object => event.event_object,
85
- :msg_title => event.msg_title,
86
- :msg_text => event.msg_text,
87
+ :msg_title => event.msg_title[0..MAX_TITLE_LENGTH - 1],
88
+ :msg_text => event.msg_text[0..MAX_BODY_LENGTH - 1],
87
89
  :json_payload => event.json_payload,
88
90
  }
89
91
 
data/lib/dogapi/facade.rb CHANGED
@@ -38,7 +38,8 @@ module Dogapi
38
38
  @user_svc = Dogapi::V1::UserService.new(@api_key, @application_key, silent, timeout)
39
39
  @snapshot_svc = Dogapi::V1::SnapshotService.new(@api_key, @application_key, silent, timeout)
40
40
  @screenboard_svc = Dogapi::V1::ScreenboardService.new(@api_key, @application_key, silent, timeout)
41
-
41
+ @monitor_svc = Dogapi::V1::MonitorService.new(@api_key, @application_key, silent, timeout)
42
+ @service_check_svc = Dogapi::V1::ServiceCheckService.new(@api_key, @application_key, silent, timeout)
42
43
  @legacy_event_svc = Dogapi::EventService.new(@datadog_host)
43
44
  end
44
45
 
@@ -317,6 +318,74 @@ module Dogapi
317
318
  @screenboard_svc.share_screenboard(board_id)
318
319
  end
319
320
 
321
+ #
322
+ # MONITORS
323
+ #
324
+
325
+ def monitor(type, query, options = {})
326
+ @monitor_svc.monitor(type, query, options)
327
+ end
328
+
329
+ def update_monitor(monitor_id, query, options = {})
330
+ @monitor_svc.update_monitor(monitor_id, query, options)
331
+ end
332
+
333
+ def get_monitor(monitor_id, options = {})
334
+ @monitor_svc.get_monitor(monitor_id, options)
335
+ end
336
+
337
+ def delete_monitor(monitor_id)
338
+ @monitor_svc.delete_monitor(monitor_id)
339
+ end
340
+
341
+ def get_all_monitors(options = {})
342
+ @monitor_svc.get_all_monitors(options)
343
+ end
344
+
345
+ def mute_monitors()
346
+ @monitor_svc.mute_monitors()
347
+ end
348
+
349
+ def unmute_monitors()
350
+ @monitor_svc.unmute_monitors()
351
+ end
352
+
353
+ def mute_monitor(monitor_id, options = {})
354
+ @monitor_svc.mute_monitor(monitor_id, options)
355
+ end
356
+
357
+ def unmute_monitor(monitor_id, options = {})
358
+ @monitor_svc.unmute_monitor(monitor_id, options)
359
+ end
360
+
361
+ #
362
+ # MONITOR DOWNTIME
363
+ #
364
+
365
+ def schedule_downtime(scope, start, options = {})
366
+ @monitor_svc.schedule_downtime(scope, start, options)
367
+ end
368
+
369
+ def get_downtime(downtime_id)
370
+ @monitor_svc.get_downtime(downtime_id)
371
+ end
372
+
373
+ def cancel_downtime(downtime_id)
374
+ @monitor_svc.cancel_downtime(downtime_id)
375
+ end
376
+
377
+ def get_all_downtimes(options = {})
378
+ @monitor_svc.get_all_downtimes(options)
379
+ end
380
+
381
+ #
382
+ # SERVICE CHECKS
383
+ #
384
+
385
+ def service_check(check, host, status, options = {})
386
+ @service_check_svc.service_check(check, host, status, options)
387
+ end
388
+
320
389
  private
321
390
 
322
391
  def override_scope(options= {})
@@ -7,6 +7,8 @@ module Dogapi
7
7
  class EventService < Dogapi::APIService
8
8
 
9
9
  API_VERSION = "v1"
10
+ MAX_BODY_LENGTH = 4000
11
+ MAX_TITLE_LENGTH = 100
10
12
 
11
13
  # Records an Event with no duration
12
14
  def post(event, scope=nil)
@@ -17,8 +19,8 @@ module Dogapi
17
19
  }
18
20
 
19
21
  body = event.to_hash.merge({
20
- :title => event.msg_title,
21
- :text => event.msg_text,
22
+ :title => event.msg_title[0..MAX_TITLE_LENGTH - 1],
23
+ :text => event.msg_text[0..MAX_BODY_LENGTH - 1],
22
24
  :date_happened => event.date_happened.to_i,
23
25
  :host => scope.host,
24
26
  :device => scope.device,
@@ -0,0 +1,220 @@
1
+ require 'dogapi'
2
+
3
+ module Dogapi
4
+ class V1 # for namespacing
5
+
6
+ class MonitorService < Dogapi::APIService
7
+
8
+ API_VERSION = 'v1'
9
+
10
+ def monitor(type, query, options = {})
11
+ begin
12
+ params = {
13
+ :api_key => @api_key,
14
+ :application_key => @application_key
15
+ }
16
+
17
+ body = {
18
+ 'type' => type,
19
+ 'query' => query,
20
+ }.merge options
21
+
22
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor", params, body, true)
23
+ rescue Exception => e
24
+ suppress_error_if_silent e
25
+ end
26
+ end
27
+
28
+ def update_monitor(monitor_id, query, options)
29
+ begin
30
+ params = {
31
+ :api_key => @api_key,
32
+ :application_key => @application_key
33
+ }
34
+
35
+ body = {
36
+ 'query' => query,
37
+ }.merge options
38
+
39
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/monitor/#{monitor_id}", params, body, true)
40
+ rescue Exception => e
41
+ suppress_error_if_silent e
42
+ end
43
+ end
44
+
45
+ def get_monitor(monitor_id, options = {})
46
+ begin
47
+ params = {
48
+ :api_key => @api_key,
49
+ :application_key => @application_key
50
+ }
51
+
52
+ # :group_states is an optional list of statuses to filter returned
53
+ # groups. If no value is given then no group states will be returned.
54
+ # Possible values are: "all", "ok", "warn", "alert", "no data".
55
+ if options[:group_states]
56
+ params[:group_states] = options[:group_states].join(',')
57
+ options.delete :group_states
58
+ end
59
+
60
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/#{monitor_id}", params, nil, false)
61
+ rescue Exception => e
62
+ suppress_error_if_silent e
63
+ end
64
+ end
65
+
66
+ def delete_monitor(monitor_id)
67
+ begin
68
+ params = {
69
+ :api_key => @api_key,
70
+ :application_key => @application_key
71
+ }
72
+
73
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/monitor/#{monitor_id}", params, nil, false)
74
+ rescue Exception => e
75
+ suppress_error_if_silent e
76
+ end
77
+ end
78
+
79
+ def get_all_monitors(options = {})
80
+ begin
81
+ params = {
82
+ :api_key => @api_key,
83
+ :application_key => @application_key
84
+ }
85
+
86
+ # :group_states is an optional list of statuses to filter returned
87
+ # groups. If no value is given then no group states will be returned.
88
+ # Possible values are: "all", "ok", "warn", "alert", "no data".
89
+ if options[:group_states]
90
+ params[:group_states] = options[:group_states].join(',')
91
+ options.delete :group_states
92
+ end
93
+
94
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor", params, nil, false)
95
+ rescue Exception => e
96
+ suppress_error_if_silent e
97
+ end
98
+ end
99
+
100
+ def mute_monitors()
101
+ begin
102
+ params = {
103
+ :api_key => @api_key,
104
+ :application_key => @application_key
105
+ }
106
+
107
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/mute_all", params, nil, false)
108
+ rescue Exception => e
109
+ suppress_error_if_silent e
110
+ end
111
+ end
112
+
113
+ def unmute_monitors()
114
+ begin
115
+ params = {
116
+ :api_key => @api_key,
117
+ :application_key => @application_key
118
+ }
119
+
120
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/unmute_all", params, nil, false)
121
+ rescue Exception => e
122
+ suppress_error_if_silent e
123
+ end
124
+ end
125
+
126
+ def mute_monitor(monitor_id, options = {})
127
+ begin
128
+ params = {
129
+ :api_key => @api_key,
130
+ :application_key => @application_key
131
+ }
132
+
133
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/#{monitor_id}/mute", params, options, true)
134
+ rescue Exception => e
135
+ suppress_error_if_silent e
136
+ end
137
+ end
138
+
139
+ def unmute_monitor(monitor_id, options = {})
140
+ begin
141
+ params = {
142
+ :api_key => @api_key,
143
+ :application_key => @application_key
144
+ }
145
+
146
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/#{monitor_id}/unmute", params, options, true)
147
+ rescue Exception => e
148
+ suppress_error_if_silent e
149
+ end
150
+ end
151
+
152
+ #
153
+ # DOWNTIMES
154
+
155
+ def schedule_downtime(scope, start, options = {})
156
+ begin
157
+ params = {
158
+ :api_key => @api_key,
159
+ :application_key => @application_key
160
+ }
161
+
162
+ body = {
163
+ 'scope' => scope,
164
+ 'start' => start
165
+ }.merge options
166
+
167
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/downtime", params, body, true)
168
+ rescue Exception => e
169
+ suppress_error_if_silent e
170
+ end
171
+ end
172
+
173
+ def get_downtime(downtime_id)
174
+ begin
175
+ params = {
176
+ :api_key => @api_key,
177
+ :application_key => @application_key
178
+ }
179
+
180
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime/#{downtime_id}", params, nil, false)
181
+ rescue Exception => e
182
+ suppress_error_if_silent e
183
+ end
184
+ end
185
+
186
+ def cancel_downtime(downtime_id)
187
+ begin
188
+ params = {
189
+ :api_key => @api_key,
190
+ :application_key => @application_key
191
+ }
192
+
193
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/downtime/#{downtime_id}", params, nil, false)
194
+ rescue Exception => e
195
+ suppress_error_if_silent e
196
+ end
197
+ end
198
+
199
+ def get_all_downtimes(options = {})
200
+ begin
201
+ params = {
202
+ :api_key => @api_key,
203
+ :application_key => @application_key
204
+ }
205
+
206
+ if options[:current_only]
207
+ params[:current_only] = options[:current_only]
208
+ options.delete :current_only
209
+ end
210
+
211
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime", params, nil, false)
212
+ rescue Exception => e
213
+ suppress_error_if_silent e
214
+ end
215
+ end
216
+
217
+ end
218
+
219
+ end
220
+ end
@@ -0,0 +1,32 @@
1
+ require 'dogapi'
2
+
3
+ module Dogapi
4
+ class V1
5
+
6
+ class ServiceCheckService < Dogapi::APIService
7
+
8
+ API_VERSION = 'v1'
9
+
10
+ def service_check(check, host, status, options = {})
11
+ begin
12
+ params = {
13
+ :api_key => @api_key,
14
+ :application_key => @application_key
15
+ }
16
+
17
+ body = {
18
+ 'check' => check,
19
+ 'host_name' => host,
20
+ 'status' => status
21
+ }.merge options
22
+
23
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/check_run", params, body, true)
24
+ rescue Exception => e
25
+ suppress_error_if_silent e
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
data/lib/dogapi/v1.rb CHANGED
@@ -8,3 +8,5 @@ require 'dogapi/v1/alert'
8
8
  require 'dogapi/v1/user'
9
9
  require 'dogapi/v1/snapshot'
10
10
  require 'dogapi/v1/screenboard'
11
+ require 'dogapi/v1/monitor'
12
+ require 'dogapi/v1/service_check'
@@ -1,3 +1,3 @@
1
1
  module Dogapi
2
- VERSION = "1.11.0"
2
+ VERSION = "1.12.0"
3
3
  end
data/spec/alerts_spec.rb CHANGED
@@ -17,8 +17,8 @@ describe "Alerts", :vcr => true do
17
17
  @dog.delete_alert(@new_alert[1]['id'])
18
18
  end
19
19
 
20
- it "returns HTTP code 201" do
21
- expect(@new_alert[0]).to eq '201'
20
+ it "returns HTTP code 200" do
21
+ expect(@new_alert[0]).to eq '200'
22
22
  end
23
23
 
24
24
  it "returns a valid event ID" do
data/spec/facade_spec.rb CHANGED
@@ -103,7 +103,7 @@ describe "Facade", :vcr => true do
103
103
 
104
104
  code, resp = @dog.emit_event(event)
105
105
  now_event_id = resp["event"]["id"]
106
- sleep 5
106
+ sleep 8
107
107
  code, resp = @dog.get_event(now_event_id)
108
108
  expect(resp['event']).not_to be_nil
109
109
  expect(resp['event']['text']).to eq(now_message)
@@ -113,7 +113,7 @@ describe "Facade", :vcr => true do
113
113
  event = Dogapi::Event.new('test message', :msg_title => 'title', :date_happened => Time.now(), :priority => "low")
114
114
  code, resp = @dog.emit_event(event)
115
115
  low_event_id = resp["event"]["id"]
116
- sleep 5
116
+ sleep 8
117
117
  code, resp = @dog.get_event(low_event_id)
118
118
  expect(resp['event']).not_to be_nil
119
119
  low_event = resp['event']
@@ -126,7 +126,7 @@ describe "Facade", :vcr => true do
126
126
  first = resp["event"]["id"]
127
127
  code, resp = @dog.emit_event(Dogapi::Event.new("Testing Aggregation (second)", :aggregation_key => now.to_i))
128
128
  second = resp["event"]["id"]
129
- sleep 5
129
+ sleep 8
130
130
  code, resp = @dog.get_event(first)
131
131
  expect(resp["event"]).not_to be_nil
132
132
  code, resp = @dog.get_event(second)
@@ -0,0 +1,98 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://app.datadoghq.com/api/v1/alert?api_key=9775a026f1ca7d1c6c5af9d94d9595a4&application_key=87ce4a24b5553d2e482ea8a8500e71b8ad4554ff
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"query":"avg(last_10m):avg:test.metric.metric{host:test.metric.host}
9
+ > 5"}'
10
+ headers:
11
+ Accept-Encoding:
12
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
13
+ Accept:
14
+ - '*/*'
15
+ User-Agent:
16
+ - Ruby
17
+ Content-Type:
18
+ - application/json
19
+ response:
20
+ status:
21
+ code: 200
22
+ message: OK
23
+ headers:
24
+ Cache-Control:
25
+ - no-cache
26
+ Content-Type:
27
+ - application/json; charset=utf-8
28
+ Date:
29
+ - Mon, 17 Nov 2014 18:26:23 GMT
30
+ Pragma:
31
+ - no-cache
32
+ Server:
33
+ - gunicorn/19.1.0
34
+ Strict-Transport-Security:
35
+ - max-age=15724800;
36
+ Vary:
37
+ - Accept-Encoding
38
+ X-Dd-Version:
39
+ - 31.1883.245-0
40
+ Content-Length:
41
+ - '288'
42
+ Connection:
43
+ - keep-alive
44
+ body:
45
+ encoding: UTF-8
46
+ string: '{"event_object":"d709ad144fa2ddcc5daa4f866747a991","notify_audit":true,"timeout_h":null,"silenced":{},"query":"avg(last_10m):avg:test.metric.metric{host:test.metric.host}
47
+ > 5","message":"","id":103961,"name":"**test.metric.metric** over **host:test.metric.host**
48
+ was **> 5** on average during the **last 10m**.","no_data_timeframe":false,"creator":3658,"notify_no_data":false,"renotify_interval":null,"state":"No
49
+ Data","escalation_message":""}'
50
+ http_version:
51
+ recorded_at: Mon, 17 Nov 2014 18:26:23 GMT
52
+ - request:
53
+ method: delete
54
+ uri: https://app.datadoghq.com/api/v1/alert/103961?api_key=9775a026f1ca7d1c6c5af9d94d9595a4&application_key=87ce4a24b5553d2e482ea8a8500e71b8ad4554ff
55
+ body:
56
+ encoding: US-ASCII
57
+ string: ''
58
+ headers:
59
+ Accept-Encoding:
60
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
61
+ Accept:
62
+ - '*/*'
63
+ User-Agent:
64
+ - Ruby
65
+ response:
66
+ status:
67
+ code: 200
68
+ message: OK
69
+ headers:
70
+ Cache-Control:
71
+ - no-cache
72
+ Content-Type:
73
+ - application/json; charset=utf-8
74
+ Date:
75
+ - Mon, 17 Nov 2014 18:26:23 GMT
76
+ Pragma:
77
+ - no-cache
78
+ Server:
79
+ - gunicorn/19.1.0
80
+ Strict-Transport-Security:
81
+ - max-age=15724800;
82
+ Vary:
83
+ - Accept-Encoding
84
+ X-Dd-Version:
85
+ - 31.1883.245-0
86
+ Content-Length:
87
+ - '279'
88
+ Connection:
89
+ - keep-alive
90
+ body:
91
+ encoding: UTF-8
92
+ string: '{"event_object":"d709ad144fa2ddcc5daa4f866747a991","notify_audit":true,"timeout_h":null,"silenced":{},"query":"avg(last_10m):avg:test.metric.metric{host:test.metric.host}
93
+ > 5","message":"","name":"**test.metric.metric** over **host:test.metric.host**
94
+ was **> 5** on average during the **last 10m**.","no_data_timeframe":false,"creator":3658,"notify_no_data":false,"renotify_interval":null,"state":"No
95
+ Data","escalation_message":""}'
96
+ http_version:
97
+ recorded_at: Mon, 17 Nov 2014 18:26:23 GMT
98
+ recorded_with: VCR 2.9.3