dogapi 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,138 @@
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_metric_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
+ options = {
13
+ 'silenced' => {'*' => nil},
14
+ 'notify_no_data' => false
15
+ }
16
+
17
+ monitor_id = dog.monitor('metric alert', query, :options=>options)[1]['id']
18
+ status, monitor = dog.get_monitor(monitor_id)
19
+ assert_equal monitor['query'], query, monitor['query']
20
+ assert_equal monitor['options']['silenced'], options['silenced'], monitor['options']
21
+
22
+ query2 = 'avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 200'
23
+ updated_monitor_id = dog.update_monitor(monitor_id, query2,
24
+ :options => options)[1]['id']
25
+ status, monitor = dog.get_monitor(updated_monitor_id)
26
+ assert_equal monitor['query'], query2, monitor['query']
27
+
28
+ name = 'test_monitors'
29
+ monitor_id = dog.update_monitor(monitor_id, query2, :name => name,
30
+ :options=>{'notify_no_data' => true})[1]['id']
31
+ status, monitor = dog.get_monitor(monitor_id)
32
+ assert_equal monitor['name'], name, monitor['name']
33
+ assert_equal monitor['options']['notify_no_data'], true, monitor['options']
34
+
35
+ dog.delete_monitor(monitor_id)
36
+ status, monitor = dog.get_monitor(monitor_id)
37
+ assert_equal status.to_i, 404, status.to_i
38
+
39
+ query1 = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"
40
+ query2 = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 200"
41
+
42
+ monitor_id1 = dog.monitor('metric alert', query1)[1]['id']
43
+ monitor_id2 = dog.monitor('metric alert', query2)[1]['id']
44
+ status, monitors = dog.get_all_monitors(:group_states => ['alert', 'warn'])
45
+ monitor1 = monitors.map{|m| m if m['id'] == monitor_id1}.compact[0]
46
+ monitor2 = monitors.map{|m| m if m['id'] == monitor_id2}.compact[0]
47
+ assert_equal monitor1['query'], query1, monitor1['query']
48
+ assert_equal monitor2['query'], query2, monitor2['query']
49
+
50
+ dog.delete_monitor(monitor_id1)
51
+ dog.delete_monitor(monitor_id2)
52
+ end
53
+
54
+ def test_checks
55
+ dog = Dogapi::Client.new(@api_key, @app_key)
56
+
57
+ query = '"ntp.in_sync".over("role:herc").last(3).count_by_status()'
58
+ options = {
59
+ 'notify_no_data' => false,
60
+ 'thresholds' => {
61
+ 'ok' => 3,
62
+ 'warning' => 2,
63
+ 'critical' => 1,
64
+ 'no data' => 3
65
+ }
66
+ }
67
+ monitor_id = dog.monitor('service check', query, :options => options)[1]['id']
68
+ status, monitor = dog.get_monitor(monitor_id, :group_states => ['all'])
69
+
70
+ assert_equal monitor['query'], query, monitor['query']
71
+ assert_equal monitor['options']['notify_no_data'], options['notify_no_data'], monitor['options']
72
+ assert_equal monitor['options']['thresholds'], options['thresholds'], monitor['options']
73
+
74
+ query2 = '"ntp.in_sync".over("role:sobotka").last(3).count_by_status()'
75
+ monitor_id = dog.update_monitor(monitor_id, query2)[1]['id']
76
+ status, monitor = dog.get_monitor(monitor_id)
77
+ assert_equal monitor['query'], query2, monitor['query']
78
+
79
+ dog.delete_monitor(monitor_id)
80
+ status, monitor = dog.get_monitor(monitor_id)
81
+ assert_equal status.to_i, 404, status.to_i
82
+ end
83
+
84
+ def test_monitor_muting
85
+ dog = Dogapi::Client.new(@api_key, @app_key)
86
+
87
+ query = 'avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100'
88
+ monitor_id = dog.monitor('metric alert', query)[1]['id']
89
+ status, monitor = dog.get_monitor(monitor_id)
90
+ assert_equal monitor['query'], query, monitor['query']
91
+
92
+ status, dt = dog.mute_monitors()
93
+ assert_equal dt['active'], true, dt['active']
94
+ assert_equal dt['scope'], ['*'], dt['scope']
95
+
96
+ status, dt = dog.unmute_monitors()
97
+ assert_equal status.to_i, 204, status.to_i
98
+
99
+ # We shouldn't be able to mute a simple alert on a scope.
100
+ status, _ = dog.mute_monitor(monitor_id, :scope => 'env:staging')
101
+ assert_equal status.to_i, 403, status.to_i
102
+
103
+ query2 = 'avg(last_1h):sum:system.net.bytes_rcvd{*} by {host} > 100'
104
+ monitor_id = dog.monitor('metric alert', query2)[1]['id']
105
+ status, monitor = dog.get_monitor(monitor_id)
106
+ assert_equal monitor['query'], query2, monitor['query']
107
+
108
+ dog.mute_monitor(monitor_id, :scope => 'host:foo')
109
+ status, monitor = dog.get_monitor(monitor_id)
110
+ assert_equal monitor['options']['silenced'], {'host:foo' => nil}, monitor['options']
111
+
112
+ dog.unmute_monitor(monitor_id, :scope => 'host:foo')
113
+ status, monitor = dog.get_monitor(monitor_id)
114
+ assert_equal monitor['options']['silenced'], {}, monitor['options']
115
+
116
+ dog.delete_monitor(monitor_id)
117
+ end
118
+
119
+ def test_downtime
120
+ dog = Dogapi::Client.new(@api_key, @app_key)
121
+ start_ts = Time.now.to_i
122
+ end_ts = start_ts + 1000
123
+ downtime_id = dog.schedule_downtime('env:staging', start_ts, :end => end_ts)[1]['id']
124
+ status, dt = dog.get_downtime(downtime_id)
125
+ assert_equal dt['start'], start_ts, dt['start']
126
+ assert_equal dt['end'], end_ts, dt['end']
127
+ assert_equal dt['scope'], ['env:staging'], dt['scope']
128
+
129
+ dog.cancel_downtime(downtime_id)
130
+ end
131
+
132
+ def test_service_checks
133
+ dog = Dogapi::Client.new(@api_key, @app_key)
134
+ status, response = dog.service_check('app.ok', 'app1', 1)
135
+ assert_equal status.to_i, 202
136
+ end
137
+
138
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-07 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.5.1
27
27
  - !ruby/object:Gem::Dependency
