flapjack 0.7.27 → 0.7.28
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +9 -0
- data/bin/flapjack +22 -28
- data/bin/flapjack-nagios-receiver +5 -27
- data/bin/flapjack-populator +2 -2
- data/bin/flapper +13 -14
- data/bin/receive-events +3 -20
- data/bin/simulate-failed-check +3 -20
- data/etc/flapjack_config.yaml.example +119 -86
- data/features/cli.feature +69 -0
- data/features/events.feature +15 -0
- data/features/packaging-lintian.feature +4 -6
- data/features/rollup.feature +198 -0
- data/features/steps/cli_steps.rb +81 -0
- data/features/steps/events_steps.rb +26 -16
- data/features/steps/notifications_steps.rb +2 -2
- data/features/steps/packaging-lintian_steps.rb +2 -2
- data/features/support/daemons.rb +113 -0
- data/features/support/env.rb +26 -4
- data/lib/flapjack/configuration.rb +2 -0
- data/lib/flapjack/data/contact.rb +76 -5
- data/lib/flapjack/data/entity_check.rb +16 -0
- data/lib/flapjack/data/message.rb +11 -8
- data/lib/flapjack/data/notification.rb +31 -3
- data/lib/flapjack/data/notification_rule.rb +1 -1
- data/lib/flapjack/filters/delays.rb +1 -5
- data/lib/flapjack/gateways/api/contact_methods.rb +12 -6
- data/lib/flapjack/gateways/email.rb +35 -26
- data/lib/flapjack/gateways/email/alert.html.erb +4 -4
- data/lib/flapjack/gateways/email/alert.text.erb +2 -2
- data/lib/flapjack/gateways/email/alert_subject.text.erb +14 -0
- data/lib/flapjack/gateways/email/rollup.html.erb +48 -0
- data/lib/flapjack/gateways/email/rollup.text.erb +20 -0
- data/lib/flapjack/gateways/email/rollup_subject.text.erb +19 -0
- data/lib/flapjack/gateways/jabber.rb +97 -47
- data/lib/flapjack/gateways/sms_messagenet.rb +26 -24
- data/lib/flapjack/gateways/sms_messagenet/alert.text.erb +15 -0
- data/lib/flapjack/gateways/sms_messagenet/rollup.text.erb +34 -0
- data/lib/flapjack/gateways/web/views/contact.html.erb +16 -8
- data/lib/flapjack/notifier.rb +17 -4
- data/lib/flapjack/processor.rb +1 -1
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +19 -19
- data/spec/lib/flapjack/data/contact_spec.rb +100 -25
- data/spec/lib/flapjack/data/event_spec.rb +1 -1
- data/spec/lib/flapjack/data/message_spec.rb +1 -1
- data/spec/lib/flapjack/data/notification_spec.rb +11 -3
- data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +36 -17
- data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +38 -38
- data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +15 -15
- data/spec/lib/flapjack/gateways/email_spec.rb +4 -4
- data/spec/lib/flapjack/gateways/jabber_spec.rb +13 -14
- data/spec/lib/flapjack/gateways/oobetet_spec.rb +2 -2
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +5 -5
- data/spec/lib/flapjack/gateways/sms_messagenet.spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +2 -2
- data/spec/lib/flapjack/gateways/web_spec.rb +4 -4
- data/spec/lib/flapjack/logger_spec.rb +3 -3
- data/spec/lib/flapjack/pikelet_spec.rb +10 -10
- data/spec/lib/flapjack/processor_spec.rb +4 -4
- data/spec/lib/flapjack/redis_pool_spec.rb +1 -1
- metadata +70 -5
- checksums.yaml +0 -15
@@ -3,11 +3,11 @@ require 'flapjack/data/notification'
|
|
3
3
|
|
4
4
|
describe Flapjack::Data::Notification, :redis => true, :logger => true do
|
5
5
|
|
6
|
-
let(:event) {
|
6
|
+
let(:event) { double(Flapjack::Data::Event) }
|
7
7
|
|
8
|
-
let(:contact) {
|
8
|
+
let(:contact) { double(Flapjack::Data::Contact) }
|
9
9
|
|
10
|
-
let(:timezone) {
|
10
|
+
let(:timezone) { double('timezone') }
|
11
11
|
|
12
12
|
it "generates a notification for an event" # do
|
13
13
|
# notification = Flapjack::Data::Notification.for_event(event, :type => 'problem',
|
@@ -27,6 +27,14 @@ describe Flapjack::Data::Notification, :redis => true, :logger => true do
|
|
27
27
|
contact.should_receive(:notification_rules).and_return([])
|
28
28
|
contact.should_receive(:media).and_return('email' => 'example@example.com',
|
29
29
|
'sms' => '0123456789')
|
30
|
+
contact.should_receive(:add_alerting_check_for_media).with("email", nil)
|
31
|
+
contact.should_receive(:add_alerting_check_for_media).with("sms", nil)
|
32
|
+
contact.should_receive(:clean_alerting_checks_for_media).with("email").and_return(0)
|
33
|
+
contact.should_receive(:clean_alerting_checks_for_media).with("sms").and_return(0)
|
34
|
+
contact.should_receive(:count_alerting_checks_for_media).with("email").and_return(0)
|
35
|
+
contact.should_receive(:count_alerting_checks_for_media).with("sms").and_return(0)
|
36
|
+
contact.should_receive(:rollup_threshold_for_media).with("email").and_return(nil)
|
37
|
+
contact.should_receive(:rollup_threshold_for_media).with("sms").and_return(nil)
|
30
38
|
|
31
39
|
messages = notification.messages([contact], :default_timezone => timezone,
|
32
40
|
:logger => @logger)
|
@@ -7,7 +7,7 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
7
7
|
Flapjack::Gateways::API
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:contact) {
|
10
|
+
let(:contact) { double(Flapjack::Data::Contact, :id => '21') }
|
11
11
|
let(:contact_core) {
|
12
12
|
{'id' => contact.id,
|
13
13
|
'first_name' => "Ada",
|
@@ -29,10 +29,14 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
29
29
|
}
|
30
30
|
}
|
31
31
|
|
32
|
-
let(:
|
32
|
+
let(:media_rollup_thresholds) {
|
33
|
+
{'email' => 5}
|
34
|
+
}
|
35
|
+
|
36
|
+
let(:redis) { double(::Redis) }
|
33
37
|
|
34
38
|
let(:notification_rule) {
|
35
|
-
|
39
|
+
double(Flapjack::Data::NotificationRule, :id => '1', :contact_id => '21')
|
36
40
|
}
|
37
41
|
|
38
42
|
let(:notification_rule_data) {
|
@@ -134,7 +138,7 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
134
138
|
]
|
135
139
|
}
|
136
140
|
|
137
|
-
existing =
|
141
|
+
existing = double(Flapjack::Data::Contact)
|
138
142
|
existing.should_receive(:id).and_return("0363")
|
139
143
|
existing.should_receive(:update).with(contacts['contacts'][1])
|
140
144
|
|
@@ -155,7 +159,7 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
155
159
|
]
|
156
160
|
}
|
157
161
|
|
158
|
-
existing =
|
162
|
+
existing = double(Flapjack::Data::Contact)
|
159
163
|
existing.should_receive(:id).twice.and_return("0362")
|
160
164
|
existing.should_receive(:delete!)
|
161
165
|
|
@@ -195,7 +199,7 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
195
199
|
end
|
196
200
|
|
197
201
|
it "lists a contact's notification rules" do
|
198
|
-
notification_rule_2 =
|
202
|
+
notification_rule_2 = double(Flapjack::Data::NotificationRule, :id => '2', :contact_id => '21')
|
199
203
|
notification_rule.should_receive(:to_json).and_return('"rule_1"')
|
200
204
|
notification_rule_2.should_receive(:to_json).and_return('"rule_2"')
|
201
205
|
notification_rules = [ notification_rule, notification_rule_2 ]
|
@@ -351,11 +355,13 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
351
355
|
it "returns the media of a contact" do
|
352
356
|
contact.should_receive(:media).and_return(media)
|
353
357
|
contact.should_receive(:media_intervals).and_return(media_intervals)
|
358
|
+
contact.should_receive(:media_rollup_thresholds).and_return(media_rollup_thresholds)
|
354
359
|
Flapjack::Data::Contact.should_receive(:find_by_id).
|
355
360
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
356
361
|
result = Hash[ *(media.keys.collect {|m|
|
357
|
-
[m, {'address'
|
358
|
-
'interval'
|
362
|
+
[m, {'address' => media[m],
|
363
|
+
'interval' => media_intervals[m],
|
364
|
+
'rollup_threshold' => media_rollup_thresholds[m] }]
|
359
365
|
}).flatten(1)].to_json
|
360
366
|
|
361
367
|
get "/contacts/#{contact.id}/media"
|
@@ -375,10 +381,15 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
375
381
|
it "returns the specified media of a contact" do
|
376
382
|
contact.should_receive(:media).and_return(media)
|
377
383
|
contact.should_receive(:media_intervals).and_return(media_intervals)
|
384
|
+
contact.should_receive(:media_rollup_thresholds).and_return(media_rollup_thresholds)
|
378
385
|
Flapjack::Data::Contact.should_receive(:find_by_id).
|
379
386
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
380
387
|
|
381
|
-
result = {
|
388
|
+
result = {
|
389
|
+
'address' => media['sms'],
|
390
|
+
'interval' => media_intervals['sms'],
|
391
|
+
'rollup_threshold' => media_rollup_thresholds['sms'],
|
392
|
+
}
|
382
393
|
|
383
394
|
get "/contacts/#{contact.id}/media/sms"
|
384
395
|
last_response.should be_ok
|
@@ -408,17 +419,22 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
408
419
|
# may distinguish between them
|
409
420
|
alt_media = media.merge('sms' => '04987654321')
|
410
421
|
alt_media_intervals = media_intervals.merge('sms' => '200')
|
422
|
+
alt_media_rollup_thresholds = media_rollup_thresholds.merge('sms' => '5')
|
411
423
|
|
412
424
|
contact.should_receive(:set_address_for_media).with('sms', '04987654321')
|
413
425
|
contact.should_receive(:set_interval_for_media).with('sms', '200')
|
426
|
+
contact.should_receive(:set_rollup_threshold_for_media).with('sms', '5')
|
414
427
|
contact.should_receive(:media).and_return(alt_media)
|
415
428
|
contact.should_receive(:media_intervals).and_return(alt_media_intervals)
|
429
|
+
contact.should_receive(:media_rollup_thresholds).and_return(alt_media_rollup_thresholds)
|
416
430
|
Flapjack::Data::Contact.should_receive(:find_by_id).
|
417
431
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
418
432
|
|
419
|
-
result = {'address'
|
433
|
+
result = {'address' => alt_media['sms'],
|
434
|
+
'interval' => alt_media_intervals['sms'],
|
435
|
+
'rollup_threshold' => alt_media_rollup_thresholds['sms']}
|
420
436
|
|
421
|
-
put "/contacts/#{contact.id}/media/sms", {:address => '04987654321', :interval => '200'}
|
437
|
+
put "/contacts/#{contact.id}/media/sms", {:address => '04987654321', :interval => '200', :rollup_threshold => '5'}
|
422
438
|
last_response.should be_ok
|
423
439
|
last_response.body.should be_json_eql(result.to_json)
|
424
440
|
end
|
@@ -442,11 +458,14 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
442
458
|
it "creates a media of a contact even if no interval is provided" do
|
443
459
|
alt_media = media.merge('sms' => '04987654321')
|
444
460
|
alt_media_intervals = media_intervals.merge('sms' => nil)
|
461
|
+
alt_media_rollup_thresholds = media_rollup_thresholds.merge('sms' => nil)
|
445
462
|
|
446
463
|
contact.should_receive(:set_address_for_media).with('sms', '04987654321')
|
447
464
|
contact.should_receive(:set_interval_for_media).with('sms', nil)
|
465
|
+
contact.should_receive(:set_rollup_threshold_for_media).with("sms", nil)
|
448
466
|
contact.should_receive(:media).and_return(alt_media)
|
449
467
|
contact.should_receive(:media_intervals).and_return(alt_media_intervals)
|
468
|
+
contact.should_receive(:media_rollup_thresholds).and_return(alt_media_rollup_thresholds)
|
450
469
|
Flapjack::Data::Contact.should_receive(:find_by_id).
|
451
470
|
with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
|
452
471
|
|
@@ -618,9 +637,9 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
618
637
|
end
|
619
638
|
|
620
639
|
it "gets all entity tags for a contact" do
|
621
|
-
entity_1 =
|
640
|
+
entity_1 = double(Flapjack::Data::Entity)
|
622
641
|
entity_1.should_receive(:name).and_return('entity_1')
|
623
|
-
entity_2 =
|
642
|
+
entity_2 = double(Flapjack::Data::Entity)
|
624
643
|
entity_2.should_receive(:name).and_return('entity_2')
|
625
644
|
tag_data = [{:entity => entity_1, :tags => ['web']},
|
626
645
|
{:entity => entity_2, :tags => ['app']}]
|
@@ -646,10 +665,10 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
646
665
|
end
|
647
666
|
|
648
667
|
it "adds tags to multiple entities for a contact" do
|
649
|
-
entity_1 =
|
668
|
+
entity_1 = double(Flapjack::Data::Entity)
|
650
669
|
entity_1.should_receive(:name).twice.and_return('entity_1')
|
651
670
|
entity_1.should_receive(:add_tags).with('web')
|
652
|
-
entity_2 =
|
671
|
+
entity_2 = double(Flapjack::Data::Entity)
|
653
672
|
entity_2.should_receive(:name).twice.and_return('entity_2')
|
654
673
|
entity_2.should_receive(:add_tags).with('app')
|
655
674
|
|
@@ -680,10 +699,10 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
|
|
680
699
|
end
|
681
700
|
|
682
701
|
it "deletes tags from multiple entities for a contact" do
|
683
|
-
entity_1 =
|
702
|
+
entity_1 = double(Flapjack::Data::Entity)
|
684
703
|
entity_1.should_receive(:name).and_return('entity_1')
|
685
704
|
entity_1.should_receive(:delete_tags).with('web')
|
686
|
-
entity_2 =
|
705
|
+
entity_2 = double(Flapjack::Data::Entity)
|
687
706
|
entity_2.should_receive(:name).and_return('entity_2')
|
688
707
|
entity_2.should_receive(:delete_tags).with('app')
|
689
708
|
|
@@ -3,7 +3,7 @@ require 'flapjack/gateways/api/entity_check_presenter'
|
|
3
3
|
|
4
4
|
describe 'Flapjack::Gateways::API::EntityCheckPresenter' do
|
5
5
|
|
6
|
-
let(:entity_check) {
|
6
|
+
let(:entity_check) { double(Flapjack::Data::EntityCheck) }
|
7
7
|
|
8
8
|
let(:time) { Time.now.to_i }
|
9
9
|
|
@@ -7,17 +7,17 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
7
7
|
Flapjack::Gateways::API
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:entity) {
|
11
|
-
let(:entity_check) {
|
10
|
+
let(:entity) { double(Flapjack::Data::Entity) }
|
11
|
+
let(:entity_check) { double(Flapjack::Data::EntityCheck) }
|
12
12
|
|
13
13
|
let(:entity_name) { 'www.example.net'}
|
14
14
|
let(:entity_name_esc) { URI.escape(entity_name) }
|
15
15
|
let(:check) { 'ping' }
|
16
16
|
|
17
|
-
let(:entity_presenter) {
|
18
|
-
let(:entity_check_presenter) {
|
17
|
+
let(:entity_presenter) { double(Flapjack::Gateways::API::EntityPresenter) }
|
18
|
+
let(:entity_check_presenter) { double(Flapjack::Gateways::API::EntityCheckPresenter) }
|
19
19
|
|
20
|
-
let(:redis) {
|
20
|
+
let(:redis) { double(::Redis) }
|
21
21
|
|
22
22
|
before(:all) do
|
23
23
|
Flapjack::Gateways::API.class_eval {
|
@@ -48,7 +48,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
48
48
|
context 'non-bulk API calls' do
|
49
49
|
|
50
50
|
it "returns the status for all checks on an entity" do
|
51
|
-
status =
|
51
|
+
status = double('status', :to_json => 'status!'.to_json)
|
52
52
|
result = {:entity => entity_name, :check => check, :status => status}
|
53
53
|
entity_presenter.should_receive(:status).and_return(result)
|
54
54
|
|
@@ -72,7 +72,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it "returns the status for a check on an entity" do
|
75
|
-
status =
|
75
|
+
status = double('status', :to_json => 'status!'.to_json)
|
76
76
|
entity_check_presenter.should_receive(:status).and_return(status)
|
77
77
|
|
78
78
|
Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
|
@@ -109,7 +109,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
109
109
|
end
|
110
110
|
|
111
111
|
it "returns a list of scheduled maintenance periods for an entity" do
|
112
|
-
sched =
|
112
|
+
sched = double('sched', :to_json => 'sched!'.to_json)
|
113
113
|
result = {:entity => entity_name, :check => check, :scheduled_maintenances => sched}
|
114
114
|
entity_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(result)
|
115
115
|
Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
|
@@ -126,7 +126,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
126
126
|
start = Time.parse('1 Jan 2012')
|
127
127
|
finish = Time.parse('6 Jan 2012')
|
128
128
|
|
129
|
-
sched =
|
129
|
+
sched = double('sched', :to_json => 'sched!'.to_json)
|
130
130
|
result = {:entity => entity_name, :check => check, :scheduled_maintenances => sched}
|
131
131
|
entity_presenter.should_receive(:scheduled_maintenances).with(start.to_i, finish.to_i).and_return(result)
|
132
132
|
Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
|
@@ -141,7 +141,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
141
141
|
end
|
142
142
|
|
143
143
|
it "returns a list of scheduled maintenance periods for a check on an entity" do
|
144
|
-
sched =
|
144
|
+
sched = double('sched', :to_json => 'sched!'.to_json)
|
145
145
|
entity_check_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(sched)
|
146
146
|
Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
|
147
147
|
with(entity_check).and_return(entity_check_presenter)
|
@@ -171,7 +171,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
171
171
|
end
|
172
172
|
|
173
173
|
it "returns a list of unscheduled maintenance periods for an entity" do
|
174
|
-
unsched =
|
174
|
+
unsched = double('unsched', :to_json => 'unsched!'.to_json)
|
175
175
|
result = {:entity => entity_name, :check => check, :unscheduled_maintenances => unsched}
|
176
176
|
entity_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(result)
|
177
177
|
Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
|
@@ -185,7 +185,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
185
185
|
end
|
186
186
|
|
187
187
|
it "returns a list of unscheduled maintenance periods for a check on an entity" do
|
188
|
-
unsched =
|
188
|
+
unsched = double('unsched', :to_json => 'unsched!'.to_json)
|
189
189
|
entity_check_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(unsched)
|
190
190
|
Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
|
191
191
|
with(entity_check).and_return(entity_check_presenter)
|
@@ -203,7 +203,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
203
203
|
start = Time.parse('1 Jan 2012')
|
204
204
|
finish = Time.parse('6 Jan 2012')
|
205
205
|
|
206
|
-
unsched =
|
206
|
+
unsched = double('unsched', :to_json => 'unsched!'.to_json)
|
207
207
|
entity_check_presenter.should_receive(:unscheduled_maintenances).with(start.to_i, finish.to_i).and_return(unsched)
|
208
208
|
Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
|
209
209
|
with(entity_check).and_return(entity_check_presenter)
|
@@ -219,7 +219,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
219
219
|
end
|
220
220
|
|
221
221
|
it "returns a list of outages for an entity" do
|
222
|
-
out =
|
222
|
+
out = double('out', :to_json => 'out!'.to_json)
|
223
223
|
result = {:entity => entity_name, :check => check, :outages => out}
|
224
224
|
entity_presenter.should_receive(:outages).with(nil, nil).and_return(result)
|
225
225
|
Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
|
@@ -233,7 +233,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
233
233
|
end
|
234
234
|
|
235
235
|
it "returns a list of outages for a check on an entity" do
|
236
|
-
out =
|
236
|
+
out = double('out', :to_json => 'out!'.to_json)
|
237
237
|
entity_check_presenter.should_receive(:outages).with(nil, nil).and_return(out)
|
238
238
|
Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
|
239
239
|
with(entity_check).and_return(entity_check_presenter)
|
@@ -248,7 +248,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
248
248
|
end
|
249
249
|
|
250
250
|
it "returns a list of downtimes for an entity" do
|
251
|
-
down =
|
251
|
+
down = double('down', :to_json => 'down!'.to_json)
|
252
252
|
result = {:entity => entity_name, :check => check, :downtime => down}
|
253
253
|
entity_presenter.should_receive(:downtime).with(nil, nil).and_return(result)
|
254
254
|
Flapjack::Gateways::API::EntityPresenter.should_receive(:new).
|
@@ -262,7 +262,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
262
262
|
end
|
263
263
|
|
264
264
|
it "returns a list of downtimes for a check on an entity" do
|
265
|
-
down =
|
265
|
+
down = double('down', :to_json => 'down!'.to_json)
|
266
266
|
entity_check_presenter.should_receive(:downtime).with(nil, nil).and_return(down)
|
267
267
|
Flapjack::Gateways::API::EntityCheckPresenter.should_receive(:new).
|
268
268
|
with(entity_check).and_return(entity_check_presenter)
|
@@ -298,7 +298,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
298
298
|
context 'bulk API calls' do
|
299
299
|
|
300
300
|
it "returns the status for all checks on an entity" do
|
301
|
-
status =
|
301
|
+
status = double('status')
|
302
302
|
result = [{:entity => entity_name, :check => check, :status => status}]
|
303
303
|
entity_presenter.should_receive(:status).and_return(result)
|
304
304
|
|
@@ -321,7 +321,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
321
321
|
end
|
322
322
|
|
323
323
|
it "returns the status for a check on an entity" do
|
324
|
-
status =
|
324
|
+
status = double('status')
|
325
325
|
result = [{:entity => entity_name, :check => check, :status => status}]
|
326
326
|
entity_check_presenter.should_receive(:status).and_return(status)
|
327
327
|
|
@@ -435,7 +435,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
435
435
|
it "deletes scheduled maintenance periods for multiple entity checks" do
|
436
436
|
start_time = Time.now + (60 * 60) # an hour from now
|
437
437
|
|
438
|
-
entity_check_2 =
|
438
|
+
entity_check_2 = double(Flapjack::Data::EntityCheck)
|
439
439
|
|
440
440
|
entity_check.should_receive(:end_scheduled_maintenance).with(start_time.to_i)
|
441
441
|
entity_check_2.should_receive(:end_scheduled_maintenance).with(start_time.to_i)
|
@@ -453,7 +453,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
453
453
|
end
|
454
454
|
|
455
455
|
it "returns a list of scheduled maintenance periods for an entity" do
|
456
|
-
sm =
|
456
|
+
sm = double('sched_maint')
|
457
457
|
result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}]
|
458
458
|
|
459
459
|
entity_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(result)
|
@@ -473,7 +473,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
473
473
|
start = Time.parse('1 Jan 2012')
|
474
474
|
finish = Time.parse('6 Jan 2012')
|
475
475
|
|
476
|
-
sm =
|
476
|
+
sm = double('sched_maint')
|
477
477
|
result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}]
|
478
478
|
|
479
479
|
entity_presenter.should_receive(:scheduled_maintenances).with(start.to_i, finish.to_i).and_return(result)
|
@@ -491,7 +491,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
491
491
|
end
|
492
492
|
|
493
493
|
it "returns a list of scheduled maintenance periods for a check on an entity" do
|
494
|
-
sm =
|
494
|
+
sm = double('sched_maint')
|
495
495
|
result = [{:entity => entity_name, :check => check, :scheduled_maintenances => sm}]
|
496
496
|
|
497
497
|
entity_check_presenter.should_receive(:scheduled_maintenances).with(nil, nil).and_return(sm)
|
@@ -511,7 +511,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
511
511
|
end
|
512
512
|
|
513
513
|
it "returns a list of unscheduled maintenance periods for an entity" do
|
514
|
-
um =
|
514
|
+
um = double('unsched_maint')
|
515
515
|
result = [{:entity => entity_name, :check => check, :unscheduled_maintenances => um}]
|
516
516
|
|
517
517
|
entity_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(result)
|
@@ -528,7 +528,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
528
528
|
end
|
529
529
|
|
530
530
|
it "returns a list of unscheduled maintenance periods for a check on an entity" do
|
531
|
-
um =
|
531
|
+
um = double('unsched_maint')
|
532
532
|
result = [{:entity => entity_name, :check => check, :unscheduled_maintenances => um}]
|
533
533
|
|
534
534
|
entity_check_presenter.should_receive(:unscheduled_maintenances).with(nil, nil).and_return(um)
|
@@ -551,7 +551,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
551
551
|
start = Time.parse('1 Jan 2012')
|
552
552
|
finish = Time.parse('6 Jan 2012')
|
553
553
|
|
554
|
-
um =
|
554
|
+
um = double('unsched_maint')
|
555
555
|
result = [{:entity => entity_name, :check => check, :unscheduled_maintenances => um}]
|
556
556
|
|
557
557
|
entity_check_presenter.should_receive(:unscheduled_maintenances).with(start.to_i, finish.to_i).and_return(um)
|
@@ -572,22 +572,22 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
572
572
|
end
|
573
573
|
|
574
574
|
it "returns a list of outages, for one whole entity and two checks on another entity" do
|
575
|
-
outages_1 =
|
576
|
-
outages_2 =
|
577
|
-
outages_3 =
|
575
|
+
outages_1 = double('outages_1')
|
576
|
+
outages_2 = double('outages_2')
|
577
|
+
outages_3 = double('outages_3')
|
578
578
|
|
579
579
|
entity_2_name = 'entity_2'
|
580
|
-
entity_2 =
|
580
|
+
entity_2 = double(Flapjack::Data::Entity)
|
581
581
|
|
582
582
|
result = [{:entity => entity_name, :check => check, :outages => outages_1},
|
583
583
|
{:entity => entity_2_name, :check => 'foo', :outages => outages_2},
|
584
584
|
{:entity => entity_2_name, :check => 'bar', :outages => outages_3}]
|
585
585
|
|
586
|
-
foo_check =
|
587
|
-
bar_check =
|
586
|
+
foo_check = double(Flapjack::Data::EntityCheck)
|
587
|
+
bar_check = double(Flapjack::Data::EntityCheck)
|
588
588
|
|
589
|
-
foo_check_presenter =
|
590
|
-
bar_check_presenter =
|
589
|
+
foo_check_presenter = double(Flapjack::Gateways::API::EntityCheckPresenter)
|
590
|
+
bar_check_presenter = double(Flapjack::Gateways::API::EntityCheckPresenter)
|
591
591
|
|
592
592
|
entity_presenter.should_receive(:outages).with(nil, nil).and_return(result[0])
|
593
593
|
foo_check_presenter.should_receive(:outages).with(nil, nil).and_return(outages_2)
|
@@ -617,7 +617,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
617
617
|
end
|
618
618
|
|
619
619
|
it "returns a list of outages for a check on an entity" do
|
620
|
-
outages =
|
620
|
+
outages = double('outages')
|
621
621
|
result = [{:entity => entity_name, :check => check, :outages => outages}]
|
622
622
|
|
623
623
|
entity_check_presenter.should_receive(:outages).with(nil, nil).and_return(outages)
|
@@ -637,7 +637,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
637
637
|
end
|
638
638
|
|
639
639
|
it "returns a list of downtimes for an entity" do
|
640
|
-
downtime =
|
640
|
+
downtime = double('downtime')
|
641
641
|
result = [{:entity => entity_name, :check => check, :downtime => downtime}]
|
642
642
|
|
643
643
|
entity_presenter.should_receive(:downtime).with(nil, nil).and_return(result)
|
@@ -654,7 +654,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
654
654
|
end
|
655
655
|
|
656
656
|
it "returns a list of downtimes for a check on an entity" do
|
657
|
-
downtime =
|
657
|
+
downtime = double('downtime')
|
658
658
|
result = [{:entity => entity_name, :check => check, :downtime => downtime}]
|
659
659
|
|
660
660
|
entity_check_presenter.should_receive(:downtime).with(nil, nil).and_return(downtime)
|
@@ -686,7 +686,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
686
686
|
Flapjack::Data::EntityCheck.should_receive(:for_entity).
|
687
687
|
with(entity, check, :redis => redis).and_return(entity_check)
|
688
688
|
|
689
|
-
entity_check_2 =
|
689
|
+
entity_check_2 = double(Flapjack::Data::EntityCheck)
|
690
690
|
entity_check_2.should_receive(:entity).and_return(entity)
|
691
691
|
entity_check_2.should_receive(:entity_name).and_return(entity_name)
|
692
692
|
entity_check_2.should_receive(:check).and_return('foo')
|