flapjack 0.6.53 → 0.6.54
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.
- data/bin/flapjack +103 -19
- data/bin/flapjack-nagios-receiver +166 -52
- data/bin/flapper +107 -18
- data/etc/flapjack_config.yaml.example +16 -0
- data/features/events.feature +63 -0
- data/features/steps/events_steps.rb +5 -5
- data/features/steps/notifications_steps.rb +8 -6
- data/features/steps/time_travel_steps.rb +4 -4
- data/features/support/env.rb +1 -2
- data/flapjack.gemspec +1 -1
- data/lib/flapjack/configuration.rb +11 -13
- data/lib/flapjack/coordinator.rb +100 -220
- data/lib/flapjack/data/entity_check.rb +2 -2
- data/lib/flapjack/data/event.rb +3 -3
- data/lib/flapjack/executive.rb +30 -40
- data/lib/flapjack/filters/delays.rb +1 -1
- data/lib/flapjack/gateways/api.rb +6 -23
- data/lib/flapjack/gateways/email.rb +4 -10
- data/lib/flapjack/gateways/email/alert.html.haml +0 -5
- data/lib/flapjack/gateways/email/alert.text.erb +0 -1
- data/lib/flapjack/gateways/jabber.rb +80 -67
- data/lib/flapjack/gateways/oobetet.rb +29 -25
- data/lib/flapjack/gateways/pagerduty.rb +26 -45
- data/lib/flapjack/gateways/sms_messagenet.rb +10 -17
- data/lib/flapjack/gateways/web.rb +7 -21
- data/lib/flapjack/gateways/web/views/_css.haml +3 -0
- data/lib/flapjack/gateways/web/views/check.haml +1 -1
- data/lib/flapjack/logger.rb +57 -0
- data/lib/flapjack/patches.rb +0 -10
- data/lib/flapjack/pikelet.rb +214 -30
- data/lib/flapjack/redis_pool.rb +2 -17
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +116 -136
- data/spec/lib/flapjack/data/entity_check_spec.rb +3 -3
- data/spec/lib/flapjack/executive_spec.rb +33 -34
- data/spec/lib/flapjack/gateways/api_spec.rb +4 -2
- data/spec/lib/flapjack/gateways/jabber_spec.rb +39 -36
- data/spec/lib/flapjack/gateways/oobetet_spec.rb +14 -24
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +43 -45
- data/spec/lib/flapjack/gateways/web_spec.rb +42 -35
- data/spec/lib/flapjack/logger_spec.rb +32 -0
- data/spec/lib/flapjack/pikelet_spec.rb +124 -15
- data/spec/lib/flapjack/redis_pool_spec.rb +1 -3
- data/spec/spec_helper.rb +34 -1
- data/tasks/events.rake +1 -0
- data/tmp/create_event_ok.rb +31 -0
- data/tmp/create_event_unknown.rb +31 -0
- data/tmp/create_events_ok.rb +1 -1
- metadata +10 -11
- data/bin/flapjack-nagios-receiver-control +0 -15
- data/bin/flapper-control +0 -15
- data/lib/flapjack/daemonizing.rb +0 -186
- data/lib/flapjack/gateways/base.rb +0 -38
@@ -485,6 +485,9 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
485
485
|
|
486
486
|
@redis.hset("check:#{name}:#{check}", 'state', 'critical')
|
487
487
|
ec.should be_failed
|
488
|
+
|
489
|
+
@redis.hset("check:#{name}:#{check}", 'state', 'unknown')
|
490
|
+
ec.should be_failed
|
488
491
|
end
|
489
492
|
|
490
493
|
it "returns that it has not failed" do
|
@@ -495,9 +498,6 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
495
498
|
|
496
499
|
@redis.hset("check:#{name}:#{check}", 'state', 'acknowledgement')
|
497
500
|
ec.should_not be_failed
|
498
|
-
|
499
|
-
@redis.hset("check:#{name}:#{check}", 'state', 'unknown')
|
500
|
-
ec.should_not be_failed
|
501
501
|
end
|
502
502
|
|
503
503
|
it "returns a status summary" do
|
@@ -1,21 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'flapjack/executive'
|
3
3
|
|
4
|
-
describe Flapjack::Executive, :
|
4
|
+
describe Flapjack::Executive, :logger => true do
|
5
5
|
|
6
6
|
# NB: this is only testing the public API of the Executive class, which is pretty limited.
|
7
7
|
# (initialize, main, stop). Most test coverage for this class comes from the cucumber features.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
redis.should_receive(:rpush).with('events', %q{{"type":"shutdown","host":"","service":"","state":""}})
|
12
|
-
|
13
|
-
executive = Flapjack::Executive.new
|
14
|
-
executive.add_shutdown_event(:redis => redis)
|
15
|
-
end
|
16
|
-
|
17
|
-
# TODO split out the setup stuff to a separate test
|
18
|
-
it "shuts down when provided with a shutdown event" do
|
9
|
+
# TODO this does too much -- split it up
|
10
|
+
it "starts up, runs and shuts down" do
|
19
11
|
t = Time.now.to_i
|
20
12
|
|
21
13
|
Flapjack::Filters::Ok.should_receive(:new)
|
@@ -25,35 +17,42 @@ describe Flapjack::Executive, :redis => true do
|
|
25
17
|
Flapjack::Filters::Delays.should_receive(:new)
|
26
18
|
Flapjack::Filters::Acknowledgement.should_receive(:new)
|
27
19
|
|
20
|
+
redis = mock('redis')
|
21
|
+
|
22
|
+
redis.should_receive(:set).with('boot_time', a_kind_of(Integer))
|
23
|
+
redis.should_receive(:hget).with('event_counters', 'all').and_return(nil)
|
24
|
+
redis.should_receive(:hset).with('event_counters', 'all', 0)
|
25
|
+
redis.should_receive(:hset).with('event_counters', 'ok', 0)
|
26
|
+
redis.should_receive(:hset).with('event_counters', 'failure', 0)
|
27
|
+
redis.should_receive(:hset).with('event_counters', 'action', 0)
|
28
|
+
|
29
|
+
redis.should_receive(:zadd).with('executive_instances', a_kind_of(Integer), a_kind_of(String))
|
30
|
+
redis.should_receive(:hset).with(/^event_counters:/, 'all', 0)
|
31
|
+
redis.should_receive(:hset).with(/^event_counters:/, 'ok', 0)
|
32
|
+
redis.should_receive(:hset).with(/^event_counters:/, 'failure', 0)
|
33
|
+
redis.should_receive(:hset).with(/^event_counters:/, 'action', 0)
|
34
|
+
|
35
|
+
redis.should_receive(:hincrby).with('event_counters', 'all', 1)
|
36
|
+
redis.should_receive(:hincrby).with(/^event_counters:/, 'all', 1)
|
37
|
+
|
38
|
+
Flapjack::Data::Event.should_receive(:pending_count).with(:redis => redis).and_return(0)
|
39
|
+
|
40
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
41
|
+
executive = Flapjack::Executive.new(:config => {}, :logger => @logger)
|
42
|
+
|
28
43
|
shutdown_evt = mock(Flapjack::Data::Event)
|
44
|
+
shutdown_evt.should_receive(:inspect)
|
29
45
|
shutdown_evt.should_receive(:id).and_return('-:-')
|
30
46
|
shutdown_evt.should_receive(:type).exactly(3).times.and_return('shutdown')
|
31
47
|
shutdown_evt.should_receive(:state).and_return(nil)
|
32
48
|
shutdown_evt.should_receive(:summary).and_return(nil)
|
33
49
|
shutdown_evt.should_receive(:time).and_return(Time.now)
|
34
|
-
Flapjack::Data::Event.should_receive(:next)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
# hacky, but the behaviour it's mimicking (shutdown from another thread) isn't
|
42
|
-
# conducive to nice tests
|
43
|
-
executive.stub(:should_quit?).and_return(false, true)
|
44
|
-
executive.main
|
45
|
-
executive.cleanup
|
46
|
-
|
47
|
-
# TODO these will need to be made relative to the running instance,
|
48
|
-
# and a list of the running instances maintained somewhere
|
49
|
-
boot_time = @redis.get('boot_time')
|
50
|
-
boot_time.should_not be_nil
|
51
|
-
boot_time.to_i.should >= t
|
52
|
-
|
53
|
-
@redis.hget('event_counters', 'all').should == 1.to_s
|
54
|
-
@redis.hget('event_counters', 'ok').should == 0.to_s
|
55
|
-
@redis.hget('event_counters', 'failure').should == 0.to_s
|
56
|
-
@redis.hget('event_counters', 'action').should == 0.to_s
|
50
|
+
Flapjack::Data::Event.should_receive(:next) {
|
51
|
+
executive.instance_variable_set('@should_quit', true)
|
52
|
+
shutdown_evt
|
53
|
+
}
|
54
|
+
|
55
|
+
executive.start
|
57
56
|
end
|
58
57
|
|
59
58
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'flapjack/gateways/api'
|
3
3
|
|
4
|
-
describe 'Flapjack::Gateways::API', :sinatra => true do
|
4
|
+
describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true do
|
5
5
|
|
6
6
|
def app
|
7
7
|
Flapjack::Gateways::API
|
@@ -21,7 +21,9 @@ describe 'Flapjack::Gateways::API', :sinatra => true do
|
|
21
21
|
|
22
22
|
before(:each) do
|
23
23
|
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
24
|
-
Flapjack::Gateways::API.
|
24
|
+
Flapjack::Gateways::API.instance_variable_set('@config', {})
|
25
|
+
Flapjack::Gateways::API.instance_variable_set('@logger', @logger)
|
26
|
+
Flapjack::Gateways::API.start
|
25
27
|
end
|
26
28
|
|
27
29
|
it "returns a list of checks for an entity" do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'flapjack/gateways/jabber'
|
3
3
|
|
4
|
-
describe Flapjack::Gateways::Jabber do
|
4
|
+
describe Flapjack::Gateways::Jabber, :logger => true do
|
5
5
|
|
6
6
|
let(:config) { {'queue' => 'jabber_notifications',
|
7
7
|
'server' => 'example.com',
|
@@ -18,9 +18,8 @@ describe Flapjack::Gateways::Jabber do
|
|
18
18
|
it "hooks up event handlers to the appropriate methods" do
|
19
19
|
Socket.should_receive(:gethostname).and_return('thismachine')
|
20
20
|
|
21
|
-
fj = Flapjack::Gateways::Jabber.new
|
22
21
|
Flapjack::RedisPool.should_receive(:new)
|
23
|
-
fj.
|
22
|
+
fj = Flapjack::Gateways::Jabber.new(:config => config, :logger => @logger)
|
24
23
|
|
25
24
|
EventMachine::Synchrony.should_receive(:next_tick).exactly(4).times.and_yield
|
26
25
|
|
@@ -40,11 +39,12 @@ describe Flapjack::Gateways::Jabber do
|
|
40
39
|
end
|
41
40
|
|
42
41
|
it "joins a chat room after connecting" do
|
43
|
-
|
44
|
-
Flapjack::RedisPool.should_receive(:new).twice
|
45
|
-
fj.bootstrap(:config => config)
|
42
|
+
Flapjack::RedisPool.should_receive(:new)
|
46
43
|
|
44
|
+
fj = Flapjack::Gateways::Jabber.new(:config => config, :logger => @logger)
|
47
45
|
fj.should_receive(:connected?).and_return(true)
|
46
|
+
|
47
|
+
EventMachine::Synchrony.should_receive(:next_tick).and_yield
|
48
48
|
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Presence))
|
49
49
|
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Message))
|
50
50
|
|
@@ -72,11 +72,10 @@ describe Flapjack::Gateways::Jabber do
|
|
72
72
|
with('main-example.com:ping', :redis => redis).
|
73
73
|
and_return(entity_check)
|
74
74
|
|
75
|
-
|
76
|
-
Flapjack::
|
77
|
-
fj.bootstrap(:config => config)
|
78
|
-
fj.instance_variable_set('@redis_handler', redis)
|
75
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
76
|
+
fj = Flapjack::Gateways::Jabber.new(:config => config, :logger => @logger)
|
79
77
|
|
78
|
+
EventMachine::Synchrony.should_receive(:next_tick).and_yield
|
80
79
|
fj.should_receive(:connected?).and_return(true)
|
81
80
|
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Message))
|
82
81
|
|
@@ -89,10 +88,10 @@ describe Flapjack::Gateways::Jabber do
|
|
89
88
|
from.should_receive(:stripped).and_return('sender')
|
90
89
|
stanza.should_receive(:from).and_return(from)
|
91
90
|
|
92
|
-
fj = Flapjack::Gateways::Jabber.new
|
93
91
|
Flapjack::RedisPool.should_receive(:new)
|
94
|
-
fj.
|
92
|
+
fj = Flapjack::Gateways::Jabber.new(:config => config, :logger => @logger)
|
95
93
|
|
94
|
+
EventMachine::Synchrony.should_receive(:next_tick).and_yield
|
96
95
|
fj.should_receive(:connected?).and_return(true)
|
97
96
|
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Message))
|
98
97
|
|
@@ -100,12 +99,16 @@ describe Flapjack::Gateways::Jabber do
|
|
100
99
|
end
|
101
100
|
|
102
101
|
it "reconnects when disconnected (if not quitting)" do
|
103
|
-
fj = Flapjack::Gateways::Jabber.new
|
104
102
|
Flapjack::RedisPool.should_receive(:new)
|
105
|
-
fj.
|
103
|
+
fj = Flapjack::Gateways::Jabber.new(:config => config, :logger => @logger)
|
106
104
|
|
107
|
-
|
108
|
-
|
105
|
+
attempts = 0
|
106
|
+
|
107
|
+
EventMachine::Synchrony.should_receive(:sleep).with(2).exactly(3).times
|
108
|
+
fj.should_receive(:connect).exactly(4).times.and_return {
|
109
|
+
attempts +=1
|
110
|
+
raise StandardError.new unless attempts > 3
|
111
|
+
}
|
109
112
|
|
110
113
|
ret = fj.on_disconnect(stanza)
|
111
114
|
ret.should be_true
|
@@ -115,43 +118,43 @@ describe Flapjack::Gateways::Jabber do
|
|
115
118
|
redis = mock('redis')
|
116
119
|
redis.should_receive(:rpush).with('jabber_notifications', %q{{"notification_type":"shutdown"}})
|
117
120
|
|
118
|
-
|
119
|
-
Flapjack::
|
120
|
-
fj.bootstrap(:config => config)
|
121
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
122
|
+
fj = Flapjack::Gateways::Jabber.new(:config => config, :logger => @logger)
|
121
123
|
|
122
|
-
fj.
|
124
|
+
fj.stop
|
123
125
|
end
|
124
126
|
|
125
127
|
it "runs a blocking loop listening for notifications" do
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
timer_2.should_receive(:cancel)
|
130
|
-
EM::Synchrony.should_receive(:add_periodic_timer).with(30).and_return(timer_1)
|
131
|
-
EM::Synchrony.should_receive(:add_periodic_timer).with(60).and_return(timer_2)
|
128
|
+
timer = mock('timer')
|
129
|
+
timer.should_receive(:cancel)
|
130
|
+
EM::Synchrony.should_receive(:add_periodic_timer).with(60).and_return(timer)
|
132
131
|
|
133
132
|
redis = mock('redis')
|
134
|
-
redis.should_receive(:empty!)
|
135
133
|
|
136
|
-
fj = Flapjack::Gateways::Jabber.new
|
137
134
|
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
138
|
-
fj.
|
135
|
+
fj = Flapjack::Gateways::Jabber.new(:config => config, :logger => @logger)
|
139
136
|
fj.should_receive(:register_handler).exactly(4).times
|
140
137
|
|
141
138
|
fj.should_receive(:connect)
|
142
139
|
fj.should_receive(:connected?).exactly(3).times.and_return(true)
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
140
|
+
|
141
|
+
blpop_count = 0
|
142
|
+
|
143
|
+
redis.should_receive(:blpop).twice {
|
144
|
+
blpop_count += 1
|
145
|
+
if blpop_count == 1
|
146
|
+
["jabber_notifications", %q{{"notification_type":"problem","event_id":"main-example.com:ping","state":"critical","summary":"!!!"}}]
|
147
|
+
else
|
148
|
+
fj.instance_variable_set('@should_quit', true)
|
149
|
+
["jabber_notifications", %q{{"notification_type":"shutdown"}}]
|
150
|
+
end
|
151
|
+
}
|
148
152
|
|
149
153
|
EventMachine::Synchrony.should_receive(:next_tick).twice.and_yield
|
150
154
|
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Message))
|
151
155
|
fj.should_receive(:close)
|
152
156
|
|
153
|
-
fj.
|
154
|
-
fj.cleanup
|
157
|
+
fj.start
|
155
158
|
end
|
156
159
|
|
157
160
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'flapjack/gateways/oobetet'
|
3
3
|
|
4
|
-
describe Flapjack::Gateways::Oobetet do
|
4
|
+
describe Flapjack::Gateways::Oobetet, :logger => true do
|
5
5
|
|
6
6
|
let(:config) { {'server' => 'example.com',
|
7
7
|
'port' => '5222',
|
@@ -19,8 +19,7 @@ describe Flapjack::Gateways::Oobetet do
|
|
19
19
|
it "raises an error if a required config setting is not set" do
|
20
20
|
Socket.should_receive(:gethostname).and_return('thismachine')
|
21
21
|
|
22
|
-
fo = Flapjack::Gateways::Oobetet.new
|
23
|
-
fo.bootstrap(:config => config.delete('watched_check'))
|
22
|
+
fo = Flapjack::Gateways::Oobetet.new(:config => config.delete('watched_check'), :logger => @logger)
|
24
23
|
|
25
24
|
lambda {
|
26
25
|
fo.setup
|
@@ -28,8 +27,7 @@ describe Flapjack::Gateways::Oobetet do
|
|
28
27
|
end
|
29
28
|
|
30
29
|
it "hooks up event handlers to the appropriate methods" do
|
31
|
-
fo = Flapjack::Gateways::Oobetet.new
|
32
|
-
fo.bootstrap(:config => config)
|
30
|
+
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
33
31
|
|
34
32
|
EventMachine::Synchrony.should_receive(:next_tick).exactly(3).times.and_yield
|
35
33
|
|
@@ -46,8 +44,7 @@ describe Flapjack::Gateways::Oobetet do
|
|
46
44
|
end
|
47
45
|
|
48
46
|
it "joins a chat room after connecting" do
|
49
|
-
fo = Flapjack::Gateways::Oobetet.new
|
50
|
-
fo.bootstrap(:config => config)
|
47
|
+
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
51
48
|
|
52
49
|
fo.should_receive(:write).with(an_instance_of(Blather::Stanza::Presence))
|
53
50
|
fo.should_receive(:write).with(an_instance_of(Blather::Stanza::Message))
|
@@ -56,8 +53,7 @@ describe Flapjack::Gateways::Oobetet do
|
|
56
53
|
end
|
57
54
|
|
58
55
|
it "reconnects when disconnected (if not quitting)" do
|
59
|
-
fo = Flapjack::Gateways::Oobetet.new
|
60
|
-
fo.bootstrap(:config => config)
|
56
|
+
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
61
57
|
|
62
58
|
EventMachine::Timer.should_receive(:new).with(1).and_yield
|
63
59
|
fo.should_receive(:connect)
|
@@ -67,9 +63,7 @@ describe Flapjack::Gateways::Oobetet do
|
|
67
63
|
end
|
68
64
|
|
69
65
|
it "records times of a problem status messages" do
|
70
|
-
fo = Flapjack::Gateways::Oobetet.new
|
71
|
-
fo.bootstrap(:config => config)
|
72
|
-
|
66
|
+
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
73
67
|
fo.setup
|
74
68
|
|
75
69
|
t = Time.now
|
@@ -85,9 +79,7 @@ describe Flapjack::Gateways::Oobetet do
|
|
85
79
|
end
|
86
80
|
|
87
81
|
it "records times of a recovery status messages" do
|
88
|
-
fo = Flapjack::Gateways::Oobetet.new
|
89
|
-
fo.bootstrap(:config => config)
|
90
|
-
|
82
|
+
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
91
83
|
fo.setup
|
92
84
|
|
93
85
|
t = Time.now
|
@@ -103,9 +95,7 @@ describe Flapjack::Gateways::Oobetet do
|
|
103
95
|
end
|
104
96
|
|
105
97
|
it "records times of an acknowledgement status messages" do
|
106
|
-
fo = Flapjack::Gateways::Oobetet.new
|
107
|
-
fo.bootstrap(:config => config)
|
108
|
-
|
98
|
+
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
109
99
|
fo.setup
|
110
100
|
|
111
101
|
t = Time.now
|
@@ -125,16 +115,16 @@ describe Flapjack::Gateways::Oobetet do
|
|
125
115
|
timer.should_receive(:cancel)
|
126
116
|
EM::Synchrony.should_receive(:add_periodic_timer).with(60).and_return(timer)
|
127
117
|
|
128
|
-
fo = Flapjack::Gateways::Oobetet.new
|
129
|
-
fo.bootstrap(:config => config)
|
118
|
+
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
130
119
|
fo.should_receive(:register_handler).exactly(3).times
|
131
|
-
|
132
120
|
fo.should_receive(:connect)
|
133
|
-
fo.should_receive(:should_quit?).twice.and_return(false, true)
|
134
121
|
|
135
|
-
EM::Synchrony.should_receive(:sleep).with(10)
|
122
|
+
EM::Synchrony.should_receive(:sleep).with(10) {
|
123
|
+
fo.instance_variable_set('@should_quit', true)
|
124
|
+
nil
|
125
|
+
}
|
136
126
|
|
137
|
-
fo.
|
127
|
+
fo.start
|
138
128
|
end
|
139
129
|
|
140
130
|
end
|
@@ -4,39 +4,40 @@ require 'yajl/json_gem'
|
|
4
4
|
|
5
5
|
require 'flapjack/gateways/pagerduty'
|
6
6
|
|
7
|
-
describe Flapjack::Gateways::Pagerduty, :
|
7
|
+
describe Flapjack::Gateways::Pagerduty, :logger => true do
|
8
8
|
|
9
9
|
let(:config) { {'queue' => 'pagerduty_notifications'} }
|
10
10
|
|
11
11
|
let(:time) { Time.new }
|
12
12
|
|
13
|
+
let(:redis) { mock('redis') }
|
14
|
+
|
13
15
|
it "prompts the blocking redis connection to quit" do
|
14
|
-
redis = mock('redis')
|
15
16
|
redis.should_receive(:rpush).with(config['queue'], %q{{"notification_type":"shutdown"}})
|
16
17
|
|
17
|
-
|
18
|
-
Flapjack::
|
19
|
-
fp.
|
20
|
-
fp.add_shutdown_event(:redis => redis)
|
18
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
19
|
+
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
20
|
+
fp.stop
|
21
21
|
end
|
22
22
|
|
23
23
|
it "doesn't look for acknowledgements if this search is already running" do
|
24
|
-
|
25
|
-
|
26
|
-
fp = Flapjack::Gateways::Pagerduty.new
|
27
|
-
Flapjack::RedisPool.should_receive(:new)
|
28
|
-
fp.bootstrap(:config => config)
|
29
|
-
fp.instance_variable_set("@redis_timer", @redis)
|
24
|
+
redis.should_receive(:get).with('sem_pagerduty_acks_running').and_return('true')
|
25
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
26
|
+
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
30
27
|
|
31
28
|
fp.should_not_receive(:find_pagerduty_acknowledgements)
|
32
29
|
fp.find_pagerduty_acknowledgements_if_safe
|
33
30
|
end
|
34
31
|
|
35
32
|
it "looks for acknowledgements if the search is not already running" do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
redis.should_receive(:get).with('sem_pagerduty_acks_running').and_return(nil)
|
34
|
+
redis.should_receive(:set).with('sem_pagerduty_acks_running', 'true')
|
35
|
+
redis.should_receive(:expire).with('sem_pagerduty_acks_running', 300)
|
36
|
+
|
37
|
+
redis.should_receive(:del).with('sem_pagerduty_acks_running')
|
38
|
+
|
39
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
40
|
+
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
40
41
|
|
41
42
|
fp.should_receive(:find_pagerduty_acknowledgements)
|
42
43
|
fp.find_pagerduty_acknowledgements_if_safe
|
@@ -71,11 +72,11 @@ describe Flapjack::Gateways::Pagerduty, :redis => true do
|
|
71
72
|
with(:headers => {'Authorization'=>['flapjack', 'password123']}).
|
72
73
|
to_return(:status => 200, :body => response.to_json, :headers => {})
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
fp.bootstrap(:config => config)
|
75
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
76
|
+
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
77
|
+
|
78
78
|
|
79
|
+
EM.synchrony do
|
79
80
|
result = fp.send(:pagerduty_acknowledged?, 'subdomain' => 'flpjck', 'username' => 'flapjack',
|
80
81
|
'password' => 'password123', 'check' => check)
|
81
82
|
|
@@ -86,12 +87,12 @@ describe Flapjack::Gateways::Pagerduty, :redis => true do
|
|
86
87
|
result[:pg_acknowledged_by]['id'].should == 'ABCDEFG'
|
87
88
|
EM.stop
|
88
89
|
end
|
90
|
+
|
89
91
|
end
|
90
92
|
|
91
93
|
it "creates acknowledgements when pagerduty acknowledgements are found" do
|
92
|
-
|
93
|
-
Flapjack::
|
94
|
-
fp.bootstrap(:config => config)
|
94
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
95
|
+
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
95
96
|
|
96
97
|
contact = mock('contact')
|
97
98
|
contact.should_receive(:pagerduty_credentials).and_return({
|
@@ -119,25 +120,27 @@ describe Flapjack::Gateways::Pagerduty, :redis => true do
|
|
119
120
|
timer.should_receive(:cancel)
|
120
121
|
EM::Synchrony.should_receive(:add_periodic_timer).with(10).and_return(timer)
|
121
122
|
|
122
|
-
redis = mock('redis')
|
123
123
|
redis.should_receive(:del).with('sem_pagerduty_acks_running')
|
124
|
-
redis.should_receive(:empty!)
|
125
124
|
|
126
|
-
fp = Flapjack::Gateways::Pagerduty.new
|
127
125
|
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
128
|
-
fp.
|
126
|
+
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
127
|
+
|
128
|
+
blpop_count = 0
|
129
129
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
130
|
+
redis.should_receive(:blpop).twice {
|
131
|
+
blpop_count += 1
|
132
|
+
if blpop_count == 1
|
133
|
+
["pagerduty_notifications", %q{{"notification_type":"problem","event_id":"main-example.com:ping","state":"critical","summary":"!!!"}}]
|
134
|
+
else
|
135
|
+
fp.instance_variable_set('@should_quit', true)
|
136
|
+
["pagerduty_notifications", %q{{"notification_type":"shutdown"}}]
|
137
|
+
end
|
138
|
+
}
|
135
139
|
|
136
140
|
fp.should_receive(:test_pagerduty_connection).and_return(true)
|
137
141
|
fp.should_receive(:send_pagerduty_event)
|
138
142
|
|
139
|
-
fp.
|
140
|
-
fp.cleanup
|
143
|
+
fp.start
|
141
144
|
end
|
142
145
|
|
143
146
|
it "tests the pagerduty connection" do
|
@@ -150,14 +153,12 @@ describe Flapjack::Gateways::Pagerduty, :redis => true do
|
|
150
153
|
stub_request(:post, "https://events.pagerduty.com/generic/2010-04-15/create_event.json").
|
151
154
|
with(:body => body).to_return(:status => 200, :body => '{"status":"success"}', :headers => {})
|
152
155
|
|
153
|
-
|
154
|
-
|
155
|
-
Flapjack::RedisPool.should_receive(:new)
|
156
|
-
fp.bootstrap(:config => config)
|
156
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
157
|
+
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
157
158
|
|
159
|
+
EM.synchrony do
|
158
160
|
ret = fp.send(:test_pagerduty_connection)
|
159
161
|
ret.should be_true
|
160
|
-
|
161
162
|
EM.stop
|
162
163
|
end
|
163
164
|
end
|
@@ -172,16 +173,13 @@ describe Flapjack::Gateways::Pagerduty, :redis => true do
|
|
172
173
|
stub_request(:post, "https://events.pagerduty.com/generic/2010-04-15/create_event.json").
|
173
174
|
with(:body => body).to_return(:status => 200, :body => "", :headers => {})
|
174
175
|
|
175
|
-
|
176
|
-
|
177
|
-
fp = Flapjack::Gateways::Pagerduty.new
|
178
|
-
Flapjack::RedisPool.should_receive(:new)
|
179
|
-
fp.bootstrap(:config => config)
|
176
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
177
|
+
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
180
178
|
|
179
|
+
EM.synchrony do
|
181
180
|
ret = fp.send(:send_pagerduty_event, evt)
|
182
181
|
ret.should_not be_nil
|
183
182
|
ret.should == [200, nil]
|
184
|
-
|
185
183
|
EM.stop
|
186
184
|
end
|
187
185
|
end
|