dogtrainer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -4
- data/ChangeLog.md +11 -1
- data/README.md +57 -0
- data/lib/dogtrainer/api.rb +79 -9
- data/lib/dogtrainer/version.rb +1 -1
- data/spec/unit/api_spec.rb +380 -30
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e6664535d42df53717f7e3c2a08f59c1c69d898
|
4
|
+
data.tar.gz: f2dbcdc8d8f59fe052494811e168c577d504ba18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2f2dc0c0bde395d17d5f082f42945648ddf778ce381a0a342374c1213dc7fca11da4cdac8e47dfd6537309159a533be2095fe8f77044a9d76ea4f1f2e5b2766
|
7
|
+
data.tar.gz: 5fb760fa4430b82104498e91851059f35306807954d2244f24257184879a8864d6df9c5422b1c7c5bfe3462d78093e2b1600aab7999aaa815f570effb29bf096
|
data/.rubocop.yml
CHANGED
@@ -4,16 +4,16 @@
|
|
4
4
|
# - 'spec/unit/api_spec.rb'
|
5
5
|
|
6
6
|
Metrics/AbcSize:
|
7
|
-
Max:
|
7
|
+
Max: 100
|
8
8
|
|
9
9
|
Metrics/ClassLength:
|
10
|
-
Max:
|
10
|
+
Max: 999
|
11
11
|
|
12
12
|
Metrics/CyclomaticComplexity:
|
13
|
-
Max:
|
13
|
+
Max: 100
|
14
14
|
|
15
15
|
Metrics/MethodLength:
|
16
|
-
Max:
|
16
|
+
Max: 100
|
17
17
|
|
18
18
|
Metrics/PerceivedComplexity:
|
19
19
|
Max: 20
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
-
Version 0.
|
1
|
+
Version 0.1.1
|
2
|
+
|
3
|
+
- add ``message`` and ``escalation_message`` options to ``DogTrainer::API.upsert_monitor``
|
4
|
+
to allow user to easily override either or both of these
|
5
|
+
- handle a ``threshold`` Hash passed to ``DogTrainer::API.upsert_monitor`` and
|
6
|
+
``DogTrainer::API.params_for_monitor``
|
7
|
+
- expose ``renotify_interval`` as an option on ``DogTrainer::API.upsert_monitor``
|
8
|
+
- pass ``mon_type`` through to ``DogTrainer::API.generate_messages`` and generate
|
9
|
+
different messages for service checks (which have warning or alert)
|
10
|
+
|
11
|
+
Version 0.1.0
|
2
12
|
|
3
13
|
- initial release
|
data/README.md
CHANGED
@@ -64,6 +64,10 @@ These examples all rely on the ``require`` and class instantiation above.
|
|
64
64
|
|
65
65
|
#### Monitors
|
66
66
|
|
67
|
+
These configurations currently make some assumptions; if those aren't correct
|
68
|
+
for you, please open an issue. They also generate alert and escalation messages
|
69
|
+
from a template; see the example below to override them.
|
70
|
+
|
67
71
|
Event alert on sparse data (lack of data should not trigger an alert):
|
68
72
|
|
69
73
|
```ruby
|
@@ -107,6 +111,59 @@ dog.upsert_monitor(
|
|
107
111
|
)
|
108
112
|
```
|
109
113
|
|
114
|
+
Service Check ("app.ok" on host my.host.name) alert, with separate warning (2),
|
115
|
+
critical (5) and OK (1) thresholds, evalulated over the last 6 checks:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
dog.upsert_monitor(
|
119
|
+
"App Health on my.host.name",
|
120
|
+
"\"app.ok\".over(\"host:my.host.name\").last(6).count_by_status()",
|
121
|
+
{ 'warning' => 2, 'critical' => 5, 'ok' => 1 },
|
122
|
+
'<',
|
123
|
+
alert_no_data: false,
|
124
|
+
mon_type: 'service check'
|
125
|
+
)
|
126
|
+
```
|
127
|
+
|
128
|
+
Override alert and escalation messages with your own:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
dog.upsert_monitor(
|
132
|
+
"ASG In-Service Instances",
|
133
|
+
"avg(last_5m):sum:aws.autoscaling.group_in_service_instances{autoscaling_group:MY_ASG_NAME} < 2",
|
134
|
+
2,
|
135
|
+
'>=',
|
136
|
+
message: 'my alert message',
|
137
|
+
escalation_message: 'my escalation message'
|
138
|
+
)
|
139
|
+
```
|
140
|
+
|
141
|
+
Override only the alert message, leaving the default (generated by #generate_messages )
|
142
|
+
escalation message:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
dog.upsert_monitor(
|
146
|
+
"ASG In-Service Instances",
|
147
|
+
"avg(last_5m):sum:aws.autoscaling.group_in_service_instances{autoscaling_group:MY_ASG_NAME} < 2",
|
148
|
+
2,
|
149
|
+
'>=',
|
150
|
+
message: 'my alert message'
|
151
|
+
)
|
152
|
+
```
|
153
|
+
|
154
|
+
Completely remove the escalation message, leaving the default
|
155
|
+
(generated by #generate_messages ) alert message:
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
dog.upsert_monitor(
|
159
|
+
"ASG In-Service Instances",
|
160
|
+
"avg(last_5m):sum:aws.autoscaling.group_in_service_instances{autoscaling_group:MY_ASG_NAME} < 2",
|
161
|
+
2,
|
162
|
+
'>=',
|
163
|
+
escalation_message: nil
|
164
|
+
)
|
165
|
+
```
|
166
|
+
|
110
167
|
#### Boards
|
111
168
|
|
112
169
|
Create a TimeBoard with a handful of graphs about the "MY_ELB_NAME" ELB,
|
data/lib/dogtrainer/api.rb
CHANGED
@@ -97,7 +97,27 @@ module DogTrainer
|
|
97
97
|
# monitored.
|
98
98
|
# @param comparison [String] comparison operator or description for metric
|
99
99
|
# vs threshold; i.e. ">=", "<=", "=", "<", etc.
|
100
|
-
|
100
|
+
# @option mon_type [String] type of monitor as defined in DataDog
|
101
|
+
# API docs.
|
102
|
+
def generate_messages(metric_desc, comparison, mon_type)
|
103
|
+
if mon_type == 'service check'
|
104
|
+
message = [
|
105
|
+
"{{#is_alert}}'#{metric_desc}' is FAILING: {{check_message}}",
|
106
|
+
"{{/is_alert}}\n",
|
107
|
+
"{{#is_warning}}'#{metric_desc}' is WARNING: {{check_message}}",
|
108
|
+
"{{/is_warning}}\n",
|
109
|
+
"{{#is_recovery}}'#{metric_desc}' recovered: {{check_message}}",
|
110
|
+
"{{/is_recovery}}\n",
|
111
|
+
"{{#is_no_data}}'#{metric_desc}' is not reporting data",
|
112
|
+
"{{/is_no_data}}\n",
|
113
|
+
# repo path and notify to
|
114
|
+
'(monitor and threshold configuration for this alert is managed by ',
|
115
|
+
"#{@repo_path}) #{@notify_to}"
|
116
|
+
].join('')
|
117
|
+
escalation = "'#{metric_desc}' is still in error state: " \
|
118
|
+
'{{check_message}}'
|
119
|
+
return [message, escalation]
|
120
|
+
end
|
101
121
|
message = [
|
102
122
|
"{{#is_alert}}'#{metric_desc}' should be #{comparison} {{threshold}}, ",
|
103
123
|
"but is {{value}}.{{/is_alert}}\n",
|
@@ -119,7 +139,10 @@ module DogTrainer
|
|
119
139
|
# account
|
120
140
|
# @param message [String] alert/notification message for the monitor
|
121
141
|
# @param query [String] query for the monitor to evaluate
|
122
|
-
# @param threshold [Float] evaluation threshold for the monitor
|
142
|
+
# @param threshold [Float or Hash] evaluation threshold for the monitor;
|
143
|
+
# if a Float is passed, it will be provided as the ``critical`` threshold;
|
144
|
+
# otherise, a Hash in the form taken by the DataDog API should be provided
|
145
|
+
# (``critical``, ``warning`` and/or ``ok`` keys, Float values)
|
123
146
|
# @param [Hash] options
|
124
147
|
# @option options [String] :escalation_message optional escalation message
|
125
148
|
# for escalation notifications. Defaults to nil.
|
@@ -127,6 +150,10 @@ module DogTrainer
|
|
127
150
|
# of data. Defaults to true.
|
128
151
|
# @option options [String] :mon_type type of monitor as defined in DataDog
|
129
152
|
# API docs. Defaults to 'metric alert'.
|
153
|
+
# @option options [Integer] :renotify_interval the number of minutes after
|
154
|
+
# the last notification before a monitor will re-notify on the current
|
155
|
+
# status. It will re-notify only if not resolved. Default: 60. Set to nil
|
156
|
+
# to disable re-notification.
|
130
157
|
def params_for_monitor(
|
131
158
|
name,
|
132
159
|
message,
|
@@ -135,11 +162,21 @@ module DogTrainer
|
|
135
162
|
options = {
|
136
163
|
escalation_message: nil,
|
137
164
|
alert_no_data: true,
|
138
|
-
mon_type: 'metric alert'
|
165
|
+
mon_type: 'metric alert',
|
166
|
+
renotify_interval: 60
|
139
167
|
}
|
140
168
|
)
|
141
169
|
options[:alert_no_data] = true unless options.key?(:alert_no_data)
|
142
170
|
options[:mon_type] = 'metric alert' unless options.key?(:mon_type)
|
171
|
+
options[:renotify_interval] = 60 unless options.key?(:renotify_interval)
|
172
|
+
|
173
|
+
# handle threshold hash
|
174
|
+
thresh = if threshold.is_a?(Hash)
|
175
|
+
threshold
|
176
|
+
else
|
177
|
+
{ 'critical' => threshold }
|
178
|
+
end
|
179
|
+
|
143
180
|
monitor_data = {
|
144
181
|
'name' => name,
|
145
182
|
'type' => options[:mon_type],
|
@@ -151,10 +188,10 @@ module DogTrainer
|
|
151
188
|
'locked' => false,
|
152
189
|
'timeout_h' => 0,
|
153
190
|
'silenced' => {},
|
154
|
-
'thresholds' =>
|
191
|
+
'thresholds' => thresh,
|
155
192
|
'require_full_window' => false,
|
156
193
|
'notify_no_data' => options[:alert_no_data],
|
157
|
-
'renotify_interval' =>
|
194
|
+
'renotify_interval' => options[:renotify_interval],
|
158
195
|
'no_data_timeframe' => 20
|
159
196
|
}
|
160
197
|
}
|
@@ -178,7 +215,10 @@ module DogTrainer
|
|
178
215
|
# @param mon_name [String] name for the monitor; must be unique per DataDog
|
179
216
|
# account
|
180
217
|
# @param query [String] query for the monitor to evaluate
|
181
|
-
# @param threshold [Float] evaluation threshold for the monitor
|
218
|
+
# @param threshold [Float or Hash] evaluation threshold for the monitor;
|
219
|
+
# if a Float is passed, it will be provided as the ``critical`` threshold;
|
220
|
+
# otherise, a Hash in the form taken by the DataDog API should be provided
|
221
|
+
# (``critical``, ``warning`` and/or ``ok`` keys, Float values)
|
182
222
|
# @param comparator [String] comparison operator for metric vs threshold,
|
183
223
|
# describing the inverse of the query. I.e. if the query is checking for
|
184
224
|
# "< 100", then the comparator would be ">=".
|
@@ -187,20 +227,50 @@ module DogTrainer
|
|
187
227
|
# of data. Defaults to true.
|
188
228
|
# @option options [String] :mon_type type of monitor as defined in DataDog
|
189
229
|
# API docs. Defaults to 'metric alert'.
|
230
|
+
# @option options [Integer] :renotify_interval the number of minutes after
|
231
|
+
# the last notification before a monitor will re-notify on the current
|
232
|
+
# status. It will re-notify only if not resolved. Default: 60. Set to nil
|
233
|
+
# to disable re-notification.
|
234
|
+
# @option options [String] :message alert/notification message for the
|
235
|
+
# monitor; if omitted, will be generated by #generate_messages
|
236
|
+
# @option options [String] :escalation_message optional escalation message
|
237
|
+
# for escalation notifications. If omitted, will be generated by
|
238
|
+
# #generate_messages; explicitly set to nil to not add an escalation
|
239
|
+
# message to the monitor.
|
190
240
|
def upsert_monitor(
|
191
241
|
mon_name,
|
192
242
|
query,
|
193
243
|
threshold,
|
194
244
|
comparator,
|
195
|
-
options = {
|
245
|
+
options = {
|
246
|
+
alert_no_data: true,
|
247
|
+
mon_type: 'metric alert',
|
248
|
+
renotify_interval: 60,
|
249
|
+
message: nil
|
250
|
+
}
|
196
251
|
)
|
197
252
|
options[:alert_no_data] = true unless options.key?(:alert_no_data)
|
198
253
|
options[:mon_type] = 'metric alert' unless options.key?(:mon_type)
|
199
|
-
|
254
|
+
options[:renotify_interval] = 60 unless options.key?(:renotify_interval)
|
255
|
+
|
256
|
+
msg, esc = generate_messages(mon_name, comparator, options[:mon_type])
|
257
|
+
message = if options[:message].nil?
|
258
|
+
msg
|
259
|
+
else
|
260
|
+
options[:message]
|
261
|
+
end
|
262
|
+
escalation = if options.key?(:escalation_message)
|
263
|
+
options[:escalation_message]
|
264
|
+
else
|
265
|
+
esc
|
266
|
+
end
|
267
|
+
|
268
|
+
rno = options[:renotify_interval]
|
200
269
|
mon_params = params_for_monitor(mon_name, message, query, threshold,
|
201
270
|
escalation_message: escalation,
|
202
271
|
alert_no_data: options[:alert_no_data],
|
203
|
-
mon_type: options[:mon_type]
|
272
|
+
mon_type: options[:mon_type],
|
273
|
+
renotify_interval: rno)
|
204
274
|
logger.info "Upserting monitor: #{mon_name}"
|
205
275
|
monitor = get_existing_monitor_by_name(mon_name)
|
206
276
|
return create_monitor(mon_name, mon_params) if monitor.nil?
|
data/lib/dogtrainer/version.rb
CHANGED
data/spec/unit/api_spec.rb
CHANGED
@@ -148,21 +148,44 @@ describe DogTrainer::API do
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
describe '#generate_messages' do
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
151
|
+
context 'mon_type metric alert' do
|
152
|
+
it 'returns the appropriate message' do
|
153
|
+
expected = "{{#is_alert}}'mydesc' should be comp {{threshold}},"
|
154
|
+
expected += " but is {{value}}.{{/is_alert}}\n"
|
155
|
+
expected += "{{#is_recovery}}'mydesc' recovered (current value "
|
156
|
+
expected += '{{value}} is comp threshold of {{threshold}}).'
|
157
|
+
expected += "{{/is_recovery}}\n(monitor and threshold configuration "
|
158
|
+
expected += 'for this alert is managed by my_repo_path) @my-notify-to'
|
159
|
+
msg, = subject.generate_messages('mydesc', 'comp', 'metric alert')
|
160
|
+
expect(msg).to eq(expected)
|
161
|
+
end
|
162
|
+
it 'returns the appropriate message' do
|
163
|
+
escalation = "'mydesc' is still in error state (current value {{value}}"
|
164
|
+
escalation += ' is comp threshold of {{threshold}})'
|
165
|
+
_, esc = subject.generate_messages('mydesc', 'comp', 'metric alert')
|
166
|
+
expect(esc).to eq(escalation)
|
167
|
+
end
|
160
168
|
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
169
|
+
context 'mon_type service check' do
|
170
|
+
it 'returns the appropriate message' do
|
171
|
+
expected = "{{#is_alert}}'mydesc' is FAILING: {{check_message}}" \
|
172
|
+
"{{/is_alert}}\n"
|
173
|
+
expected += "{{#is_warning}}'mydesc' is WARNING: {{check_message}}" \
|
174
|
+
"{{/is_warning}}\n"
|
175
|
+
expected += "{{#is_recovery}}'mydesc' recovered: {{check_message}}" \
|
176
|
+
"{{/is_recovery}}\n"
|
177
|
+
expected += "{{#is_no_data}}'mydesc' is not reporting data" \
|
178
|
+
"{{/is_no_data}}\n"
|
179
|
+
expected += '(monitor and threshold configuration '
|
180
|
+
expected += 'for this alert is managed by my_repo_path) @my-notify-to'
|
181
|
+
msg, = subject.generate_messages('mydesc', 'comp', 'service check')
|
182
|
+
expect(msg).to eq(expected)
|
183
|
+
end
|
184
|
+
it 'returns the appropriate message' do
|
185
|
+
escalation = "'mydesc' is still in error state: {{check_message}}"
|
186
|
+
_, esc = subject.generate_messages('mydesc', 'comp', 'service check')
|
187
|
+
expect(esc).to eq(escalation)
|
188
|
+
end
|
166
189
|
end
|
167
190
|
end
|
168
191
|
describe '#params_for_monitor' do
|
@@ -247,6 +270,68 @@ describe DogTrainer::API do
|
|
247
270
|
mon_type: 'foo'
|
248
271
|
)).to eq(expected)
|
249
272
|
end
|
273
|
+
it 'sets renotify_interval if provided in options' do
|
274
|
+
expected = {
|
275
|
+
'name' => 'monname',
|
276
|
+
'type' => 'metric alert',
|
277
|
+
'query' => 'my_query',
|
278
|
+
'message' => 'my_msg',
|
279
|
+
'tags' => [],
|
280
|
+
'options' => {
|
281
|
+
'notify_audit' => false,
|
282
|
+
'locked' => false,
|
283
|
+
'timeout_h' => 0,
|
284
|
+
'silenced' => {},
|
285
|
+
'thresholds' => { 'critical' => 123.4 },
|
286
|
+
'require_full_window' => false,
|
287
|
+
'notify_no_data' => true,
|
288
|
+
'renotify_interval' => 120,
|
289
|
+
'no_data_timeframe' => 20
|
290
|
+
}
|
291
|
+
}
|
292
|
+
expect(subject.params_for_monitor(
|
293
|
+
'monname',
|
294
|
+
'my_msg',
|
295
|
+
'my_query',
|
296
|
+
123.4,
|
297
|
+
renotify_interval: 120
|
298
|
+
)).to eq(expected)
|
299
|
+
end
|
300
|
+
it 'passes through a threshold Hash' do
|
301
|
+
expected = {
|
302
|
+
'name' => 'monname',
|
303
|
+
'type' => 'foo',
|
304
|
+
'query' => 'my_query',
|
305
|
+
'message' => 'my_msg',
|
306
|
+
'tags' => [],
|
307
|
+
'options' => {
|
308
|
+
'notify_audit' => false,
|
309
|
+
'locked' => false,
|
310
|
+
'timeout_h' => 0,
|
311
|
+
'silenced' => {},
|
312
|
+
'thresholds' => {
|
313
|
+
'warning' => 50,
|
314
|
+
'critical' => 123.4,
|
315
|
+
'ok' => 20
|
316
|
+
},
|
317
|
+
'require_full_window' => false,
|
318
|
+
'notify_no_data' => true,
|
319
|
+
'renotify_interval' => 60,
|
320
|
+
'no_data_timeframe' => 20
|
321
|
+
}
|
322
|
+
}
|
323
|
+
expect(subject.params_for_monitor(
|
324
|
+
'monname',
|
325
|
+
'my_msg',
|
326
|
+
'my_query',
|
327
|
+
{
|
328
|
+
'warning' => 50,
|
329
|
+
'critical' => 123.4,
|
330
|
+
'ok' => 20
|
331
|
+
},
|
332
|
+
mon_type: 'foo'
|
333
|
+
)).to eq(expected)
|
334
|
+
end
|
250
335
|
it 'sets notify_no_data to false if provided in options' do
|
251
336
|
expected = {
|
252
337
|
'name' => 'monname',
|
@@ -289,7 +374,7 @@ describe DogTrainer::API do
|
|
289
374
|
'thresholds' => { 'critical' => 123.4 },
|
290
375
|
'require_full_window' => false,
|
291
376
|
'notify_no_data' => false,
|
292
|
-
'renotify_interval' =>
|
377
|
+
'renotify_interval' => 123,
|
293
378
|
'no_data_timeframe' => 20,
|
294
379
|
'escalation_message' => 'myesc'
|
295
380
|
}
|
@@ -301,7 +386,8 @@ describe DogTrainer::API do
|
|
301
386
|
123.4,
|
302
387
|
alert_no_data: false,
|
303
388
|
mon_type: 'foo',
|
304
|
-
escalation_message: 'myesc'
|
389
|
+
escalation_message: 'myesc',
|
390
|
+
renotify_interval: 123
|
305
391
|
)).to eq(expected)
|
306
392
|
end
|
307
393
|
end
|
@@ -321,11 +407,13 @@ describe DogTrainer::API do
|
|
321
407
|
.and_return('12345')
|
322
408
|
|
323
409
|
expect(dog).to_not receive(:update_monitor)
|
324
|
-
expect(subject).to receive(:generate_messages).once
|
410
|
+
expect(subject).to receive(:generate_messages).once
|
411
|
+
.with('mname', '>=', 'metric alert')
|
325
412
|
expect(subject).to receive(:params_for_monitor).once
|
326
413
|
.with('mname', 'msg', 'my_query', 123.4, escalation_message: 'esc',
|
327
414
|
alert_no_data: true,
|
328
|
-
mon_type: 'metric alert'
|
415
|
+
mon_type: 'metric alert',
|
416
|
+
renotify_interval: 60)
|
329
417
|
expect(subject).to receive(:get_existing_monitor_by_name).once
|
330
418
|
.with('mname')
|
331
419
|
expect(subject).to receive(:create_monitor).once
|
@@ -338,6 +426,41 @@ describe DogTrainer::API do
|
|
338
426
|
'>='
|
339
427
|
)).to eq('12345')
|
340
428
|
end
|
429
|
+
it 'handles a hash threshold' do
|
430
|
+
params = { 'foo' => 'bar', 'baz' => 'blam' }
|
431
|
+
dog = double(Dogapi::Client)
|
432
|
+
allow(dog).to receive(:update_monitor).with(any_args)
|
433
|
+
subject.instance_variable_set('@dog', dog)
|
434
|
+
allow(subject).to receive(:generate_messages).with(any_args)
|
435
|
+
.and_return(%w(msg esc))
|
436
|
+
allow(subject).to receive(:params_for_monitor).with(any_args)
|
437
|
+
.and_return(params)
|
438
|
+
allow(subject).to receive(:get_existing_monitor_by_name).with(any_args)
|
439
|
+
.and_return(nil)
|
440
|
+
allow(subject).to receive(:create_monitor).with(any_args)
|
441
|
+
.and_return('12345')
|
442
|
+
|
443
|
+
expect(dog).to_not receive(:update_monitor)
|
444
|
+
expect(subject).to receive(:generate_messages).once
|
445
|
+
.with('mname', '>=', 'metric alert')
|
446
|
+
expect(subject).to receive(:params_for_monitor).once
|
447
|
+
.with('mname', 'msg', 'my_query', { 'warning' => 5.3, 'ok' => 1 },
|
448
|
+
escalation_message: 'esc',
|
449
|
+
alert_no_data: true,
|
450
|
+
mon_type: 'metric alert',
|
451
|
+
renotify_interval: 60)
|
452
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
453
|
+
.with('mname')
|
454
|
+
expect(subject).to receive(:create_monitor).once
|
455
|
+
.with('mname', params)
|
456
|
+
|
457
|
+
expect(subject.upsert_monitor(
|
458
|
+
'mname',
|
459
|
+
'my_query',
|
460
|
+
{ 'warning' => 5.3, 'ok' => 1 },
|
461
|
+
'>='
|
462
|
+
)).to eq('12345')
|
463
|
+
end
|
341
464
|
it 'does nothing if it already exists with the right params' do
|
342
465
|
params = { 'foo' => 'bar', 'baz' => 'blam' }
|
343
466
|
existing = { 'foo' => 'bar', 'baz' => 'blam', 'id' => 'monid' }
|
@@ -354,11 +477,13 @@ describe DogTrainer::API do
|
|
354
477
|
.and_return('12345')
|
355
478
|
|
356
479
|
expect(dog).to_not receive(:update_monitor)
|
357
|
-
expect(subject).to receive(:generate_messages).once
|
480
|
+
expect(subject).to receive(:generate_messages).once
|
481
|
+
.with('mname', '>=', 'metric alert')
|
358
482
|
expect(subject).to receive(:params_for_monitor).once
|
359
483
|
.with('mname', 'msg', 'my_query', 123.4, escalation_message: 'esc',
|
360
484
|
alert_no_data: true,
|
361
|
-
mon_type: 'metric alert'
|
485
|
+
mon_type: 'metric alert',
|
486
|
+
renotify_interval: 60)
|
362
487
|
expect(subject).to receive(:get_existing_monitor_by_name).once
|
363
488
|
.with('mname')
|
364
489
|
expect(subject).to_not receive(:create_monitor)
|
@@ -398,11 +523,13 @@ describe DogTrainer::API do
|
|
398
523
|
|
399
524
|
expect(dog).to receive(:update_monitor).once
|
400
525
|
.with('monid', 'my_query', params)
|
401
|
-
expect(subject).to receive(:generate_messages).once
|
526
|
+
expect(subject).to receive(:generate_messages).once
|
527
|
+
.with('mname', '>=', 'metric alert')
|
402
528
|
expect(subject).to receive(:params_for_monitor).once
|
403
529
|
.with('mname', 'msg', 'my_query', 123.4, escalation_message: 'esc',
|
404
530
|
alert_no_data: true,
|
405
|
-
mon_type: 'metric alert'
|
531
|
+
mon_type: 'metric alert',
|
532
|
+
renotify_interval: 60)
|
406
533
|
expect(subject).to receive(:get_existing_monitor_by_name).once
|
407
534
|
.with('mname')
|
408
535
|
expect(subject).to_not receive(:create_monitor)
|
@@ -437,11 +564,13 @@ describe DogTrainer::API do
|
|
437
564
|
|
438
565
|
expect(dog).to receive(:update_monitor).once
|
439
566
|
.with('monid', 'my_query', params)
|
440
|
-
expect(subject).to receive(:generate_messages).once
|
567
|
+
expect(subject).to receive(:generate_messages).once
|
568
|
+
.with('mname', '>=', 'metric alert')
|
441
569
|
expect(subject).to receive(:params_for_monitor).once
|
442
570
|
.with('mname', 'msg', 'my_query', 123.4, escalation_message: 'esc',
|
443
571
|
alert_no_data: true,
|
444
|
-
mon_type: 'metric alert'
|
572
|
+
mon_type: 'metric alert',
|
573
|
+
renotify_interval: 60)
|
445
574
|
expect(subject).to receive(:get_existing_monitor_by_name).once
|
446
575
|
.with('mname')
|
447
576
|
expect(subject).to_not receive(:create_monitor)
|
@@ -484,11 +613,13 @@ describe DogTrainer::API do
|
|
484
613
|
|
485
614
|
expect(dog).to receive(:update_monitor).once
|
486
615
|
.with('monid', 'my_query', params)
|
487
|
-
expect(subject).to receive(:generate_messages).once
|
616
|
+
expect(subject).to receive(:generate_messages).once
|
617
|
+
.with('mname', '>=', 'metric alert')
|
488
618
|
expect(subject).to receive(:params_for_monitor).once
|
489
619
|
.with('mname', 'msg', 'my_query', 123.4, escalation_message: 'esc',
|
490
620
|
alert_no_data: true,
|
491
|
-
mon_type: 'metric alert'
|
621
|
+
mon_type: 'metric alert',
|
622
|
+
renotify_interval: 60)
|
492
623
|
expect(subject).to receive(:get_existing_monitor_by_name).once
|
493
624
|
.with('mname')
|
494
625
|
expect(subject).to_not receive(:create_monitor)
|
@@ -518,11 +649,13 @@ describe DogTrainer::API do
|
|
518
649
|
.and_return('12345')
|
519
650
|
|
520
651
|
expect(dog).to_not receive(:update_monitor)
|
521
|
-
expect(subject).to receive(:generate_messages).once
|
652
|
+
expect(subject).to receive(:generate_messages).once
|
653
|
+
.with('mname', '>=', 'metric alert')
|
522
654
|
expect(subject).to receive(:params_for_monitor).once
|
523
655
|
.with('mname', 'msg', 'my_query', 123.4, escalation_message: 'esc',
|
524
656
|
alert_no_data: false,
|
525
|
-
mon_type: 'metric alert'
|
657
|
+
mon_type: 'metric alert',
|
658
|
+
renotify_interval: 60)
|
526
659
|
expect(subject).to receive(:get_existing_monitor_by_name).once
|
527
660
|
.with('mname')
|
528
661
|
expect(subject).to_not receive(:create_monitor)
|
@@ -551,11 +684,13 @@ describe DogTrainer::API do
|
|
551
684
|
.and_return('12345')
|
552
685
|
|
553
686
|
expect(dog).to_not receive(:update_monitor)
|
554
|
-
expect(subject).to receive(:generate_messages).once
|
687
|
+
expect(subject).to receive(:generate_messages).once
|
688
|
+
.with('mname', '>=', 'foobar')
|
555
689
|
expect(subject).to receive(:params_for_monitor).once
|
556
690
|
.with('mname', 'msg', 'my_query', 123.4, escalation_message: 'esc',
|
557
691
|
alert_no_data: true,
|
558
|
-
mon_type: 'foobar'
|
692
|
+
mon_type: 'foobar',
|
693
|
+
renotify_interval: 60)
|
559
694
|
expect(subject).to receive(:get_existing_monitor_by_name).once
|
560
695
|
.with('mname')
|
561
696
|
expect(subject).to_not receive(:create_monitor)
|
@@ -568,6 +703,221 @@ describe DogTrainer::API do
|
|
568
703
|
mon_type: 'foobar'
|
569
704
|
)).to eq('monid')
|
570
705
|
end
|
706
|
+
it 'handles sparse options, with only renotify_interval' do
|
707
|
+
params = { 'foo' => 'bar', 'baz' => 'blam' }
|
708
|
+
existing = { 'foo' => 'bar', 'baz' => 'blam', 'id' => 'monid' }
|
709
|
+
dog = double(Dogapi::Client)
|
710
|
+
allow(dog).to receive(:update_monitor).with(any_args)
|
711
|
+
subject.instance_variable_set('@dog', dog)
|
712
|
+
allow(subject).to receive(:generate_messages).with(any_args)
|
713
|
+
.and_return(%w(msg esc))
|
714
|
+
allow(subject).to receive(:params_for_monitor).with(any_args)
|
715
|
+
.and_return(params)
|
716
|
+
allow(subject).to receive(:get_existing_monitor_by_name).with(any_args)
|
717
|
+
.and_return(existing)
|
718
|
+
allow(subject).to receive(:create_monitor).with(any_args)
|
719
|
+
.and_return('12345')
|
720
|
+
|
721
|
+
expect(dog).to_not receive(:update_monitor)
|
722
|
+
expect(subject).to receive(:generate_messages).once
|
723
|
+
.with('mname', '>=', 'metric alert')
|
724
|
+
expect(subject).to receive(:params_for_monitor).once
|
725
|
+
.with('mname', 'msg', 'my_query', 123.4, escalation_message: 'esc',
|
726
|
+
alert_no_data: true,
|
727
|
+
mon_type: 'metric alert',
|
728
|
+
renotify_interval: 100)
|
729
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
730
|
+
.with('mname')
|
731
|
+
expect(subject).to_not receive(:create_monitor)
|
732
|
+
|
733
|
+
expect(subject.upsert_monitor(
|
734
|
+
'mname',
|
735
|
+
'my_query',
|
736
|
+
123.4,
|
737
|
+
'>=',
|
738
|
+
renotify_interval: 100
|
739
|
+
)).to eq('monid')
|
740
|
+
end
|
741
|
+
it 'handles sparse options, with only message' do
|
742
|
+
params = { 'foo' => 'bar', 'baz' => 'blam' }
|
743
|
+
existing = { 'foo' => 'bar', 'baz' => 'blam', 'id' => 'monid' }
|
744
|
+
dog = double(Dogapi::Client)
|
745
|
+
allow(dog).to receive(:update_monitor).with(any_args)
|
746
|
+
subject.instance_variable_set('@dog', dog)
|
747
|
+
allow(subject).to receive(:generate_messages).with(any_args)
|
748
|
+
.and_return(%w(msg esc))
|
749
|
+
allow(subject).to receive(:params_for_monitor).with(any_args)
|
750
|
+
.and_return(params)
|
751
|
+
allow(subject).to receive(:get_existing_monitor_by_name).with(any_args)
|
752
|
+
.and_return(existing)
|
753
|
+
allow(subject).to receive(:create_monitor).with(any_args)
|
754
|
+
.and_return('12345')
|
755
|
+
|
756
|
+
expect(dog).to_not receive(:update_monitor)
|
757
|
+
expect(subject).to receive(:generate_messages).once
|
758
|
+
.with('mname', '>=', 'metric alert')
|
759
|
+
expect(subject).to receive(:params_for_monitor).once
|
760
|
+
.with('mname', 'foo', 'my_query', 123.4, escalation_message: 'esc',
|
761
|
+
alert_no_data: true,
|
762
|
+
mon_type: 'metric alert',
|
763
|
+
renotify_interval: 60)
|
764
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
765
|
+
.with('mname')
|
766
|
+
expect(subject).to_not receive(:create_monitor)
|
767
|
+
|
768
|
+
expect(subject.upsert_monitor(
|
769
|
+
'mname',
|
770
|
+
'my_query',
|
771
|
+
123.4,
|
772
|
+
'>=',
|
773
|
+
message: 'foo'
|
774
|
+
)).to eq('monid')
|
775
|
+
end
|
776
|
+
it 'handles sparse options, with only escalation_message' do
|
777
|
+
params = { 'foo' => 'bar', 'baz' => 'blam' }
|
778
|
+
existing = { 'foo' => 'bar', 'baz' => 'blam', 'id' => 'monid' }
|
779
|
+
dog = double(Dogapi::Client)
|
780
|
+
allow(dog).to receive(:update_monitor).with(any_args)
|
781
|
+
subject.instance_variable_set('@dog', dog)
|
782
|
+
allow(subject).to receive(:generate_messages).with(any_args)
|
783
|
+
.and_return(%w(msg esc))
|
784
|
+
allow(subject).to receive(:params_for_monitor).with(any_args)
|
785
|
+
.and_return(params)
|
786
|
+
allow(subject).to receive(:get_existing_monitor_by_name).with(any_args)
|
787
|
+
.and_return(existing)
|
788
|
+
allow(subject).to receive(:create_monitor).with(any_args)
|
789
|
+
.and_return('12345')
|
790
|
+
|
791
|
+
expect(dog).to_not receive(:update_monitor)
|
792
|
+
expect(subject).to receive(:generate_messages).once
|
793
|
+
.with('mname', '>=', 'metric alert')
|
794
|
+
expect(subject).to receive(:params_for_monitor).once
|
795
|
+
.with('mname', 'msg', 'my_query', 123.4, escalation_message: 'bar',
|
796
|
+
alert_no_data: true,
|
797
|
+
mon_type: 'metric alert',
|
798
|
+
renotify_interval: 60)
|
799
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
800
|
+
.with('mname')
|
801
|
+
expect(subject).to_not receive(:create_monitor)
|
802
|
+
|
803
|
+
expect(subject.upsert_monitor(
|
804
|
+
'mname',
|
805
|
+
'my_query',
|
806
|
+
123.4,
|
807
|
+
'>=',
|
808
|
+
escalation_message: 'bar'
|
809
|
+
)).to eq('monid')
|
810
|
+
end
|
811
|
+
it 'handles sparse options, with only message and escalation_message' do
|
812
|
+
params = { 'foo' => 'bar', 'baz' => 'blam' }
|
813
|
+
existing = { 'foo' => 'bar', 'baz' => 'blam', 'id' => 'monid' }
|
814
|
+
dog = double(Dogapi::Client)
|
815
|
+
allow(dog).to receive(:update_monitor).with(any_args)
|
816
|
+
subject.instance_variable_set('@dog', dog)
|
817
|
+
allow(subject).to receive(:generate_messages).with(any_args)
|
818
|
+
.and_return(%w(msg esc))
|
819
|
+
allow(subject).to receive(:params_for_monitor).with(any_args)
|
820
|
+
.and_return(params)
|
821
|
+
allow(subject).to receive(:get_existing_monitor_by_name).with(any_args)
|
822
|
+
.and_return(existing)
|
823
|
+
allow(subject).to receive(:create_monitor).with(any_args)
|
824
|
+
.and_return('12345')
|
825
|
+
|
826
|
+
expect(dog).to_not receive(:update_monitor)
|
827
|
+
expect(subject).to receive(:generate_messages).once
|
828
|
+
.with('mname', '>=', 'metric alert')
|
829
|
+
expect(subject).to receive(:params_for_monitor).once
|
830
|
+
.with('mname', 'foo', 'my_query', 123.4, escalation_message: 'bar',
|
831
|
+
alert_no_data: true,
|
832
|
+
mon_type: 'metric alert',
|
833
|
+
renotify_interval: 60)
|
834
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
835
|
+
.with('mname')
|
836
|
+
expect(subject).to_not receive(:create_monitor)
|
837
|
+
|
838
|
+
expect(subject.upsert_monitor(
|
839
|
+
'mname',
|
840
|
+
'my_query',
|
841
|
+
123.4,
|
842
|
+
'>=',
|
843
|
+
message: 'foo',
|
844
|
+
escalation_message: 'bar'
|
845
|
+
)).to eq('monid')
|
846
|
+
end
|
847
|
+
it 'handles sparse options, with only escalation_message set to nil' do
|
848
|
+
params = { 'foo' => 'bar', 'baz' => 'blam' }
|
849
|
+
existing = { 'foo' => 'bar', 'baz' => 'blam', 'id' => 'monid' }
|
850
|
+
dog = double(Dogapi::Client)
|
851
|
+
allow(dog).to receive(:update_monitor).with(any_args)
|
852
|
+
subject.instance_variable_set('@dog', dog)
|
853
|
+
allow(subject).to receive(:generate_messages).with(any_args)
|
854
|
+
.and_return(%w(msg esc))
|
855
|
+
allow(subject).to receive(:params_for_monitor).with(any_args)
|
856
|
+
.and_return(params)
|
857
|
+
allow(subject).to receive(:get_existing_monitor_by_name).with(any_args)
|
858
|
+
.and_return(existing)
|
859
|
+
allow(subject).to receive(:create_monitor).with(any_args)
|
860
|
+
.and_return('12345')
|
861
|
+
|
862
|
+
expect(dog).to_not receive(:update_monitor)
|
863
|
+
expect(subject).to receive(:generate_messages).once
|
864
|
+
.with('mname', '>=', 'metric alert')
|
865
|
+
expect(subject).to receive(:params_for_monitor).once
|
866
|
+
.with('mname', 'msg', 'my_query', 123.4, alert_no_data: true,
|
867
|
+
mon_type: 'metric alert',
|
868
|
+
renotify_interval: 60,
|
869
|
+
escalation_message: nil)
|
870
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
871
|
+
.with('mname')
|
872
|
+
expect(subject).to_not receive(:create_monitor)
|
873
|
+
|
874
|
+
expect(subject.upsert_monitor(
|
875
|
+
'mname',
|
876
|
+
'my_query',
|
877
|
+
123.4,
|
878
|
+
'>=',
|
879
|
+
escalation_message: nil
|
880
|
+
)).to eq('monid')
|
881
|
+
end
|
882
|
+
it 'handles all options' do
|
883
|
+
params = { 'foo' => 'bar', 'baz' => 'blam' }
|
884
|
+
existing = { 'foo' => 'bar', 'baz' => 'blam', 'id' => 'monid' }
|
885
|
+
dog = double(Dogapi::Client)
|
886
|
+
allow(dog).to receive(:update_monitor).with(any_args)
|
887
|
+
subject.instance_variable_set('@dog', dog)
|
888
|
+
allow(subject).to receive(:generate_messages).with(any_args)
|
889
|
+
.and_return(%w(msg esc))
|
890
|
+
allow(subject).to receive(:params_for_monitor).with(any_args)
|
891
|
+
.and_return(params)
|
892
|
+
allow(subject).to receive(:get_existing_monitor_by_name).with(any_args)
|
893
|
+
.and_return(existing)
|
894
|
+
allow(subject).to receive(:create_monitor).with(any_args)
|
895
|
+
.and_return('12345')
|
896
|
+
|
897
|
+
expect(dog).to_not receive(:update_monitor)
|
898
|
+
expect(subject).to receive(:generate_messages).once
|
899
|
+
.with('mname', '>=', 'service check')
|
900
|
+
expect(subject).to receive(:params_for_monitor).once
|
901
|
+
.with('mname', 'foo', 'my_query', 123.4, escalation_message: 'bar',
|
902
|
+
alert_no_data: false,
|
903
|
+
mon_type: 'service check',
|
904
|
+
renotify_interval: 10)
|
905
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
906
|
+
.with('mname')
|
907
|
+
expect(subject).to_not receive(:create_monitor)
|
908
|
+
|
909
|
+
expect(subject.upsert_monitor(
|
910
|
+
'mname',
|
911
|
+
'my_query',
|
912
|
+
123.4,
|
913
|
+
'>=',
|
914
|
+
renotify_interval: 10,
|
915
|
+
alert_no_data: false,
|
916
|
+
mon_type: 'service check',
|
917
|
+
message: 'foo',
|
918
|
+
escalation_message: 'bar'
|
919
|
+
)).to eq('monid')
|
920
|
+
end
|
571
921
|
end
|
572
922
|
describe '#create_monitor' do
|
573
923
|
it 'returns the monitor id if created successfully' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dogtrainer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jantman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dogapi
|