dogapi 1.4.3 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,13 @@
1
- = Ruby client for Datadog API v1.4.3
1
+ = Ruby client for Datadog API v1.5.0
2
2
 
3
3
  The Ruby client is a library suitable for inclusion in existing Ruby projects or for development of standalone scripts. It provides an abstraction on top of Datadog's raw HTTP interface for reporting events and metrics.
4
4
 
5
5
  = What's new?
6
6
 
7
+ == v1.5.0
8
+
9
+ * Alerting API
10
+
7
11
  == v1.4.3
8
12
 
9
13
  * Fix bug with capistrano integration for capistrano 2.13.5 (thanks @ansel1)
@@ -32,6 +32,7 @@ module Dogapi
32
32
  @comment_svc = Dogapi::V1::CommentService.new(@api_key, @application_key, silent)
33
33
  @search_svc = Dogapi::V1::SearchService.new(@api_key, @application_key, silent)
34
34
  @dash_service = Dogapi::V1::DashService.new(@api_key, @application_key, silent)
35
+ @alert_svc = Dogapi::V1::AlertService.new(@api_key, @application_key, silent)
35
36
 
36
37
  @legacy_event_svc = Dogapi::EventService.new(@datadog_host)
37
38
  end
@@ -240,6 +241,38 @@ module Dogapi
240
241
  @dash_service.delete_dashboard(dash_id)
241
242
  end
242
243
 
244
+ #
245
+ # ALERTS
246
+ #
247
+
248
+ def alert(query, options={})
249
+ @alert_svc.alert(query, options)
250
+ end
251
+
252
+ def update_alert(alert_id, query, options={})
253
+ @alert_svc.update_alert(alert_id, query, options)
254
+ end
255
+
256
+ def get_alert(alert_id)
257
+ @alert_svc.get_alert(alert_id)
258
+ end
259
+
260
+ def delete_alert(alert_id)
261
+ @alert_svc.delete_alert(alert_id)
262
+ end
263
+
264
+ def get_all_alerts()
265
+ @alert_svc.get_all_alerts()
266
+ end
267
+
268
+ def mute_alerts()
269
+ @alert_svc.mute_alerts()
270
+ end
271
+
272
+ def unmute_alerts()
273
+ @alert_svc.unmute_alerts()
274
+ end
275
+
243
276
  private
244
277
 
245
278
  def override_scope(host, device)
@@ -4,3 +4,4 @@ require 'dogapi/v1/tag'
4
4
  require 'dogapi/v1/comment'
5
5
  require 'dogapi/v1/search'
6
6
  require 'dogapi/v1/dash'