@@ -56,14 +56,14 @@ dependencies:
56
56
  name: rdoc
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: Ruby bindings for Datadog's API
@@ -102,8 +102,10 @@ files:
102
102
  - lib/dogapi/v1/dash.rb
103
103
  - lib/dogapi/v1/event.rb
104
104
  - lib/dogapi/v1/metric.rb
105
+ - lib/dogapi/v1/monitor.rb
105
106
  - lib/dogapi/v1/screenboard.rb
106
107
  - lib/dogapi/v1/search.rb
108
+ - lib/dogapi/v1/service_check.rb
107
109
  - lib/dogapi/v1/snapshot.rb
108
110
  - lib/dogapi/v1/tag.rb
109
111
  - lib/dogapi/v1/user.rb
@@ -112,6 +114,7 @@ files:
112
114
  - spec/common_spec.rb
113
115
  - spec/facade_spec.rb
114
116
  - spec/spec_helper.rb
117
+ - spec/support/cassettes/Alerts/create/returns_HTTP_code_200.yml
115
118
  - spec/support/cassettes/Alerts/create/returns_HTTP_code_201.yml
116
119
  - spec/support/cassettes/Alerts/create/returns_a_valid_event_ID.yml
117
120
  - spec/support/cassettes/Alerts/create/returns_the_same_query_as_sent.yml
@@ -128,6 +131,7 @@ files:
128
131
  - tests/test_client.rb
129
132
  - tests/test_comments.rb
130
133
  - tests/test_dashes.rb
134
+ - tests/test_monitors.rb
131
135
  - tests/test_screenboard.rb
132
136
  - tests/test_search.rb
133
137
  - tests/test_snapshot.rb
@@ -148,17 +152,17 @@ require_paths:
148
152
  - lib
149
153
  required_ruby_version: !ruby/object:Gem::Requirement
150
154
  requirements:
151
- - - ! '>='
155
+ - - '>='
152
156
  - !ruby/object:Gem::Version
153
157
  version: '0'
154
158
  required_rubygems_version: !ruby/object:Gem::Requirement
155
159
  requirements:
156
- - - ! '>='
160
+ - - '>='
157
161
  - !ruby/object:Gem::Version
158
162
  version: '0'
159
163
  requirements: []
160
164
  rubyforge_project:
161
- rubygems_version: 2.2.2
165
+ rubygems_version: 2.0.3
162
166
  signing_key:
163
167
  specification_version: 4
164
168
  summary: Ruby bindings for Datadog's API
@@ -167,6 +171,7 @@ test_files:
167
171
  - spec/common_spec.rb
168
172
  - spec/facade_spec.rb
169
173
  - spec/spec_helper.rb
174
+ - spec/support/cassettes/Alerts/create/returns_HTTP_code_200.yml
170
175
  - spec/support/cassettes/Alerts/create/returns_HTTP_code_201.yml
171
176
  - spec/support/cassettes/Alerts/create/returns_a_valid_event_ID.yml
172
177
  - spec/support/cassettes/Alerts/create/returns_the_same_query_as_sent.yml