dogtrainer 0.1.1 → 0.2.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 +4 -4
- data/ChangeLog.md +4 -0
- data/README.md +48 -0
- data/lib/dogtrainer/api.rb +143 -6
- data/lib/dogtrainer/version.rb +1 -1
- data/spec/unit/api_spec.rb +238 -14
- 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: 82d400dbf30520efe26fd2c8e35423766df31d70
|
4
|
+
data.tar.gz: c49711ca30824470040e34c5010be7a2afee19d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0bb25a6a3c4119e67338aacdcdeb700b9ad2f4cce57152290f6f1b877af203c2b8e20fbcec1751deb84011df2dad4ebecea88d66b85a57479c4d70a604e4287
|
7
|
+
data.tar.gz: ccd27b826a7ed42ee86c30882101c5e5515327196842b5c2b1a7aa98f00063870888c89236eb3f90275258c1c13a122567174b2c24bb61dafa0ba45d5702e808
|
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
@@ -164,6 +164,54 @@ dog.upsert_monitor(
|
|
164
164
|
)
|
165
165
|
```
|
166
166
|
|
167
|
+
##### Muting and Unmuting monitors
|
168
|
+
|
169
|
+
Mute a single monitor by ID number (12345):
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
dog.mute_monitor_by_id(12345)
|
173
|
+
```
|
174
|
+
|
175
|
+
Mute a single monitor by ID number (12345) for one hour:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
ts = Time.now + 3600
|
179
|
+
dog.mute_monitor_by_id(12345, end_timestamp: ts.to_i)
|
180
|
+
```
|
181
|
+
|
182
|
+
Unmute a single monitor by ID number (12345):
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
dog.unmute_monitor_by_id(12345)
|
186
|
+
```
|
187
|
+
|
188
|
+
Mute a single monitor by name for one hour:
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
ts = Time.now + 3600
|
192
|
+
dog.mute_monitor_by_name('my whole monitor name', end_timestamp: ts.to_i)
|
193
|
+
```
|
194
|
+
|
195
|
+
Unmute a single monitor by name:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
dog.unmute_monitor_by_name('my whole monitor name')
|
199
|
+
```
|
200
|
+
|
201
|
+
Mute all monitors matching regex /ELB/ for one hour (this also accepts a String
|
202
|
+
in addition to Regexp objects):
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
ts = Time.now + 3600
|
206
|
+
dog.mute_monitors_by_regex(/ELB/, end_timestamp: ts.to_i)
|
207
|
+
```
|
208
|
+
|
209
|
+
Unmute all monitors matching /foo/ (provided as a String instead of Regexp):
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
dog.unmute_monitors_by_regex('foo')
|
213
|
+
```
|
214
|
+
|
167
215
|
#### Boards
|
168
216
|
|
169
217
|
Create a TimeBoard with a handful of graphs about the "MY_ELB_NAME" ELB,
|
data/lib/dogtrainer/api.rb
CHANGED
@@ -322,19 +322,156 @@ module DogTrainer
|
|
322
322
|
#
|
323
323
|
# @param mon_name [String] name of the monitor to return
|
324
324
|
def get_existing_monitor_by_name(mon_name)
|
325
|
+
get_monitors.each do |mon|
|
326
|
+
return mon if mon['name'] == mon_name
|
327
|
+
end
|
328
|
+
nil
|
329
|
+
end
|
330
|
+
|
331
|
+
# Get all monitors from DataDog, caching them in an instance variable.
|
332
|
+
def get_monitors
|
325
333
|
if @monitors.nil?
|
326
334
|
@monitors = @dog.get_all_monitors(group_states: 'all')
|
327
335
|
logger.info "Found #{@monitors[1].length} existing monitors in DataDog"
|
328
336
|
if @monitors[1].empty?
|
329
|
-
|
330
|
-
'
|
331
|
-
exit 1
|
337
|
+
raise 'ERROR: DataDog API call returned no existing monitors. ' \
|
338
|
+
'Something is wrong.'
|
332
339
|
end
|
333
340
|
end
|
334
|
-
@monitors[1]
|
335
|
-
|
341
|
+
@monitors[1]
|
342
|
+
end
|
343
|
+
|
344
|
+
# Mute the monitor identified by the specified unique ID, with an optional
|
345
|
+
# duration.
|
346
|
+
#
|
347
|
+
# @example mute monitor 12345 indefinitely
|
348
|
+
# dog = DogTrainer::API.new(api_key, app_key, notify_to)
|
349
|
+
# dog.mute_monitor_by_id(12345)
|
350
|
+
#
|
351
|
+
# @example mute monitor 12345 until 2016-09-17 01:39:52-00:00
|
352
|
+
# dog = DogTrainer::API.new(api_key, app_key, notify_to)
|
353
|
+
# dog.mute_monitor_by_id(12345, end_timestamp: 1474076393)
|
354
|
+
#
|
355
|
+
# @param mon_id [Integer] ID of the monitor to mute
|
356
|
+
# @param [Hash] options
|
357
|
+
# @option options [Integer] :end_timestamp optional timestamp
|
358
|
+
# for when the mute should end; Integer POSIX timestamp.
|
359
|
+
def mute_monitor_by_id(mon_id, options = { end_timestamp: nil })
|
360
|
+
if options.fetch(:end_timestamp, nil).nil?
|
361
|
+
logger.info "Muting monitor by ID #{mon_id}"
|
362
|
+
@dog.mute_monitor(mon_id)
|
363
|
+
else
|
364
|
+
end_ts = options[:end_timestamp]
|
365
|
+
logger.info "Muting monitor by ID #{mon_id} until #{end_ts}"
|
366
|
+
@dog.mute_monitor(mon_id, end: end_ts)
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
# Mute the monitor identified by the specified name, with an optional
|
371
|
+
# duration.
|
372
|
+
#
|
373
|
+
# @example mute monitor named 'My Monitor' indefinitely
|
374
|
+
# dog = DogTrainer::API.new(api_key, app_key, notify_to)
|
375
|
+
# dog.mute_monitor_by_name('My Monitor')
|
376
|
+
#
|
377
|
+
# @example mute monitor named 'My Monitor' until 2016-09-17 01:39:52-00:00
|
378
|
+
# dog = DogTrainer::API.new(api_key, app_key, notify_to)
|
379
|
+
# dog.mute_monitor_by_name('My Monitor', end_timestamp: 1474076393)
|
380
|
+
#
|
381
|
+
# @param mon_name [String] name of the monitor to mute
|
382
|
+
# @param [Hash] options
|
383
|
+
# @option options [Integer] :end_timestamp optional timestamp
|
384
|
+
# for when the mute should end; Integer POSIX timestamp.
|
385
|
+
# @raise [RuntimeError] raised if the specified monitor name can't be found
|
386
|
+
def mute_monitor_by_name(mon_name, options = { end_timestamp: nil })
|
387
|
+
mon = get_existing_monitor_by_name(mon_name)
|
388
|
+
raise "ERROR: Could not find monitor with name #{mon_name}" if mon.nil?
|
389
|
+
if options.fetch(:end_timestamp, nil).nil?
|
390
|
+
logger.info "Muting monitor by name #{mon_name} (#{mon['id']})"
|
391
|
+
@dog.mute_monitor(mon['id'])
|
392
|
+
else
|
393
|
+
end_ts = options[:end_timestamp]
|
394
|
+
logger.info "Muting monitor by name #{mon_name} (#{mon['id']}) " \
|
395
|
+
"until #{end_ts}"
|
396
|
+
@dog.mute_monitor(mon['id'], end: end_ts)
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
# Mute all monitors with names matching the specified regex, with an
|
401
|
+
# optional duration.
|
402
|
+
#
|
403
|
+
# @example mute monitors with names matching /myapp/ indefinitely
|
404
|
+
# dog = DogTrainer::API.new(api_key, app_key, notify_to)
|
405
|
+
# dog.mute_monitor_by_regex(/myapp/)
|
406
|
+
#
|
407
|
+
# @example mute monitors with names containing 'foo' indefinitely
|
408
|
+
# dog = DogTrainer::API.new(api_key, app_key, notify_to)
|
409
|
+
# dog.mute_monitor_by_regex('foo')
|
410
|
+
#
|
411
|
+
# @example mute monitors with names matching /myapp/ until 2016-09-17
|
412
|
+
# 01:39:52-00:00
|
413
|
+
# dog = DogTrainer::API.new(api_key, app_key, notify_to)
|
414
|
+
# dog.mute_monitor_by_regex(/myapp/, end_timestamp: 1474076393)
|
415
|
+
#
|
416
|
+
# @param mon_name_regex [String] or [Regexp] regex to match monitor names
|
417
|
+
# against
|
418
|
+
# @param [Hash] options
|
419
|
+
# @option options [Integer] :end_timestamp optional timestamp
|
420
|
+
# for when the mute should end; Integer POSIX timestamp.
|
421
|
+
def mute_monitors_by_regex(mon_name_regex, options = { end_timestamp: nil })
|
422
|
+
if mon_name_regex.class != Regexp
|
423
|
+
mon_name_regex = Regexp.new(mon_name_regex)
|
424
|
+
end
|
425
|
+
if options.fetch(:end_timestamp, nil).nil?
|
426
|
+
logger.info "Muting monitors by regex #{mon_name_regex.source}"
|
427
|
+
end_ts = nil
|
428
|
+
else
|
429
|
+
logger.info "Muting monitors by regex #{mon_name_regex.source} " \
|
430
|
+
"until #{end_ts}"
|
431
|
+
end_ts = options[:end_timestamp]
|
432
|
+
end
|
433
|
+
logger.debug "Searching for monitors matching: #{mon_name_regex.source}"
|
434
|
+
get_monitors.each do |mon|
|
435
|
+
if mon['name'] =~ mon_name_regex
|
436
|
+
logger.info "Muting monitor '#{mon['name']}' (#{mon['id']})"
|
437
|
+
mute_monitor_by_id(mon['id'], end_timestamp: end_ts)
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
# Unute the monitor identified by the specified unique ID.
|
443
|
+
#
|
444
|
+
# @param mon_id [Integer] ID of the monitor to mute
|
445
|
+
def unmute_monitor_by_id(mon_id)
|
446
|
+
logger.info "Unmuting monitor by ID #{mon_id}"
|
447
|
+
@dog.unmute_monitor(mon_id, all_scopes: true)
|
448
|
+
end
|
449
|
+
|
450
|
+
# Unmute the monitor identified by the specified name.
|
451
|
+
#
|
452
|
+
# @param mon_name [String] name of the monitor to mute
|
453
|
+
# @raise [RuntimeError] raised if the specified monitor name can't be found
|
454
|
+
def unmute_monitor_by_name(mon_name)
|
455
|
+
mon = get_existing_monitor_by_name(mon_name)
|
456
|
+
logger.info "Unmuting monitor by name #{mon_name}"
|
457
|
+
raise "ERROR: Could not find monitor with name #{mon_name}" if mon.nil?
|
458
|
+
unmute_monitor_by_id(mon['id'])
|
459
|
+
end
|
460
|
+
|
461
|
+
# Unmute all monitors with names matching the specified regex.
|
462
|
+
#
|
463
|
+
# @param mon_name_regex [String] regex to match monitor names against
|
464
|
+
def unmute_monitors_by_regex(mon_name_regex)
|
465
|
+
if mon_name_regex.class != Regexp
|
466
|
+
mon_name_regex = Regexp.new(mon_name_regex)
|
467
|
+
end
|
468
|
+
logger.info "Unmuting monitors by regex #{mon_name_regex.source}"
|
469
|
+
get_monitors.each do |mon|
|
470
|
+
if mon['name'] =~ mon_name_regex
|
471
|
+
logger.info "Unmuting monitor '#{mon['name']}' (#{mon['id']})"
|
472
|
+
unmute_monitor_by_id(mon['id'])
|
473
|
+
end
|
336
474
|
end
|
337
|
-
nil
|
338
475
|
end
|
339
476
|
|
340
477
|
###########################################
|
data/lib/dogtrainer/version.rb
CHANGED
data/spec/unit/api_spec.rb
CHANGED
@@ -948,7 +948,7 @@ describe DogTrainer::API do
|
|
948
948
|
expect(subject.create_monitor('foo', params)).to be_nil
|
949
949
|
end
|
950
950
|
end
|
951
|
-
describe '#
|
951
|
+
describe '#get_monitors' do
|
952
952
|
it 'retrieves monitors if they are not cached' do
|
953
953
|
monitors = [
|
954
954
|
'200',
|
@@ -963,8 +963,7 @@ describe DogTrainer::API do
|
|
963
963
|
subject.instance_variable_set('@dog', dog)
|
964
964
|
|
965
965
|
expect(dog).to receive(:get_all_monitors).once.with(group_states: 'all')
|
966
|
-
expect(subject.
|
967
|
-
.to eq('name' => 'bar', 'foo' => 'baz')
|
966
|
+
expect(subject.get_monitors).to eq(monitors[1])
|
968
967
|
expect(subject.instance_variable_get('@monitors')).to eq(monitors)
|
969
968
|
end
|
970
969
|
it 'does not retrieve monitors if they are cached' do
|
@@ -982,25 +981,250 @@ describe DogTrainer::API do
|
|
982
981
|
subject.instance_variable_set('@monitors', monitors)
|
983
982
|
|
984
983
|
expect(dog).to_not receive(:get_all_monitors)
|
985
|
-
expect(subject.
|
986
|
-
.to eq('name' => 'bar', 'foo' => 'baz')
|
984
|
+
expect(subject.get_monitors).to eq(monitors[1])
|
987
985
|
expect(subject.instance_variable_get('@monitors')).to eq(monitors)
|
988
986
|
end
|
989
|
-
it '
|
987
|
+
it 'raises if monitors list is empty' do
|
990
988
|
monitors = ['200', []]
|
991
989
|
dog = double(Dogapi::Client)
|
992
990
|
allow(dog).to receive(:get_all_monitors).with(any_args)
|
993
991
|
.and_return(monitors)
|
994
992
|
subject.instance_variable_set('@dog', dog)
|
995
|
-
allow(subject.logger).to receive(:error).with(any_args)
|
996
993
|
|
997
|
-
expect(dog).to receive(:get_all_monitors).once
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
994
|
+
expect(dog).to receive(:get_all_monitors).once.with(group_states: 'all')
|
995
|
+
expect { subject.get_monitors }
|
996
|
+
.to raise_error(RuntimeError, 'ERROR: DataDog API call returned no ' \
|
997
|
+
'existing monitors. Something is wrong.')
|
998
|
+
end
|
999
|
+
end
|
1000
|
+
describe '#mute_monitor_by_id' do
|
1001
|
+
it 'calls dog.mute_monitor with id' do
|
1002
|
+
dog = double(Dogapi::Client)
|
1003
|
+
allow(dog).to receive(:mute_monitor).with(any_args)
|
1004
|
+
subject.instance_variable_set('@dog', dog)
|
1005
|
+
|
1006
|
+
expect(dog).to receive(:mute_monitor).once.with(12_345)
|
1007
|
+
subject.mute_monitor_by_id(12_345)
|
1008
|
+
end
|
1009
|
+
it 'calls dog.mute_monitor with id and timestamp if specified' do
|
1010
|
+
dog = double(Dogapi::Client)
|
1011
|
+
allow(dog).to receive(:mute_monitor).with(any_args)
|
1012
|
+
subject.instance_variable_set('@dog', dog)
|
1013
|
+
|
1014
|
+
expect(dog).to receive(:mute_monitor).once
|
1015
|
+
.with(12_345, end: 6_789)
|
1016
|
+
subject.mute_monitor_by_id(12_345, end_timestamp: 6_789)
|
1017
|
+
end
|
1018
|
+
end
|
1019
|
+
describe '#mute_monitor_by_name' do
|
1020
|
+
it 'calls dog.mute_monitor with id' do
|
1021
|
+
monitor = { 'id' => 5_678 }
|
1022
|
+
dog = double(Dogapi::Client)
|
1023
|
+
allow(dog).to receive(:mute_monitor).with(any_args)
|
1024
|
+
allow(subject).to receive(:get_existing_monitor_by_name)
|
1025
|
+
.and_return(monitor)
|
1026
|
+
subject.instance_variable_set('@dog', dog)
|
1027
|
+
|
1028
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
1029
|
+
.with('mymon')
|
1030
|
+
expect(dog).to receive(:mute_monitor).once.with(5_678)
|
1031
|
+
subject.mute_monitor_by_name('mymon')
|
1032
|
+
end
|
1033
|
+
it 'calls dog.mute_monitor with id and timestamp if specified' do
|
1034
|
+
monitor = { 'id' => 5_678 }
|
1035
|
+
dog = double(Dogapi::Client)
|
1036
|
+
allow(dog).to receive(:mute_monitor).with(any_args)
|
1037
|
+
allow(subject).to receive(:get_existing_monitor_by_name)
|
1038
|
+
.and_return(monitor)
|
1039
|
+
subject.instance_variable_set('@dog', dog)
|
1040
|
+
|
1041
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
1042
|
+
.with('mymon')
|
1043
|
+
expect(dog).to receive(:mute_monitor).once.with(5_678, end: 1_234)
|
1044
|
+
subject.mute_monitor_by_name('mymon', end_timestamp: 1_234)
|
1045
|
+
end
|
1046
|
+
it 'raises error if monitor cannot be found' do
|
1047
|
+
dog = double(Dogapi::Client)
|
1048
|
+
allow(dog).to receive(:mute_monitor).with(any_args)
|
1049
|
+
allow(subject).to receive(:get_existing_monitor_by_name)
|
1050
|
+
.and_return(nil)
|
1051
|
+
subject.instance_variable_set('@dog', dog)
|
1052
|
+
|
1053
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
1054
|
+
.with('mymon')
|
1055
|
+
expect(dog).to_not receive(:mute_monitor)
|
1056
|
+
expect { subject.mute_monitor_by_name('mymon') }
|
1057
|
+
.to raise_error(RuntimeError,
|
1058
|
+
'ERROR: Could not find monitor with name mymon')
|
1059
|
+
end
|
1060
|
+
end
|
1061
|
+
describe '#mute_monitors_by_regex' do
|
1062
|
+
it 'mutes all matching monitors when passed a regex' do
|
1063
|
+
monitors = [
|
1064
|
+
{ 'name' => 'mymonitor', 'id' => 1 },
|
1065
|
+
{ 'name' => 'foo', 'id' => 2 },
|
1066
|
+
{ 'name' => 'bar', 'id' => 3 },
|
1067
|
+
{ 'name' => 'other monitor foo', 'id' => 4 }
|
1068
|
+
]
|
1069
|
+
allow(subject).to receive(:get_monitors).and_return(monitors)
|
1070
|
+
allow(subject).to receive(:mute_monitor_by_id)
|
1071
|
+
|
1072
|
+
expect(subject).to receive(:get_monitors).once
|
1073
|
+
expect(subject).to receive(:mute_monitor_by_id).once
|
1074
|
+
.with(1, end_timestamp: nil)
|
1075
|
+
expect(subject).to receive(:mute_monitor_by_id).once
|
1076
|
+
.with(4, end_timestamp: nil)
|
1077
|
+
subject.mute_monitors_by_regex(/monitor/)
|
1078
|
+
end
|
1079
|
+
it 'mutes all matching monitors when passed a string' do
|
1080
|
+
monitors = [
|
1081
|
+
{ 'name' => 'mymonitor', 'id' => 1 },
|
1082
|
+
{ 'name' => 'foo', 'id' => 2 },
|
1083
|
+
{ 'name' => 'bar', 'id' => 3 },
|
1084
|
+
{ 'name' => 'other monitor foo', 'id' => 4 }
|
1085
|
+
]
|
1086
|
+
allow(subject).to receive(:get_monitors).and_return(monitors)
|
1087
|
+
allow(subject).to receive(:mute_monitor_by_id)
|
1088
|
+
|
1089
|
+
expect(subject).to receive(:get_monitors).once
|
1090
|
+
expect(subject).to receive(:mute_monitor_by_id).once
|
1091
|
+
.with(1, end_timestamp: nil)
|
1092
|
+
expect(subject).to receive(:mute_monitor_by_id).once
|
1093
|
+
.with(4, end_timestamp: nil)
|
1094
|
+
subject.mute_monitors_by_regex('monitor')
|
1095
|
+
end
|
1096
|
+
it 'mutes all monitors with an end_timestamp if specified' do
|
1097
|
+
monitors = [
|
1098
|
+
{ 'name' => 'mymonitor', 'id' => 1 },
|
1099
|
+
{ 'name' => 'foo', 'id' => 2 },
|
1100
|
+
{ 'name' => 'bar', 'id' => 3 },
|
1101
|
+
{ 'name' => 'other monitor foo', 'id' => 4 }
|
1102
|
+
]
|
1103
|
+
allow(subject).to receive(:get_monitors).and_return(monitors)
|
1104
|
+
allow(subject).to receive(:mute_monitor_by_id)
|
1105
|
+
|
1106
|
+
expect(subject).to receive(:get_monitors).once
|
1107
|
+
expect(subject).to receive(:mute_monitor_by_id).once
|
1108
|
+
.with(1, end_timestamp: 1_234)
|
1109
|
+
expect(subject).to receive(:mute_monitor_by_id).once
|
1110
|
+
.with(4, end_timestamp: 1_234)
|
1111
|
+
subject.mute_monitors_by_regex('monitor', end_timestamp: 1_234)
|
1112
|
+
end
|
1113
|
+
it 'does not mute any monitors if there are no matches' do
|
1114
|
+
monitors = [
|
1115
|
+
{ 'name' => 'foo', 'id' => 2 },
|
1116
|
+
{ 'name' => 'bar', 'id' => 3 }
|
1117
|
+
]
|
1118
|
+
allow(subject).to receive(:get_monitors).and_return(monitors)
|
1119
|
+
allow(subject).to receive(:mute_monitor_by_id)
|
1120
|
+
|
1121
|
+
expect(subject).to receive(:get_monitors).once
|
1122
|
+
expect(subject).to_not receive(:mute_monitor_by_id)
|
1123
|
+
subject.mute_monitors_by_regex('monitor')
|
1124
|
+
end
|
1125
|
+
end
|
1126
|
+
describe '#unmute_monitor_by_id' do
|
1127
|
+
it 'calls dog.unmute_monitor with id' do
|
1128
|
+
dog = double(Dogapi::Client)
|
1129
|
+
allow(dog).to receive(:unmute_monitor).with(any_args)
|
1130
|
+
subject.instance_variable_set('@dog', dog)
|
1131
|
+
|
1132
|
+
expect(dog).to receive(:unmute_monitor).once
|
1133
|
+
.with(12_345, all_scopes: true)
|
1134
|
+
subject.unmute_monitor_by_id(12_345)
|
1135
|
+
end
|
1136
|
+
end
|
1137
|
+
describe '#unmute_monitor_by_name' do
|
1138
|
+
it 'calls dog.unmute_monitor with id' do
|
1139
|
+
monitor = { 'id' => 5_678 }
|
1140
|
+
allow(subject).to receive(:unmute_monitor_by_id).with(any_args)
|
1141
|
+
allow(subject).to receive(:get_existing_monitor_by_name)
|
1142
|
+
.and_return(monitor)
|
1143
|
+
|
1144
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
1145
|
+
.with('mymon')
|
1146
|
+
expect(subject).to receive(:unmute_monitor_by_id).once
|
1147
|
+
.with(5_678)
|
1148
|
+
subject.unmute_monitor_by_name('mymon')
|
1149
|
+
end
|
1150
|
+
it 'raises error if monitor cannot be found' do
|
1151
|
+
allow(subject).to receive(:unmute_monitor_by_id).with(any_args)
|
1152
|
+
allow(subject).to receive(:get_existing_monitor_by_name)
|
1153
|
+
.and_return(nil)
|
1154
|
+
|
1155
|
+
expect(subject).to receive(:get_existing_monitor_by_name).once
|
1156
|
+
.with('mymon')
|
1157
|
+
expect(subject).to_not receive(:unmute_monitor_by_id)
|
1158
|
+
expect { subject.unmute_monitor_by_name('mymon') }
|
1159
|
+
.to raise_error(RuntimeError,
|
1160
|
+
'ERROR: Could not find monitor with name mymon')
|
1161
|
+
end
|
1162
|
+
end
|
1163
|
+
describe '#unmute_monitors_by_regex' do
|
1164
|
+
it 'unmutes all matching monitors when passed a regex' do
|
1165
|
+
monitors = [
|
1166
|
+
{ 'name' => 'mymonitor', 'id' => 1 },
|
1167
|
+
{ 'name' => 'foo', 'id' => 2 },
|
1168
|
+
{ 'name' => 'bar', 'id' => 3 },
|
1169
|
+
{ 'name' => 'other monitor foo', 'id' => 4 }
|
1170
|
+
]
|
1171
|
+
allow(subject).to receive(:get_monitors).and_return(monitors)
|
1172
|
+
allow(subject).to receive(:unmute_monitor_by_id)
|
1173
|
+
|
1174
|
+
expect(subject).to receive(:get_monitors).once
|
1175
|
+
expect(subject).to receive(:unmute_monitor_by_id).once.with(1)
|
1176
|
+
expect(subject).to receive(:unmute_monitor_by_id).once.with(4)
|
1177
|
+
subject.unmute_monitors_by_regex(/monitor/)
|
1178
|
+
end
|
1179
|
+
it 'unmutes all matching monitors when passed a string' do
|
1180
|
+
monitors = [
|
1181
|
+
{ 'name' => 'mymonitor', 'id' => 1 },
|
1182
|
+
{ 'name' => 'foo', 'id' => 2 },
|
1183
|
+
{ 'name' => 'bar', 'id' => 3 },
|
1184
|
+
{ 'name' => 'other monitor foo', 'id' => 4 }
|
1185
|
+
]
|
1186
|
+
allow(subject).to receive(:get_monitors).and_return(monitors)
|
1187
|
+
allow(subject).to receive(:unmute_monitor_by_id)
|
1188
|
+
|
1189
|
+
expect(subject).to receive(:get_monitors).once
|
1190
|
+
expect(subject).to receive(:unmute_monitor_by_id).once.with(1)
|
1191
|
+
expect(subject).to receive(:unmute_monitor_by_id).once.with(4)
|
1192
|
+
subject.unmute_monitors_by_regex('monitor')
|
1193
|
+
end
|
1194
|
+
it 'does not unmute any monitors if there are no matches' do
|
1195
|
+
monitors = [
|
1196
|
+
{ 'name' => 'foo', 'id' => 2 },
|
1197
|
+
{ 'name' => 'bar', 'id' => 3 }
|
1198
|
+
]
|
1199
|
+
allow(subject).to receive(:get_monitors).and_return(monitors)
|
1200
|
+
allow(subject).to receive(:unmute_monitor_by_id)
|
1201
|
+
|
1202
|
+
expect(subject).to receive(:get_monitors).once
|
1203
|
+
expect(subject).to_not receive(:unmute_monitor_by_id)
|
1204
|
+
subject.unmute_monitors_by_regex('monitor')
|
1205
|
+
end
|
1206
|
+
end
|
1207
|
+
describe '#get_existing_monitor_by_name' do
|
1208
|
+
it 'returns the monitor if it exists' do
|
1209
|
+
monitors = [
|
1210
|
+
'200',
|
1211
|
+
[
|
1212
|
+
{ 'name' => 'foo', 'foo' => 'bar' },
|
1213
|
+
{ 'name' => 'bar', 'foo' => 'baz' }
|
1214
|
+
]
|
1215
|
+
]
|
1216
|
+
allow(subject).to receive(:get_monitors).and_return(monitors[1])
|
1217
|
+
|
1218
|
+
expect(subject).to receive(:get_monitors).once
|
1219
|
+
expect(subject.get_existing_monitor_by_name('bar'))
|
1220
|
+
.to eq('name' => 'bar', 'foo' => 'baz')
|
1221
|
+
end
|
1222
|
+
it 'returns nil if no monitors can be found' do
|
1223
|
+
monitors = ['200', []]
|
1224
|
+
allow(subject).to receive(:get_monitors).and_return(monitors[1])
|
1225
|
+
|
1226
|
+
expect(subject).to receive(:get_monitors).once
|
1227
|
+
expect(subject.get_existing_monitor_by_name('bar')).to be_nil
|
1004
1228
|
end
|
1005
1229
|
end
|
1006
1230
|
describe '#graphdef' 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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jantman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dogapi
|