flapjack 0.7.35 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -1
- data/Gemfile +3 -4
- data/Guardfile +1 -1
- data/README.md +38 -19
- data/Rakefile +1 -3
- data/etc/flapjack_config.yaml.example +11 -1
- data/features/steps/cli_steps.rb +3 -3
- data/features/steps/events_steps.rb +7 -6
- data/features/steps/flapjack-netsaint-parser_steps.rb +8 -8
- data/features/steps/notifications_steps.rb +10 -10
- data/features/steps/packaging-lintian_steps.rb +5 -9
- data/features/steps/time_travel_steps.rb +1 -1
- data/flapjack.gemspec +4 -3
- data/lib/flapjack/data/contact.rb +78 -6
- data/lib/flapjack/data/entity.rb +11 -2
- data/lib/flapjack/data/notification_rule.rb +67 -59
- data/lib/flapjack/data/semaphore.rb +44 -0
- data/lib/flapjack/gateways/api.rb +24 -28
- data/lib/flapjack/gateways/api/contact_methods.rb +1 -2
- data/lib/flapjack/gateways/api/entity_methods.rb +3 -3
- data/lib/flapjack/gateways/jsonapi.rb +249 -0
- data/lib/flapjack/gateways/jsonapi/contact_methods.rb +544 -0
- data/lib/flapjack/gateways/jsonapi/entity_check_presenter.rb +217 -0
- data/lib/flapjack/gateways/jsonapi/entity_methods.rb +350 -0
- data/lib/flapjack/gateways/jsonapi/entity_presenter.rb +75 -0
- data/lib/flapjack/gateways/jsonapi/rack/json_params_parser.rb +32 -0
- data/lib/flapjack/gateways/web.rb +78 -12
- data/lib/flapjack/gateways/web/public/css/bootstrap-theme.css +397 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap-theme.min.css +7 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap.css +7118 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap.min.css +6 -8
- data/lib/flapjack/gateways/web/public/css/font-awesome.css +1338 -0
- data/lib/flapjack/gateways/web/public/css/font-awesome.min.css +4 -0
- data/lib/flapjack/gateways/web/public/css/screen.css +80 -0
- data/lib/flapjack/gateways/web/public/css/select2-bootstrap.css +87 -0
- data/lib/flapjack/gateways/web/public/css/select2.css +615 -0
- data/lib/flapjack/gateways/web/public/fonts/FontAwesome.otf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.eot +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.svg +414 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/fontawesome-webfont.woff +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.svg +229 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/flapjack/gateways/web/public/img/flapjack-2013-notext-transparent-300-300.png +0 -0
- data/lib/flapjack/gateways/web/public/img/select2.png +0 -0
- data/lib/flapjack/gateways/web/public/img/select2x2.png +0 -0
- data/lib/flapjack/gateways/web/public/js/backbone-min.js +2 -0
- data/lib/flapjack/gateways/web/public/js/backbone.js +1581 -0
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +75 -0
- data/lib/flapjack/gateways/web/public/js/bootstrap.js +2276 -0
- data/lib/flapjack/gateways/web/public/js/contacts.js +225 -0
- data/lib/flapjack/gateways/web/public/js/jquery-1.10.2.js +9789 -0
- data/lib/flapjack/gateways/web/public/js/jquery-1.10.2.min.js +6 -0
- data/lib/flapjack/gateways/web/public/js/select2.js +3255 -0
- data/lib/flapjack/gateways/web/public/js/select2.min.js +22 -0
- data/lib/flapjack/gateways/web/public/js/underscore-min.js +6 -0
- data/lib/flapjack/gateways/web/public/js/underscore.js +1276 -0
- data/lib/flapjack/gateways/web/views/check.html.erb +423 -193
- data/lib/flapjack/gateways/web/views/checks.html.erb +51 -71
- data/lib/flapjack/gateways/web/views/contact.html.erb +142 -164
- data/lib/flapjack/gateways/web/views/contacts.html.erb +20 -40
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +83 -0
- data/lib/flapjack/gateways/web/views/entities.html.erb +18 -37
- data/lib/flapjack/gateways/web/views/entity.html.erb +46 -65
- data/lib/flapjack/gateways/web/views/index.html.erb +6 -27
- data/lib/flapjack/gateways/web/views/layout.erb +95 -0
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +100 -114
- data/lib/flapjack/pikelet.rb +4 -2
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +120 -120
- data/spec/lib/flapjack/data/contact_spec.rb +66 -58
- data/spec/lib/flapjack/data/entity_check_spec.rb +179 -179
- data/spec/lib/flapjack/data/entity_spec.rb +71 -71
- data/spec/lib/flapjack/data/event_spec.rb +34 -30
- data/spec/lib/flapjack/data/message_spec.rb +6 -6
- data/spec/lib/flapjack/data/notification_rule_spec.rb +24 -24
- data/spec/lib/flapjack/data/notification_spec.rb +19 -19
- data/spec/lib/flapjack/data/semaphore_spec.rb +24 -0
- data/spec/lib/flapjack/data/tag_spec.rb +11 -10
- data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +201 -201
- data/spec/lib/flapjack/gateways/api/entity_check_presenter_spec.rb +55 -55
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +257 -257
- data/spec/lib/flapjack/gateways/api/entity_presenter_spec.rb +26 -26
- data/spec/lib/flapjack/gateways/api_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/email_spec.rb +4 -4
- data/spec/lib/flapjack/gateways/jabber_spec.rb +77 -77
- data/spec/lib/flapjack/gateways/jsonapi/contact_methods_spec.rb +830 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_check_presenter_spec.rb +211 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +863 -0
- data/spec/lib/flapjack/gateways/jsonapi/entity_presenter_spec.rb +108 -0
- data/spec/lib/flapjack/gateways/jsonapi_spec.rb +8 -0
- data/spec/lib/flapjack/gateways/oobetet_spec.rb +35 -35
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +40 -40
- data/spec/lib/flapjack/gateways/sms_messagenet_spec.rb +3 -3
- data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +5 -5
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/web_spec.rb +73 -74
- data/spec/lib/flapjack/logger_spec.rb +13 -13
- data/spec/lib/flapjack/pikelet_spec.rb +33 -33
- data/spec/lib/flapjack/processor_spec.rb +22 -22
- data/spec/lib/flapjack/redis_pool_spec.rb +1 -1
- data/spec/lib/flapjack/utility_spec.rb +12 -12
- data/spec/spec_helper.rb +9 -9
- data/spec/support/erb_view_helper.rb +4 -0
- metadata +107 -96
- data/lib/flapjack/gateways/web/public/css/flapjack.css +0 -49
- data/lib/flapjack/gateways/web/views/_css.html.erb +0 -42
- data/lib/flapjack/gateways/web/views/_foot.html.erb +0 -3
- data/lib/flapjack/gateways/web/views/_head.html.erb +0 -5
- data/lib/flapjack/gateways/web/views/_nav.html.erb +0 -10
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'flapjack/gateways/jsonapi/entity_presenter'
|
3
|
+
|
4
|
+
describe 'Flapjack::Gateways::JSONAPI::EntityPresenter' do
|
5
|
+
|
6
|
+
let(:entity) { double(Flapjack::Data::Entity) }
|
7
|
+
|
8
|
+
let(:check_a) { double(Flapjack::Data::EntityCheck) }
|
9
|
+
let(:check_b) { double(Flapjack::Data::EntityCheck) }
|
10
|
+
|
11
|
+
let(:checkpres_a) { double(Flapjack::Gateways::JSONAPI::EntityCheckPresenter) }
|
12
|
+
let(:checkpres_b) { double(Flapjack::Gateways::JSONAPI::EntityCheckPresenter) }
|
13
|
+
|
14
|
+
let(:time) { Time.now.to_i }
|
15
|
+
|
16
|
+
let(:start_time) { time - (6 * 60 * 60) }
|
17
|
+
let(:end_time) { time - (2 * 60 * 60) }
|
18
|
+
|
19
|
+
def expect_check_presenters
|
20
|
+
expect(entity).to receive(:name).exactly(4).times.and_return('foo')
|
21
|
+
expect(entity).to receive(:check_list).and_return(['ping', 'ssh'])
|
22
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
23
|
+
with(entity, 'ssh', anything).and_return(check_a)
|
24
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
25
|
+
with(entity, 'ping', anything).and_return(check_b)
|
26
|
+
|
27
|
+
expect(Flapjack::Gateways::JSONAPI::EntityCheckPresenter).to receive(:new).
|
28
|
+
with(check_a).and_return(checkpres_a)
|
29
|
+
expect(Flapjack::Gateways::JSONAPI::EntityCheckPresenter).to receive(:new).
|
30
|
+
with(check_b).and_return(checkpres_b)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns a list of status hashes for each check on an entity' do
|
34
|
+
expect_check_presenters
|
35
|
+
|
36
|
+
status_a = double('status_a')
|
37
|
+
status_b = double('status_b')
|
38
|
+
expect(checkpres_a).to receive(:status).and_return(status_a)
|
39
|
+
expect(checkpres_b).to receive(:status).and_return(status_b)
|
40
|
+
|
41
|
+
ep = Flapjack::Gateways::JSONAPI::EntityPresenter.new(entity)
|
42
|
+
status = ep.status
|
43
|
+
expect(status).to eq([{:entity => entity.name, :check => 'ping', :status => status_b},
|
44
|
+
{:entity => entity.name, :check => 'ssh', :status => status_a}])
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns a list of outage hashes for each check on an entity" do
|
49
|
+
expect_check_presenters
|
50
|
+
outages_a = double('outages_a')
|
51
|
+
outages_b = double('outages_b')
|
52
|
+
expect(checkpres_a).to receive(:outages).with(start_time, end_time).
|
53
|
+
and_return(outages_a)
|
54
|
+
expect(checkpres_b).to receive(:outages).with(start_time, end_time).
|
55
|
+
and_return(outages_b)
|
56
|
+
|
57
|
+
ep = Flapjack::Gateways::JSONAPI::EntityPresenter.new(entity)
|
58
|
+
outages = ep.outages(start_time, end_time)
|
59
|
+
expect(outages).to eq([{:entity => entity.name, :check => 'ping', :outages => outages_b},
|
60
|
+
{:entity => entity.name, :check => 'ssh', :outages => outages_a}])
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns a list of unscheduled maintenance periods for each check on an entity" do
|
64
|
+
expect_check_presenters
|
65
|
+
unsched_maint_a = double('unsched_maint_a')
|
66
|
+
unsched_maint_b = double('unsched_maint_b')
|
67
|
+
expect(checkpres_a).to receive(:unscheduled_maintenances).with(start_time, end_time).
|
68
|
+
and_return(unsched_maint_a)
|
69
|
+
expect(checkpres_b).to receive(:unscheduled_maintenances).with(start_time, end_time).
|
70
|
+
and_return(unsched_maint_b)
|
71
|
+
|
72
|
+
ep = Flapjack::Gateways::JSONAPI::EntityPresenter.new(entity)
|
73
|
+
unsched_maint = ep.unscheduled_maintenances(start_time, end_time)
|
74
|
+
expect(unsched_maint).to eq([{:entity => entity.name, :check => 'ping', :unscheduled_maintenances => unsched_maint_b},
|
75
|
+
{:entity => entity.name, :check => 'ssh', :unscheduled_maintenances => unsched_maint_a}])
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns a list of scheduled maintenance periods for each check on an entity" do
|
79
|
+
expect_check_presenters
|
80
|
+
sched_maint_a = double('sched_maint_a')
|
81
|
+
sched_maint_b = double('sched_maint_b')
|
82
|
+
expect(checkpres_a).to receive(:scheduled_maintenances).with(start_time, end_time).
|
83
|
+
and_return(sched_maint_a)
|
84
|
+
expect(checkpres_b).to receive(:scheduled_maintenances).with(start_time, end_time).
|
85
|
+
and_return(sched_maint_b)
|
86
|
+
|
87
|
+
ep = Flapjack::Gateways::JSONAPI::EntityPresenter.new(entity)
|
88
|
+
sched_maint = ep.scheduled_maintenances(start_time, end_time)
|
89
|
+
expect(sched_maint).to eq([{:entity => entity.name, :check => 'ping', :scheduled_maintenances => sched_maint_b},
|
90
|
+
{:entity => entity.name, :check => 'ssh', :scheduled_maintenances => sched_maint_a}])
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns a list of downtime for each check on an entity" do
|
94
|
+
expect_check_presenters
|
95
|
+
downtime_a = double('downtime_a')
|
96
|
+
downtime_b = double('downtime_b')
|
97
|
+
expect(checkpres_a).to receive(:downtime).with(start_time, end_time).
|
98
|
+
and_return(downtime_a)
|
99
|
+
expect(checkpres_b).to receive(:downtime).with(start_time, end_time).
|
100
|
+
and_return(downtime_b)
|
101
|
+
|
102
|
+
ep = Flapjack::Gateways::JSONAPI::EntityPresenter.new(entity)
|
103
|
+
downtime = ep.downtime(start_time, end_time)
|
104
|
+
expect(downtime).to eq([{:entity => entity.name, :check => 'ping', :downtime => downtime_b},
|
105
|
+
{:entity => entity.name, :check => 'ssh', :downtime => downtime_a}])
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -17,28 +17,28 @@ describe Flapjack::Gateways::Oobetet, :logger => true do
|
|
17
17
|
let(:stanza) { double('stanza') }
|
18
18
|
|
19
19
|
it "raises an error if a required config setting is not set" do
|
20
|
-
Socket.
|
20
|
+
expect(Socket).to receive(:gethostname).and_return('thismachine')
|
21
21
|
|
22
22
|
fo = Flapjack::Gateways::Oobetet.new(:config => config.delete('watched_check'), :logger => @logger)
|
23
23
|
|
24
|
-
|
24
|
+
expect {
|
25
25
|
fo.setup
|
26
|
-
}.
|
26
|
+
}.to raise_error
|
27
27
|
end
|
28
28
|
|
29
29
|
it "hooks up event handlers to the appropriate methods" do
|
30
30
|
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
31
31
|
|
32
|
-
EventMachine::Synchrony.
|
32
|
+
expect(EventMachine::Synchrony).to receive(:next_tick).exactly(3).times.and_yield
|
33
33
|
|
34
|
-
fo.
|
35
|
-
fo.
|
34
|
+
expect(fo).to receive(:register_handler).with(:ready).and_yield(stanza)
|
35
|
+
expect(fo).to receive(:on_ready).with(stanza)
|
36
36
|
|
37
|
-
fo.
|
38
|
-
fo.
|
37
|
+
expect(fo).to receive(:register_handler).with(:message, :groupchat?).and_yield(stanza)
|
38
|
+
expect(fo).to receive(:on_groupchat).with(stanza)
|
39
39
|
|
40
|
-
fo.
|
41
|
-
fo.
|
40
|
+
expect(fo).to receive(:register_handler).with(:disconnected).and_yield(stanza)
|
41
|
+
expect(fo).to receive(:on_disconnect).with(stanza).and_return(true)
|
42
42
|
|
43
43
|
fo.register_handlers
|
44
44
|
end
|
@@ -46,8 +46,8 @@ describe Flapjack::Gateways::Oobetet, :logger => true do
|
|
46
46
|
it "joins a chat room after connecting" do
|
47
47
|
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
48
48
|
|
49
|
-
fo.
|
50
|
-
fo.
|
49
|
+
expect(fo).to receive(:write).with(an_instance_of(Blather::Stanza::Presence))
|
50
|
+
expect(fo).to receive(:write).with(an_instance_of(Blather::Stanza::Message))
|
51
51
|
|
52
52
|
fo.on_ready(stanza)
|
53
53
|
end
|
@@ -55,11 +55,11 @@ describe Flapjack::Gateways::Oobetet, :logger => true do
|
|
55
55
|
it "reconnects when disconnected (if not quitting)" do
|
56
56
|
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
57
57
|
|
58
|
-
EventMachine::Timer.
|
59
|
-
fo.
|
58
|
+
expect(EventMachine::Timer).to receive(:new).with(1).and_yield
|
59
|
+
expect(fo).to receive(:connect)
|
60
60
|
|
61
61
|
ret = fo.on_disconnect(stanza)
|
62
|
-
ret.
|
62
|
+
expect(ret).to be true
|
63
63
|
end
|
64
64
|
|
65
65
|
it "records times of a problem status messages" do
|
@@ -68,14 +68,14 @@ describe Flapjack::Gateways::Oobetet, :logger => true do
|
|
68
68
|
|
69
69
|
t = Time.now
|
70
70
|
|
71
|
-
stanza.
|
72
|
-
Time.
|
71
|
+
expect(stanza).to receive(:body).and_return( %q{PROBLEM: "PING" on foo.bar.net} )
|
72
|
+
expect(Time).to receive(:now).and_return(t)
|
73
73
|
|
74
74
|
fo.on_groupchat(stanza)
|
75
75
|
fo_times = fo.instance_variable_get('@times')
|
76
|
-
fo_times.
|
77
|
-
fo_times.
|
78
|
-
fo_times[:last_problem].
|
76
|
+
expect(fo_times).not_to be_nil
|
77
|
+
expect(fo_times).to have_key(:last_problem)
|
78
|
+
expect(fo_times[:last_problem]).to eq(t.to_i)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "records times of a recovery status messages" do
|
@@ -84,14 +84,14 @@ describe Flapjack::Gateways::Oobetet, :logger => true do
|
|
84
84
|
|
85
85
|
t = Time.now
|
86
86
|
|
87
|
-
stanza.
|
88
|
-
Time.
|
87
|
+
expect(stanza).to receive(:body).and_return( %q{RECOVERY: "PING" on foo.bar.net} )
|
88
|
+
expect(Time).to receive(:now).and_return(t)
|
89
89
|
|
90
90
|
fo.on_groupchat(stanza)
|
91
91
|
fo_times = fo.instance_variable_get('@times')
|
92
|
-
fo_times.
|
93
|
-
fo_times.
|
94
|
-
fo_times[:last_recovery].
|
92
|
+
expect(fo_times).not_to be_nil
|
93
|
+
expect(fo_times).to have_key(:last_recovery)
|
94
|
+
expect(fo_times[:last_recovery]).to eq(t.to_i)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "records times of an acknowledgement status messages" do
|
@@ -100,26 +100,26 @@ describe Flapjack::Gateways::Oobetet, :logger => true do
|
|
100
100
|
|
101
101
|
t = Time.now
|
102
102
|
|
103
|
-
stanza.
|
104
|
-
Time.
|
103
|
+
expect(stanza).to receive(:body).and_return( %q{ACKNOWLEDGEMENT: "PING" on foo.bar.net} )
|
104
|
+
expect(Time).to receive(:now).and_return(t)
|
105
105
|
|
106
106
|
fo.on_groupchat(stanza)
|
107
107
|
fo_times = fo.instance_variable_get('@times')
|
108
|
-
fo_times.
|
109
|
-
fo_times.
|
110
|
-
fo_times[:last_ack].
|
108
|
+
expect(fo_times).not_to be_nil
|
109
|
+
expect(fo_times).to have_key(:last_ack)
|
110
|
+
expect(fo_times[:last_ack]).to eq(t.to_i)
|
111
111
|
end
|
112
112
|
|
113
113
|
it "runs a loop checking for recorded problems" do
|
114
114
|
timer = double('timer')
|
115
|
-
timer.
|
116
|
-
EM::Synchrony.
|
115
|
+
expect(timer).to receive(:cancel)
|
116
|
+
expect(EM::Synchrony).to receive(:add_periodic_timer).with(60).and_return(timer)
|
117
117
|
|
118
118
|
fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger)
|
119
|
-
fo.
|
120
|
-
fo.
|
119
|
+
expect(fo).to receive(:register_handler).exactly(3).times
|
120
|
+
expect(fo).to receive(:connect)
|
121
121
|
|
122
|
-
EM::Synchrony.
|
122
|
+
expect(EM::Synchrony).to receive(:sleep).with(10) {
|
123
123
|
fo.instance_variable_set('@should_quit', true)
|
124
124
|
nil
|
125
125
|
}
|
@@ -12,34 +12,34 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
|
|
12
12
|
|
13
13
|
it "prompts the blocking redis connection to quit" do
|
14
14
|
shutdown_redis = double('shutdown_redis')
|
15
|
-
shutdown_redis.
|
16
|
-
EM::Hiredis.
|
15
|
+
expect(shutdown_redis).to receive(:rpush).with(config['queue'], %q{{"notification_type":"shutdown"}})
|
16
|
+
expect(EM::Hiredis).to receive(:connect).and_return(shutdown_redis)
|
17
17
|
|
18
|
-
Flapjack::RedisPool.
|
18
|
+
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
19
19
|
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
20
20
|
fp.stop
|
21
21
|
end
|
22
22
|
|
23
23
|
it "doesn't look for acknowledgements if this search is already running" do
|
24
|
-
redis.
|
25
|
-
Flapjack::RedisPool.
|
24
|
+
expect(redis).to receive(:get).with('sem_pagerduty_acks_running').and_return('true')
|
25
|
+
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
26
26
|
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
27
27
|
|
28
|
-
fp.
|
28
|
+
expect(fp).not_to receive(:find_pagerduty_acknowledgements)
|
29
29
|
fp.find_pagerduty_acknowledgements_if_safe
|
30
30
|
end
|
31
31
|
|
32
32
|
it "looks for acknowledgements if the search is not already running" do
|
33
|
-
redis.
|
34
|
-
redis.
|
35
|
-
redis.
|
33
|
+
expect(redis).to receive(:get).with('sem_pagerduty_acks_running').and_return(nil)
|
34
|
+
expect(redis).to receive(:set).with('sem_pagerduty_acks_running', 'true')
|
35
|
+
expect(redis).to receive(:expire).with('sem_pagerduty_acks_running', 300)
|
36
36
|
|
37
|
-
redis.
|
37
|
+
expect(redis).to receive(:del).with('sem_pagerduty_acks_running')
|
38
38
|
|
39
|
-
Flapjack::RedisPool.
|
39
|
+
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
40
40
|
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
41
41
|
|
42
|
-
fp.
|
42
|
+
expect(fp).to receive(:find_pagerduty_acknowledgements)
|
43
43
|
fp.find_pagerduty_acknowledgements_if_safe
|
44
44
|
end
|
45
45
|
|
@@ -50,7 +50,7 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
|
|
50
50
|
# NB: needs to run in synchrony block to catch the evented HTTP requests
|
51
51
|
it "looks for acknowledgements via the PagerDuty API" do
|
52
52
|
check = 'PING'
|
53
|
-
Time.
|
53
|
+
expect(Time).to receive(:now).and_return(time)
|
54
54
|
since = (time.utc - (60*60*24*7)).iso8601 # the last week
|
55
55
|
unt = (time.utc + (60*60*24)).iso8601 # 1 day in the future
|
56
56
|
|
@@ -72,7 +72,7 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
|
|
72
72
|
with(:headers => {'Authorization'=>['flapjack', 'password123']}).
|
73
73
|
to_return(:status => 200, :body => response.to_json, :headers => {})
|
74
74
|
|
75
|
-
Flapjack::RedisPool.
|
75
|
+
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
76
76
|
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
77
77
|
|
78
78
|
|
@@ -80,22 +80,22 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
|
|
80
80
|
result = fp.send(:pagerduty_acknowledged?, 'subdomain' => 'flpjck', 'username' => 'flapjack',
|
81
81
|
'password' => 'password123', 'check' => check)
|
82
82
|
|
83
|
-
result.
|
84
|
-
result.
|
85
|
-
result[:pg_acknowledged_by].
|
86
|
-
result[:pg_acknowledged_by].
|
87
|
-
result[:pg_acknowledged_by]['id'].
|
83
|
+
expect(result).to be_a(Hash)
|
84
|
+
expect(result).to have_key(:pg_acknowledged_by)
|
85
|
+
expect(result[:pg_acknowledged_by]).to be_a(Hash)
|
86
|
+
expect(result[:pg_acknowledged_by]).to have_key('id')
|
87
|
+
expect(result[:pg_acknowledged_by]['id']).to eq('ABCDEFG')
|
88
88
|
EM.stop
|
89
89
|
end
|
90
90
|
|
91
91
|
end
|
92
92
|
|
93
93
|
it "creates acknowledgements when pagerduty acknowledgements are found" do
|
94
|
-
Flapjack::RedisPool.
|
94
|
+
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
95
95
|
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
96
96
|
|
97
97
|
contact = double('contact')
|
98
|
-
contact.
|
98
|
+
expect(contact).to receive(:pagerduty_credentials).and_return({
|
99
99
|
'service_key' => '12345678',
|
100
100
|
'subdomain"' => 'flpjck',
|
101
101
|
'username' => 'flapjack',
|
@@ -103,32 +103,32 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
|
|
103
103
|
})
|
104
104
|
|
105
105
|
entity_check = double('entity_check')
|
106
|
-
entity_check.
|
107
|
-
entity_check.
|
108
|
-
entity_check.
|
109
|
-
Flapjack::Data::Event.
|
106
|
+
expect(entity_check).to receive(:check).and_return('PING')
|
107
|
+
expect(entity_check).to receive(:contacts).and_return([contact])
|
108
|
+
expect(entity_check).to receive(:entity_name).exactly(2).times.and_return('foo-app-01.bar.net')
|
109
|
+
expect(Flapjack::Data::Event).to receive(:create_acknowledgement).with('foo-app-01.bar.net', 'PING',
|
110
110
|
:summary => 'Acknowledged on PagerDuty', :duration => 14400, :redis => redis)
|
111
111
|
|
112
|
-
Flapjack::Data::Global.
|
112
|
+
expect(Flapjack::Data::Global).to receive(:unacknowledged_failing_checks).and_return([entity_check])
|
113
113
|
|
114
|
-
fp.
|
114
|
+
expect(fp).to receive(:pagerduty_acknowledged?).and_return({})
|
115
115
|
|
116
116
|
fp.send(:find_pagerduty_acknowledgements)
|
117
117
|
end
|
118
118
|
|
119
119
|
it "runs a blocking loop listening for notifications" do
|
120
120
|
timer = double('timer')
|
121
|
-
timer.
|
122
|
-
EM::Synchrony.
|
121
|
+
expect(timer).to receive(:cancel)
|
122
|
+
expect(EM::Synchrony).to receive(:add_periodic_timer).with(10).and_return(timer)
|
123
123
|
|
124
|
-
redis.
|
124
|
+
expect(redis).to receive(:del).with('sem_pagerduty_acks_running')
|
125
125
|
|
126
|
-
Flapjack::RedisPool.
|
126
|
+
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
127
127
|
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
128
128
|
|
129
129
|
blpop_count = 0
|
130
130
|
|
131
|
-
redis.
|
131
|
+
expect(redis).to receive(:blpop).twice {
|
132
132
|
blpop_count += 1
|
133
133
|
if blpop_count == 1
|
134
134
|
["pagerduty_notifications", '{"notification_type":"problem","event_id":"main-example.com:ping",' +
|
@@ -139,12 +139,12 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
|
|
139
139
|
end
|
140
140
|
}
|
141
141
|
|
142
|
-
fp.
|
143
|
-
fp.
|
142
|
+
expect(fp).to receive(:test_pagerduty_connection).and_return(true)
|
143
|
+
expect(fp).to receive(:send_pagerduty_event)
|
144
144
|
|
145
145
|
fp.start
|
146
146
|
|
147
|
-
@logger.errors.
|
147
|
+
expect(@logger.errors).to be_empty
|
148
148
|
end
|
149
149
|
|
150
150
|
it "tests the pagerduty connection" do
|
@@ -157,12 +157,12 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
|
|
157
157
|
stub_request(:post, "https://events.pagerduty.com/generic/2010-04-15/create_event.json").
|
158
158
|
with(:body => body).to_return(:status => 200, :body => '{"status":"success"}', :headers => {})
|
159
159
|
|
160
|
-
Flapjack::RedisPool.
|
160
|
+
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
161
161
|
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
162
162
|
|
163
163
|
EM.synchrony do
|
164
164
|
ret = fp.send(:test_pagerduty_connection)
|
165
|
-
ret.
|
165
|
+
expect(ret).to be true
|
166
166
|
EM.stop
|
167
167
|
end
|
168
168
|
end
|
@@ -177,13 +177,13 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
|
|
177
177
|
stub_request(:post, "https://events.pagerduty.com/generic/2010-04-15/create_event.json").
|
178
178
|
with(:body => body).to_return(:status => 200, :body => "", :headers => {})
|
179
179
|
|
180
|
-
Flapjack::RedisPool.
|
180
|
+
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
181
181
|
fp = Flapjack::Gateways::Pagerduty.new(:config => config, :logger => @logger)
|
182
182
|
|
183
183
|
EM.synchrony do
|
184
184
|
ret = fp.send(:send_pagerduty_event, evt)
|
185
|
-
ret.
|
186
|
-
ret.
|
185
|
+
expect { ret }.not_to be_nil
|
186
|
+
expect(ret).to eq([200, nil])
|
187
187
|
EM.stop
|
188
188
|
end
|
189
189
|
end
|
@@ -45,7 +45,7 @@ describe Flapjack::Gateways::SmsMessagenet, :logger => true do
|
|
45
45
|
Flapjack::Gateways::SmsMessagenet.perform(message)
|
46
46
|
EM.stop
|
47
47
|
end
|
48
|
-
req.
|
48
|
+
expect(req).to have_been_requested
|
49
49
|
end
|
50
50
|
|
51
51
|
it "truncates a long message a" do
|
@@ -70,7 +70,7 @@ describe Flapjack::Gateways::SmsMessagenet, :logger => true do
|
|
70
70
|
Flapjack::Gateways::SmsMessagenet.perform(long_msg)
|
71
71
|
EM.stop
|
72
72
|
end
|
73
|
-
req.
|
73
|
+
expect(req).to have_been_requested
|
74
74
|
end
|
75
75
|
|
76
76
|
it "does not send an SMS message with an invalid config" do
|
@@ -82,7 +82,7 @@ describe Flapjack::Gateways::SmsMessagenet, :logger => true do
|
|
82
82
|
EM.stop
|
83
83
|
end
|
84
84
|
|
85
|
-
WebMock.
|
85
|
+
expect(WebMock).not_to have_requested(:get,
|
86
86
|
"https://www.messagenet.com.au/dotnet/Lodge.asmx/LodgeSMSMessage")
|
87
87
|
end
|
88
88
|
|