7
+ require 'dogapi/v1/alert'
@@ -0,0 +1,112 @@
1
+ require 'dogapi'
2
+
3
+ module Dogapi
4
+ class V1 # for namespacing
5
+
6
+ class AlertService < Dogapi::APIService
7
+
8
+ API_VERSION = "v1"
9
+
10
+ def alert(query, options={})
11
+ begin
12
+ params = {
13
+ :api_key => @api_key,
14
+ :application_key => @application_key
15
+ }
16
+
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
25
+ end
26
+
27
+ 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
37
+
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
42
+ end
43
+
44
+ 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
55
+ end
56
+
57
+ 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
68
+ end
69
+
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
81
+ end
82
+
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
94
+ end
95
+
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
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,38 @@
1
+ require 'dogapi'
2
+ require 'time'
3
+ require 'test_base.rb'
4
+
5
+ class TestAlerts < Test::Unit::TestCase
6
+ include TestBase
7
+
8
+ def test_alerts
9
+ dog = Dogapi::Client.new(@api_key, @app_key)
10
+
11
+ query = 'sum(last_1d):sum:system.net.bytes_rcvd{host:host0} > 100'
12
+
13
+ alert_id = dog.alert(query)[1]['id']
14
+ status, alert = dog.get_alert(alert_id)
15
+ assert_equal alert['query'], query, alert['query']
16
+ assert_equal alert['silenced'], false, alert['silenced']
17
+
18
+ dog.update_alert(alert_id, query, :silenced => true)
19
+ status, alert = dog.get_alert(alert_id)
20
+ assert_equal alert['query'], query, alert['query']
21
+ assert_equal alert['silenced'], true, alert['silenced']
22
+
23
+ dog.delete_alert(alert_id)
24
+
25
+ query1 = 'sum(last_1d):sum:system.net.bytes_rcvd{host:host0} > 100'
26
+ query2 = 'sum(last_1d):sum:system.net.bytes_rcvd{host:host0} > 200'
27
+
28
+ alert_id1 = dog.alert(query1)[1]['id']
29
+ alert_id2 = dog.alert(query2)[1]['id']
30
+ status, alerts = dog.get_all_alerts()
31
+ alerts = alerts['alerts']
32
+ alert1 = alerts.select {|a| a['id'] == alert_id1}
33
+ alert2 = alerts.select {|a| a['id'] == alert_id2}
34
+ assert_equal alert1[0]['query'], query1, alert1
35
+ assert_equal alert2[0]['query'], query2, alert2
36
+
37
+ end
38
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogapi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 1
8
- - 4
9
- - 3
10
- version: 1.4.3
7
+ - 5
8
+ - 0
9
+ segments_generated: true
10
+ version: 1.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Datadog, Inc.
@@ -15,24 +15,24 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-01 00:00:00 Z
18
+ date: 2012-11-06 00:00:00 -05:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
22
+ prerelease: false
21
23
  name: json
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
+ type: :runtime
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
27
- hash: 1
28
29
  segments:
29
30
  - 1
30
31
  - 5
31
32
  - 1
33
+ segments_generated: true
32
34
  version: 1.5.1
33
- version_requirements: *id001
34
- prerelease: false
35
- type: :runtime
35
+ requirement: *id001
36
36
  description:
37
37
  email: packages@datadoghq.com
38
38
  executables: []
@@ -48,6 +48,7 @@ files:
48
48
  - lib/dogapi/event.rb
49
49
  - lib/dogapi/facade.rb
50
50
  - lib/dogapi/metric.rb
51
+ - lib/dogapi/v1/alert.rb
51
52
  - lib/dogapi/v1/comment.rb
52
53
  - lib/dogapi/v1/dash.rb
53
54
  - lib/dogapi/v1/event.rb
@@ -56,12 +57,14 @@ files:
56
57
  - lib/dogapi/v1/tag.rb
57
58
  - lib/dogapi/v1.rb
58
59
  - lib/dogapi.rb
60
+ - tests/test_alerts.rb
59
61
  - tests/test_base.rb
60
62
  - tests/test_client.rb
61
63
  - tests/test_comments.rb
62
64
  - tests/test_dashes.rb
63
65
  - tests/test_search.rb
64
66
  - README.rdoc
67
+ has_rdoc: true
65
68
  homepage: http://datadoghq.com/
66
69
  licenses:
67
70
  - BSD
@@ -76,27 +79,25 @@ rdoc_options:
76
79
  require_paths:
77
80
  - lib
78
81
  required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
82
  requirements:
81
83
  - - ">="
82
84
  - !ruby/object:Gem::Version
83
- hash: 3
84
85
  segments:
85
86
  - 0
87
+ segments_generated: true
86
88
  version: "0"
87
89
  required_rubygems_version: !ruby/object:Gem::Requirement
88
- none: false
89
90
  requirements:
90
91
  - - ">="
91
92
  - !ruby/object:Gem::Version
92
- hash: 3
93
93
  segments:
94
94
  - 0
95
+ segments_generated: true
95
96
  version: "0"
96
97
  requirements: []
97
98
 
98
99
  rubyforge_project:
99
- rubygems_version: 1.8.24
100
+ rubygems_version: 1.3.6
100
101
  signing_key:
101
102
  specification_version: 3
102
103
  summary: Ruby bindings for Datadog's API