flapjack 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/etc/flapjack_config.yaml.example +2 -0
- data/features/notification_rules.feature +4 -4
- data/features/steps/events_steps.rb +28 -15
- data/lib/flapjack/coordinator.rb +9 -1
- data/lib/flapjack/data/contact.rb +1 -0
- data/lib/flapjack/data/notification_rule.rb +197 -93
- data/lib/flapjack/executive.rb +11 -20
- data/lib/flapjack/gateways/api.rb +247 -363
- data/lib/flapjack/gateways/web.rb +28 -16
- data/lib/flapjack/gateways/web/views/_foot.haml +2 -2
- data/lib/flapjack/gateways/web/views/entity.haml +8 -2
- data/lib/flapjack/gateways/web/views/self_stats.haml +1 -1
- data/lib/flapjack/patches.rb +20 -1
- data/lib/flapjack/pikelet.rb +5 -14
- data/lib/flapjack/utility.rb +16 -0
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +29 -0
- data/spec/lib/flapjack/data/contact_spec.rb +1 -4
- data/spec/lib/flapjack/data/notification_rule_spec.rb +102 -9
- data/spec/lib/flapjack/gateways/api_spec.rb +9 -11
- data/spec/lib/flapjack/gateways/web_spec.rb +15 -19
- data/spec/lib/flapjack/pikelet_spec.rb +2 -56
- metadata +8 -2
@@ -393,7 +393,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
|
|
393
393
|
Flapjack::Data::Entity.should_receive(:add).twice
|
394
394
|
|
395
395
|
post "/entities", entities.to_json, {'CONTENT_TYPE' => 'application/json'}
|
396
|
-
last_response.status.should ==
|
396
|
+
last_response.status.should == 204
|
397
397
|
end
|
398
398
|
|
399
399
|
it "does not create entities if the data is improperly formatted" do
|
@@ -419,7 +419,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
|
|
419
419
|
Flapjack::Data::Entity.should_receive(:add)
|
420
420
|
|
421
421
|
post "/entities", entities.to_json, {'CONTENT_TYPE' => 'application/json'}
|
422
|
-
last_response.status.should ==
|
422
|
+
last_response.status.should == 403
|
423
423
|
end
|
424
424
|
|
425
425
|
it "creates contacts from a submitted list" do
|
@@ -442,7 +442,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
|
|
442
442
|
Flapjack::Data::Contact.should_receive(:add).twice
|
443
443
|
|
444
444
|
post "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
445
|
-
last_response.status.should ==
|
445
|
+
last_response.status.should == 204
|
446
446
|
end
|
447
447
|
|
448
448
|
it "does not create contacts if the data is improperly formatted" do
|
@@ -472,7 +472,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
|
|
472
472
|
Flapjack::Data::Contact.should_receive(:add)
|
473
473
|
|
474
474
|
post "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
475
|
-
last_response.status.should ==
|
475
|
+
last_response.status.should == 204
|
476
476
|
end
|
477
477
|
|
478
478
|
it "updates a contact if it is already present" do
|
@@ -499,7 +499,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
|
|
499
499
|
Flapjack::Data::Contact.should_receive(:add).with(contacts['contacts'][0], :redis => redis)
|
500
500
|
|
501
501
|
post "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
502
|
-
last_response.status.should ==
|
502
|
+
last_response.status.should == 204
|
503
503
|
end
|
504
504
|
|
505
505
|
it "deletes a contact not found in a bulk update list" do
|
@@ -520,7 +520,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
|
|
520
520
|
Flapjack::Data::Contact.should_receive(:add).with(contacts['contacts'][0], :redis => redis)
|
521
521
|
|
522
522
|
post "/contacts", contacts.to_json, {'CONTENT_TYPE' => 'application/json'}
|
523
|
-
last_response.status.should ==
|
523
|
+
last_response.status.should == 204
|
524
524
|
end
|
525
525
|
|
526
526
|
it "returns all the contacts" do
|
@@ -624,8 +624,6 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
|
|
624
624
|
|
625
625
|
it "does not create a notification_rule if a rule id is provided" do
|
626
626
|
contact.should_not_receive(:add_notification_rule)
|
627
|
-
Flapjack::Data::Contact.should_receive(:find_by_id).
|
628
|
-
with(contact.id, :redis => redis).and_return(contact)
|
629
627
|
|
630
628
|
post "/notification_rules", notification_rule_data.merge(:id => 1).to_json,
|
631
629
|
{'CONTENT_TYPE' => 'application/json'}
|
@@ -646,7 +644,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
|
|
646
644
|
}
|
647
645
|
notification_rule_data_sym.delete(:contact_id)
|
648
646
|
|
649
|
-
notification_rule.should_receive(:update).with(notification_rule_data_sym)
|
647
|
+
notification_rule.should_receive(:update).with(notification_rule_data_sym).and_return(true)
|
650
648
|
|
651
649
|
put "/notification_rules/#{notification_rule.id}", notification_rule_data.to_json,
|
652
650
|
{'CONTENT_TYPE' => 'application/json'}
|
@@ -655,8 +653,6 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
|
|
655
653
|
end
|
656
654
|
|
657
655
|
it "does not update a notification rule that's not present" do
|
658
|
-
Flapjack::Data::Contact.should_receive(:find_by_id).
|
659
|
-
with(contact.id, :redis => redis).and_return(contact)
|
660
656
|
Flapjack::Data::NotificationRule.should_receive(:find_by_id).
|
661
657
|
with(notification_rule.id, :redis => redis).and_return(nil)
|
662
658
|
|
@@ -665,6 +661,8 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
|
|
665
661
|
end
|
666
662
|
|
667
663
|
it "does not update a notification_rule for a contact that's not present" do
|
664
|
+
Flapjack::Data::NotificationRule.should_receive(:find_by_id).
|
665
|
+
with(notification_rule.id, :redis => redis).and_return(notification_rule)
|
668
666
|
Flapjack::Data::Contact.should_receive(:find_by_id).
|
669
667
|
with(contact.id, :redis => redis).and_return(nil)
|
670
668
|
|
@@ -34,9 +34,7 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def expect_stats
|
37
|
-
redis.should_receive(:
|
38
|
-
redis.should_receive(:keys).with('check:*:*').and_return([])
|
39
|
-
redis.should_receive(:zcard).with('failed_checks')
|
37
|
+
redis.should_receive(:dbsize).and_return(3)
|
40
38
|
redis.should_receive(:keys).with('executive_instance:*').and_return(["executive_instance:foo-app-01"])
|
41
39
|
redis.should_receive(:hget).twice.and_return(Time.now.to_i - 60)
|
42
40
|
redis.should_receive(:hgetall).twice.and_return({'all' => '8001', 'ok' => '8002'},
|
@@ -44,6 +42,14 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
44
42
|
redis.should_receive(:llen).with('events')
|
45
43
|
end
|
46
44
|
|
45
|
+
def expect_check_stats
|
46
|
+
redis.should_receive(:keys).with('check:*:*').and_return([])
|
47
|
+
redis.should_receive(:zcard).with('failed_checks')
|
48
|
+
end
|
49
|
+
|
50
|
+
def expect_entity_stats
|
51
|
+
end
|
52
|
+
|
47
53
|
def expect_entity_check_status(ec)
|
48
54
|
time = Time.now.to_i
|
49
55
|
|
@@ -62,11 +68,8 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
62
68
|
|
63
69
|
it "shows a page listing all checks" do
|
64
70
|
redis.should_receive(:keys).with('*:*:states').and_return(["#{entity_name}:#{check}:states"])
|
65
|
-
redis.should_receive(:keys).with('check:*').and_return(["#{entity_name}:#{check}:states"])
|
66
|
-
|
67
|
-
expect_stats
|
68
71
|
|
69
|
-
|
72
|
+
expect_check_stats
|
70
73
|
|
71
74
|
expect_entity_check_status(entity_check)
|
72
75
|
|
@@ -81,10 +84,9 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
81
84
|
end
|
82
85
|
|
83
86
|
it "shows a page listing failing checks" do
|
84
|
-
redis.should_receive(:zrange).with('failed_checks', 0, -1).
|
85
|
-
redis.should_receive(:keys).with('check:*').and_return(["#{entity_name}:#{check}:states"])
|
87
|
+
redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"])
|
86
88
|
|
87
|
-
|
89
|
+
expect_check_stats
|
88
90
|
|
89
91
|
expect_entity_check_status(entity_check)
|
90
92
|
|
@@ -101,6 +103,8 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
101
103
|
redis.should_receive(:keys).with('check:*').and_return([])
|
102
104
|
redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"])
|
103
105
|
expect_stats
|
106
|
+
expect_check_stats
|
107
|
+
expect_entity_stats
|
104
108
|
|
105
109
|
get '/self_stats'
|
106
110
|
last_response.should be_ok
|
@@ -113,9 +117,7 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
113
117
|
:recovery => time - (3 * 60 * 60),
|
114
118
|
:acknowledgement => nil }
|
115
119
|
|
116
|
-
|
117
|
-
redis.should_receive(:keys).with('check:*').and_return([])
|
118
|
-
redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return([])
|
120
|
+
expect_check_stats
|
119
121
|
entity_check.should_receive(:state).and_return('ok')
|
120
122
|
entity_check.should_receive(:last_update).and_return(time - (3 * 60 * 60))
|
121
123
|
entity_check.should_receive(:last_change).and_return(time - (3 * 60 * 60))
|
@@ -235,9 +237,6 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
235
237
|
|
236
238
|
it "shows a list of all known contacts" do
|
237
239
|
Flapjack::Data::Contact.should_receive(:all)
|
238
|
-
redis.should_receive(:keys).with('check:*').and_return([])
|
239
|
-
redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"])
|
240
|
-
expect_stats
|
241
240
|
|
242
241
|
get "/contacts"
|
243
242
|
last_response.should be_ok
|
@@ -249,9 +248,6 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
249
248
|
contact.should_receive(:media).exactly(3).times.and_return({})
|
250
249
|
contact.should_receive(:entities).with(:checks => true).and_return([])
|
251
250
|
contact.should_receive(:notification_rules).and_return([])
|
252
|
-
redis.should_receive(:keys).with('check:*').and_return([])
|
253
|
-
redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"])
|
254
|
-
expect_stats
|
255
251
|
|
256
252
|
Flapjack::Data::Contact.should_receive(:find_by_id).
|
257
253
|
with('0362', :redis => redis).and_return(contact)
|
@@ -33,27 +33,6 @@ describe Flapjack::Pikelet do
|
|
33
33
|
pik.start
|
34
34
|
end
|
35
35
|
|
36
|
-
it "handles an exception raised by a jabber pikelet" do
|
37
|
-
Flapjack::Logger.should_receive(:new).and_return(logger)
|
38
|
-
logger.should_receive(:fatal)
|
39
|
-
|
40
|
-
config.should_receive(:[]).with('logger').and_return(nil)
|
41
|
-
|
42
|
-
jabber = mock('jabber')
|
43
|
-
jabber.should_receive(:start).and_raise(RuntimeError)
|
44
|
-
jabber.should_receive(:stop)
|
45
|
-
Flapjack::Gateways::Jabber.should_receive(:new).with(:config => config,
|
46
|
-
:redis_config => redis_config, :logger => logger).and_return(jabber)
|
47
|
-
|
48
|
-
fiber.should_receive(:resume)
|
49
|
-
Fiber.should_receive(:new).and_yield.and_return(fiber)
|
50
|
-
|
51
|
-
pik = Flapjack::Pikelet.create('jabber', :config => config,
|
52
|
-
:redis_config => redis_config)
|
53
|
-
pik.should be_a(Flapjack::Pikelet::Generic)
|
54
|
-
pik.start
|
55
|
-
end
|
56
|
-
|
57
36
|
it "creates and starts a resque worker gateway" do
|
58
37
|
Flapjack::Logger.should_receive(:new).and_return(logger)
|
59
38
|
|
@@ -85,48 +64,15 @@ describe Flapjack::Pikelet do
|
|
85
64
|
pik.start
|
86
65
|
end
|
87
66
|
|
88
|
-
|
89
|
-
it "handles an exception raised by a resque worker gateway" do
|
90
|
-
|
91
|
-
Flapjack::Logger.should_receive(:new).and_return(logger)
|
92
|
-
logger.should_receive(:fatal)
|
93
|
-
|
94
|
-
config.should_receive(:[]).with('logger').and_return(nil)
|
95
|
-
config.should_receive(:[]).with('queue').and_return('email_notif')
|
96
|
-
|
97
|
-
redis = mock('redis')
|
98
|
-
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
99
|
-
Resque.should_receive(:redis=).with( redis )
|
100
|
-
|
101
|
-
Flapjack::Gateways::Email.should_receive(:instance_variable_set).
|
102
|
-
with('@config', config)
|
103
|
-
Flapjack::Gateways::Email.should_receive(:instance_variable_set).
|
104
|
-
with('@redis_config', redis_config)
|
105
|
-
Flapjack::Gateways::Email.should_receive(:instance_variable_set).
|
106
|
-
with('@logger', logger)
|
107
|
-
|
108
|
-
worker = mock('worker')
|
109
|
-
worker.should_receive(:work).with(0.1).and_raise(RuntimeError)
|
110
|
-
Flapjack::Gateways::Email.should_receive(:start)
|
111
|
-
Flapjack::Gateways::Email.should_receive(:stop)
|
112
|
-
EM::Resque::Worker.should_receive(:new).with('email_notif').and_return(worker)
|
113
|
-
|
114
|
-
fiber.should_receive(:resume)
|
115
|
-
Fiber.should_receive(:new).and_yield.and_return(fiber)
|
116
|
-
|
117
|
-
pik = Flapjack::Pikelet.create('email', :config => config,
|
118
|
-
:redis_config => redis_config)
|
119
|
-
pik.should be_a(Flapjack::Pikelet::Resque)
|
120
|
-
pik.start
|
121
|
-
end
|
122
|
-
|
123
67
|
it "creates a thin server gateway" do
|
124
68
|
Flapjack::Logger.should_receive(:new).and_return(logger)
|
125
69
|
|
126
70
|
config.should_receive(:[]).with('logger').and_return(nil)
|
127
71
|
config.should_receive(:[]).with('port').and_return(7654)
|
72
|
+
config.should_receive(:[]).with('timeout').and_return(90)
|
128
73
|
|
129
74
|
server = mock('server')
|
75
|
+
server.should_receive(:timeout=).with(90)
|
130
76
|
server.should_receive(:start)
|
131
77
|
Thin::Server.should_receive(:new).
|
132
78
|
with(/^(?:\d{1,3}\.){3}\d{1,3}$/, 7654,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flapjack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-05-
|
14
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: dante
|
@@ -551,12 +551,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
551
551
|
- - ! '>='
|
552
552
|
- !ruby/object:Gem::Version
|
553
553
|
version: '0'
|
554
|
+
segments:
|
555
|
+
- 0
|
556
|
+
hash: 2332608677203659919
|
554
557
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
555
558
|
none: false
|
556
559
|
requirements:
|
557
560
|
- - ! '>='
|
558
561
|
- !ruby/object:Gem::Version
|
559
562
|
version: '0'
|
563
|
+
segments:
|
564
|
+
- 0
|
565
|
+
hash: 2332608677203659919
|
560
566
|
requirements: []
|
561
567
|
rubyforge_project:
|
562
568
|
rubygems_version: 1.8.23
|