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
@@ -8,7 +8,7 @@ describe 'web/views/check.html.erb', :erb_view => true do
|
|
8
8
|
@last_notifications = {}
|
9
9
|
|
10
10
|
page = render_erb('check.html.erb', binding)
|
11
|
-
page.
|
11
|
+
expect(page).to match(%r{/abc-xyz-01/Disk%20%2F%20Utilisation})
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
@@ -4,19 +4,19 @@ describe 'web/views/contact.html.erb', :erb_view => true do
|
|
4
4
|
|
5
5
|
it "should escape unsafe check characters in URI parameters" do
|
6
6
|
@contact = double('contact')
|
7
|
-
@contact.
|
8
|
-
@contact.
|
9
|
-
@contact.
|
7
|
+
expect(@contact).to receive(:media)
|
8
|
+
expect(@contact).to receive(:name).and_return('Aeschylus')
|
9
|
+
expect(@contact).to receive(:notification_rules)
|
10
10
|
|
11
11
|
entity = double('entity')
|
12
|
-
entity.
|
12
|
+
expect(entity).to receive(:name).exactly(3).times.and_return('abc-xyz-01')
|
13
13
|
|
14
14
|
checks = ['Disk / Utilisation']
|
15
15
|
|
16
16
|
@entities_and_checks = [{:entity => entity, :checks => checks}]
|
17
17
|
|
18
18
|
page = render_erb('contact.html.erb', binding)
|
19
|
-
page.
|
19
|
+
expect(page).to match(%r{\?entity=abc-xyz-01&check=Disk%20%2F%20Utilisation})
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -8,7 +8,7 @@ describe 'web/views/checks.html.erb', :erb_view => true do
|
|
8
8
|
@adjective = "all"
|
9
9
|
|
10
10
|
page = render_erb('checks.html.erb', binding)
|
11
|
-
page.
|
11
|
+
expect(page).to match(%r{\?entity=abc-xyz-01&check=Disk%20%2F%20Utilisation})
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
@@ -24,49 +24,49 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
before(:each) do
|
27
|
-
Flapjack::RedisPool.
|
27
|
+
expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
|
28
28
|
Flapjack::Gateways::Web.instance_variable_set('@config', {})
|
29
29
|
Flapjack::Gateways::Web.instance_variable_set('@logger', @logger)
|
30
30
|
Flapjack::Gateways::Web.start
|
31
31
|
end
|
32
32
|
|
33
33
|
def expect_stats
|
34
|
-
redis.
|
35
|
-
redis.
|
36
|
-
redis.
|
37
|
-
redis.
|
34
|
+
expect(redis).to receive(:dbsize).and_return(3)
|
35
|
+
expect(redis).to receive(:keys).with('executive_instance:*').and_return(["executive_instance:foo-app-01"])
|
36
|
+
expect(redis).to receive(:hget).once.and_return(Time.now.to_i - 60)
|
37
|
+
expect(redis).to receive(:hgetall).twice.and_return({'all' => '8001', 'ok' => '8002'},
|
38
38
|
{'all' => '9001', 'ok' => '9002'})
|
39
|
-
redis.
|
40
|
-
redis.
|
41
|
-
redis.
|
39
|
+
expect(redis).to receive(:llen).with('events')
|
40
|
+
expect(redis).to receive(:zrange).with('current_entities', 0, -1).and_return(['foo-app-01.example.com'])
|
41
|
+
expect(redis).to receive(:zrange).with('current_checks:foo-app-01.example.com', 0, -1, {:withscores => true}).and_return([['ping', 1382329923.0]])
|
42
42
|
end
|
43
43
|
|
44
44
|
def expect_check_stats
|
45
|
-
Flapjack::Data::EntityCheck.
|
45
|
+
expect(Flapjack::Data::EntityCheck).to receive(:count_all).
|
46
46
|
with(:redis => redis).and_return(1)
|
47
|
-
Flapjack::Data::EntityCheck.
|
47
|
+
expect(Flapjack::Data::EntityCheck).to receive(:count_all_failing).
|
48
48
|
with(:redis => redis).and_return(1)
|
49
49
|
end
|
50
50
|
|
51
51
|
def expect_entity_stats
|
52
|
-
Flapjack::Data::Entity.
|
52
|
+
expect(Flapjack::Data::Entity).to receive(:find_all_with_checks).
|
53
53
|
with(:redis => redis).and_return([entity_name])
|
54
|
-
Flapjack::Data::Entity.
|
54
|
+
expect(Flapjack::Data::Entity).to receive(:find_all_with_failing_checks).
|
55
55
|
with(:redis => redis).and_return([entity_name])
|
56
56
|
end
|
57
57
|
|
58
58
|
def expect_entity_check_status(ec)
|
59
59
|
time = Time.now.to_i
|
60
60
|
|
61
|
-
ec.
|
62
|
-
ec.
|
63
|
-
ec.
|
64
|
-
ec.
|
65
|
-
ec.
|
66
|
-
ec.
|
67
|
-
ec.
|
68
|
-
ec.
|
69
|
-
ec.
|
61
|
+
expect(ec).to receive(:state).and_return('ok')
|
62
|
+
expect(ec).to receive(:summary).and_return('happy results are returned')
|
63
|
+
expect(ec).to receive(:last_update).and_return(time - (3 * 60 * 60))
|
64
|
+
expect(ec).to receive(:last_change).and_return(time - (3 * 60 * 60))
|
65
|
+
expect(ec).to receive(:last_notification_for_state).with(:problem).and_return({:timestamp => time - ((3 * 60 * 60) + (5 * 60))})
|
66
|
+
expect(ec).to receive(:last_notification_for_state).with(:recovery).and_return({:timestamp => time - (3 * 60 * 60)})
|
67
|
+
expect(ec).to receive(:last_notification_for_state).with(:acknowledgement).and_return({:timestamp => nil})
|
68
|
+
expect(ec).to receive(:in_scheduled_maintenance?).and_return(false)
|
69
|
+
expect(ec).to receive(:in_unscheduled_maintenance?).and_return(false)
|
70
70
|
end
|
71
71
|
|
72
72
|
# TODO add data, test that pages contain representations of it
|
@@ -74,20 +74,20 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
74
74
|
|
75
75
|
it "shows a page listing all checks" do
|
76
76
|
#redis.should_receive(:keys).with('*:*:states').and_return(["#{entity_name}:#{check}"])
|
77
|
-
Flapjack::Data::EntityCheck.
|
77
|
+
expect(Flapjack::Data::EntityCheck).to receive(:find_all_by_entity).
|
78
78
|
with(:redis => redis).and_return({entity_name => [check]})
|
79
79
|
expect_check_stats
|
80
80
|
|
81
81
|
expect_entity_check_status(entity_check)
|
82
82
|
|
83
|
-
Flapjack::Data::Entity.
|
83
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
84
84
|
with(entity_name, :redis => redis).and_return(entity)
|
85
85
|
|
86
|
-
Flapjack::Data::EntityCheck.
|
86
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
87
87
|
with(entity, 'ping', :redis => redis).and_return(entity_check)
|
88
88
|
|
89
89
|
aget '/checks_all'
|
90
|
-
last_response.
|
90
|
+
expect(last_response).to be_ok
|
91
91
|
end
|
92
92
|
|
93
93
|
it "shows a page listing failing checks" do
|
@@ -97,16 +97,16 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
97
97
|
|
98
98
|
expect_entity_check_status(entity_check)
|
99
99
|
|
100
|
-
Flapjack::Data::Entity.
|
100
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
101
101
|
with(entity_name, :redis => redis).and_return(entity)
|
102
102
|
|
103
|
-
Flapjack::Data::EntityCheck.
|
103
|
+
expect(Flapjack::Data::EntityCheck).to receive(:find_all_failing_by_entity).
|
104
104
|
with(:redis => redis).and_return({entity_name => [check]})
|
105
105
|
|
106
|
-
Flapjack::Data::EntityCheck.
|
106
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
107
107
|
with(entity, 'ping', :redis => redis).and_return(entity_check)
|
108
108
|
aget '/checks_failing'
|
109
|
-
last_response.
|
109
|
+
expect(last_response).to be_ok
|
110
110
|
end
|
111
111
|
|
112
112
|
it "shows a page listing flapjack statistics" do
|
@@ -117,75 +117,74 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
117
117
|
expect_entity_stats
|
118
118
|
|
119
119
|
aget '/self_stats'
|
120
|
-
last_response.
|
120
|
+
expect(last_response).to be_ok
|
121
121
|
end
|
122
122
|
|
123
123
|
it "shows the state of a check for an entity" do
|
124
124
|
time = Time.now
|
125
|
-
Time.
|
125
|
+
expect(Time).to receive(:now).exactly(5).times.and_return(time)
|
126
126
|
|
127
127
|
last_notifications = {:problem => {:timestamp => time.to_i - ((3 * 60 * 60) + (5 * 60)), :summary => 'prob'},
|
128
128
|
:recovery => {:timestamp => time.to_i - (3 * 60 * 60), :summary => nil},
|
129
129
|
:acknowledgement => {:timestamp => nil, :summary => nil} }
|
130
130
|
|
131
131
|
expect_check_stats
|
132
|
-
entity_check.
|
133
|
-
entity_check.
|
134
|
-
entity_check.
|
135
|
-
entity_check.
|
136
|
-
entity_check.
|
137
|
-
entity_check.
|
138
|
-
entity_check.
|
139
|
-
entity_check.
|
140
|
-
entity_check.
|
141
|
-
entity_check.
|
142
|
-
entity_check.
|
143
|
-
entity_check.
|
132
|
+
expect(entity_check).to receive(:state).and_return('ok')
|
133
|
+
expect(entity_check).to receive(:last_update).and_return(time.to_i - (3 * 60 * 60))
|
134
|
+
expect(entity_check).to receive(:last_change).and_return(time.to_i - (3 * 60 * 60))
|
135
|
+
expect(entity_check).to receive(:summary).and_return('all good')
|
136
|
+
expect(entity_check).to receive(:details).and_return('seriously, all very wonderful')
|
137
|
+
expect(entity_check).to receive(:last_notifications_of_each_type).and_return(last_notifications)
|
138
|
+
expect(entity_check).to receive(:maintenances).with(nil, nil, :scheduled => true).and_return([])
|
139
|
+
expect(entity_check).to receive(:failed?).and_return(false)
|
140
|
+
expect(entity_check).to receive(:current_maintenance).with(:scheduled => true).and_return(false)
|
141
|
+
expect(entity_check).to receive(:current_maintenance).with(:scheduled => false).and_return(false)
|
142
|
+
expect(entity_check).to receive(:contacts).and_return([])
|
143
|
+
expect(entity_check).to receive(:historical_states).
|
144
144
|
with(nil, time.to_i, :order => 'desc', :limit => 20).and_return([])
|
145
|
-
entity_check.
|
146
|
-
and_return(true)
|
145
|
+
expect(entity_check).to receive(:enabled?).and_return(true)
|
147
146
|
|
148
|
-
Flapjack::Data::Entity.
|
147
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
149
148
|
with(entity_name, :redis => redis).and_return(entity)
|
150
149
|
|
151
|
-
Flapjack::Data::EntityCheck.
|
150
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
152
151
|
with(entity, 'ping', :redis => redis).and_return(entity_check)
|
153
152
|
|
154
153
|
aget "/check?entity=#{entity_name_esc}&check=ping"
|
155
|
-
last_response.
|
154
|
+
expect(last_response).to be_ok
|
156
155
|
# TODO test instance variables set to appropriate values
|
157
156
|
end
|
158
157
|
|
159
158
|
it "returns 404 if an unknown entity is requested" do
|
160
|
-
Flapjack::Data::Entity.
|
159
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
161
160
|
with(entity_name_esc, :redis => redis).and_return(nil)
|
162
161
|
|
163
162
|
aget "/check?entity=#{entity_name_esc}&check=ping"
|
164
|
-
last_response.
|
163
|
+
expect(last_response).to be_not_found
|
165
164
|
end
|
166
165
|
|
167
166
|
# TODO shouldn't create actual entity record
|
168
167
|
it "returns 404 if no entity check is passed" do
|
169
|
-
Flapjack::Data::Entity.
|
168
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
170
169
|
with(entity_name, :redis => redis).and_return(entity)
|
171
170
|
|
172
171
|
aget "/check?entity=#{entity_name_esc}"
|
173
|
-
last_response.
|
172
|
+
expect(last_response).to be_not_found
|
174
173
|
end
|
175
174
|
|
176
175
|
it "creates an acknowledgement for an entity check" do
|
177
|
-
Flapjack::Data::Entity.
|
176
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
178
177
|
with(entity_name, :redis => redis).and_return(entity)
|
179
178
|
|
180
|
-
Flapjack::Data::EntityCheck.
|
179
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
181
180
|
with(entity, 'ping', :redis => redis).and_return(entity_check)
|
182
181
|
|
183
|
-
Flapjack::Data::Event.
|
182
|
+
expect(Flapjack::Data::Event).to receive(:create_acknowledgement).
|
184
183
|
with(entity_name, 'ping', :summary => "", :duration => (4 * 60 * 60),
|
185
184
|
:acknowledgement_id => '1234', :redis => redis)
|
186
185
|
|
187
186
|
apost "/acknowledgements/#{entity_name_esc}/ping?acknowledgement_id=1234"
|
188
|
-
last_response.status.
|
187
|
+
expect(last_response.status).to eq(302)
|
189
188
|
end
|
190
189
|
|
191
190
|
it "creates a scheduled maintenance period for an entity check" do
|
@@ -195,22 +194,22 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
195
194
|
duration = 30 * 60
|
196
195
|
summary = 'wow'
|
197
196
|
|
198
|
-
Chronic.
|
199
|
-
ChronicDuration.
|
197
|
+
expect(Chronic).to receive(:parse).with('1 day ago').and_return(start_time)
|
198
|
+
expect(ChronicDuration).to receive(:parse).with('30 minutes').and_return(duration)
|
200
199
|
|
201
|
-
Flapjack::Data::Entity.
|
200
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
202
201
|
with(entity_name, :redis => redis).and_return(entity)
|
203
202
|
|
204
|
-
Flapjack::Data::EntityCheck.
|
203
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
205
204
|
with(entity, 'ping', :redis => redis).and_return(entity_check)
|
206
205
|
|
207
|
-
entity_check.
|
206
|
+
expect(entity_check).to receive(:create_scheduled_maintenance).
|
208
207
|
with(start_time.to_i, duration, :summary => summary)
|
209
208
|
|
210
209
|
apost "/scheduled_maintenances/#{entity_name_esc}/ping?"+
|
211
210
|
"start_time=1+day+ago&duration=30+minutes&summary=wow"
|
212
211
|
|
213
|
-
last_response.status.
|
212
|
+
expect(last_response.status).to eq(302)
|
214
213
|
end
|
215
214
|
|
216
215
|
it "deletes a scheduled maintenance period for an entity check" do
|
@@ -218,37 +217,37 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
|
|
218
217
|
|
219
218
|
start_time = t - (24 * 60 * 60)
|
220
219
|
|
221
|
-
Flapjack::Data::Entity.
|
220
|
+
expect(Flapjack::Data::Entity).to receive(:find_by_name).
|
222
221
|
with(entity_name, :redis => redis).and_return(entity)
|
223
222
|
|
224
|
-
Flapjack::Data::EntityCheck.
|
223
|
+
expect(Flapjack::Data::EntityCheck).to receive(:for_entity).
|
225
224
|
with(entity, 'ping', :redis => redis).and_return(entity_check)
|
226
225
|
|
227
|
-
entity_check.
|
226
|
+
expect(entity_check).to receive(:end_scheduled_maintenance).with(start_time)
|
228
227
|
|
229
228
|
adelete "/scheduled_maintenances/#{entity_name_esc}/ping?start_time=#{start_time}"
|
230
|
-
last_response.status.
|
229
|
+
expect(last_response.status).to eq(302)
|
231
230
|
end
|
232
231
|
|
233
232
|
it "shows a list of all known contacts" do
|
234
|
-
Flapjack::Data::Contact.
|
233
|
+
expect(Flapjack::Data::Contact).to receive(:all)
|
235
234
|
|
236
235
|
aget "/contacts"
|
237
|
-
last_response.
|
236
|
+
expect(last_response).to be_ok
|
238
237
|
end
|
239
238
|
|
240
239
|
it "shows details of an individual contact found by id" do
|
241
240
|
contact = double('contact')
|
242
|
-
contact.
|
243
|
-
contact.
|
244
|
-
contact.
|
245
|
-
contact.
|
241
|
+
expect(contact).to receive(:name).and_return("Smithson Smith")
|
242
|
+
expect(contact).to receive(:media).exactly(3).times.and_return({})
|
243
|
+
expect(contact).to receive(:entities).with(:checks => true).and_return([])
|
244
|
+
expect(contact).to receive(:notification_rules).and_return([])
|
246
245
|
|
247
|
-
Flapjack::Data::Contact.
|
246
|
+
expect(Flapjack::Data::Contact).to receive(:find_by_id).
|
248
247
|
with('0362', :redis => redis).and_return(contact)
|
249
248
|
|
250
249
|
aget "/contacts/0362"
|
251
|
-
last_response.
|
250
|
+
expect(last_response).to be_ok
|
252
251
|
end
|
253
252
|
|
254
253
|
end
|
@@ -9,29 +9,29 @@ describe Flapjack::Logger do
|
|
9
9
|
let(:syslog) { double(Syslog) }
|
10
10
|
|
11
11
|
it "creates a logger logging to STDOUT and syslog" do
|
12
|
-
logger.
|
13
|
-
logger.
|
14
|
-
logger.
|
15
|
-
::Logger.
|
12
|
+
expect(logger).to receive(:formatter=).with(an_instance_of(Proc))
|
13
|
+
expect(logger).to receive(:level=).and_return(Logger::DEBUG)
|
14
|
+
expect(logger).to receive(:add).with(2, nil, "Yowza!")
|
15
|
+
expect(::Logger).to receive(:new).with(STDOUT).and_return(logger)
|
16
16
|
|
17
|
-
Syslog.
|
17
|
+
expect(Syslog).to receive(:open).with('flapjack',
|
18
18
|
(Syslog::Constants::LOG_PID | Syslog::Constants::LOG_CONS),
|
19
19
|
Syslog::Constants::LOG_USER).and_return(syslog)
|
20
|
-
Syslog.
|
21
|
-
Syslog.
|
22
|
-
Syslog.
|
20
|
+
expect(Syslog).to receive(:mask=).with(Syslog::LOG_UPTO(Syslog::Constants::LOG_ERR))
|
21
|
+
expect(Syslog).to receive(:log).with(Syslog::Constants::LOG_WARNING, /\[WARN\] :: spec :: %s/, "Yowza!")
|
22
|
+
expect(Syslog).to receive(:close)
|
23
23
|
|
24
24
|
flogger = Flapjack::Logger.new('spec', 'level' => 'debug', 'syslog_errors' => 'true')
|
25
25
|
flogger.warn "Yowza!"
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'defaults to not logging via syslog' do
|
29
|
-
logger.
|
30
|
-
logger.
|
31
|
-
logger.
|
32
|
-
::Logger.
|
29
|
+
expect(logger).to receive(:formatter=).with(an_instance_of(Proc))
|
30
|
+
expect(logger).to receive(:level=).and_return(Logger::DEBUG)
|
31
|
+
expect(logger).to receive(:add).with(2, nil, "Yowza!")
|
32
|
+
expect(::Logger).to receive(:new).with(STDOUT).and_return(logger)
|
33
33
|
|
34
|
-
Syslog.
|
34
|
+
expect(Syslog).not_to receive(:open)
|
35
35
|
|
36
36
|
flogger = Flapjack::Logger.new('spec', 'level' => 'debug')
|
37
37
|
flogger.warn "Yowza!"
|
@@ -17,86 +17,86 @@ describe Flapjack::Pikelet do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "creates and starts a processor pikelet" do
|
20
|
-
Flapjack::Logger.
|
20
|
+
expect(Flapjack::Logger).to receive(:new).and_return(logger)
|
21
21
|
|
22
|
-
config.
|
22
|
+
expect(config).to receive(:[]).with('logger').and_return(nil)
|
23
23
|
|
24
24
|
fc = double('coordinator')
|
25
25
|
|
26
26
|
processor = double('processor')
|
27
|
-
processor.
|
28
|
-
Flapjack::Processor.
|
27
|
+
expect(processor).to receive(:start)
|
28
|
+
expect(Flapjack::Processor).to receive(:new).with(:config => config,
|
29
29
|
:redis_config => redis_config, :boot_time => time, :logger => logger, :coordinator => fc).
|
30
30
|
and_return(processor)
|
31
31
|
|
32
|
-
fiber.
|
33
|
-
Fiber.
|
32
|
+
expect(fiber).to receive(:resume)
|
33
|
+
expect(Fiber).to receive(:new).and_yield.and_return(fiber)
|
34
34
|
|
35
35
|
pik = Flapjack::Pikelet.create('processor', :config => config,
|
36
36
|
:redis_config => redis_config, :boot_time => time, :coordinator => fc)
|
37
|
-
pik.
|
37
|
+
expect(pik).to be_a(Flapjack::Pikelet::Generic)
|
38
38
|
pik.start
|
39
39
|
end
|
40
40
|
|
41
41
|
it "creates and starts a resque worker gateway" do
|
42
|
-
Flapjack::Logger.
|
42
|
+
expect(Flapjack::Logger).to receive(:new).and_return(logger)
|
43
43
|
|
44
|
-
config.
|
45
|
-
config.
|
44
|
+
expect(config).to receive(:[]).with('logger').and_return(nil)
|
45
|
+
expect(config).to receive(:[]).with('queue').and_return('email_notif')
|
46
46
|
|
47
47
|
resque_redis = double('resque_redis')
|
48
48
|
redis = double('redis')
|
49
|
-
Flapjack::RedisPool.
|
50
|
-
Resque.
|
49
|
+
expect(Flapjack::RedisPool).to receive(:new).twice.and_return(resque_redis, redis)
|
50
|
+
expect(Resque).to receive(:redis=).with(resque_redis)
|
51
51
|
|
52
|
-
Flapjack::Gateways::Email.
|
52
|
+
expect(Flapjack::Gateways::Email).to receive(:instance_variable_set).
|
53
53
|
with('@config', config)
|
54
|
-
Flapjack::Gateways::Email.
|
54
|
+
expect(Flapjack::Gateways::Email).to receive(:instance_variable_set).
|
55
55
|
with('@redis', redis)
|
56
|
-
Flapjack::Gateways::Email.
|
56
|
+
expect(Flapjack::Gateways::Email).to receive(:instance_variable_set).
|
57
57
|
with('@logger', logger)
|
58
58
|
|
59
59
|
worker = double('worker')
|
60
|
-
worker.
|
61
|
-
Flapjack::Gateways::Email.
|
62
|
-
EM::Resque::Worker.
|
60
|
+
expect(worker).to receive(:work).with(0.1)
|
61
|
+
expect(Flapjack::Gateways::Email).to receive(:start)
|
62
|
+
expect(EM::Resque::Worker).to receive(:new).with('email_notif').and_return(worker)
|
63
63
|
|
64
|
-
fiber.
|
65
|
-
Fiber.
|
64
|
+
expect(fiber).to receive(:resume)
|
65
|
+
expect(Fiber).to receive(:new).and_yield.and_return(fiber)
|
66
66
|
|
67
67
|
pik = Flapjack::Pikelet.create('email', :config => config,
|
68
68
|
:redis_config => redis_config)
|
69
|
-
pik.
|
69
|
+
expect(pik).to be_a(Flapjack::Pikelet::Resque)
|
70
70
|
pik.start
|
71
71
|
end
|
72
72
|
|
73
73
|
it "creates a thin server gateway" do
|
74
|
-
Flapjack::Logger.
|
74
|
+
expect(Flapjack::Logger).to receive(:new).and_return(logger)
|
75
75
|
|
76
|
-
config.
|
77
|
-
config.
|
78
|
-
config.
|
76
|
+
expect(config).to receive(:[]).with('logger').and_return(nil)
|
77
|
+
expect(config).to receive(:[]).with('port').and_return(7654)
|
78
|
+
expect(config).to receive(:[]).with('timeout').and_return(90)
|
79
79
|
|
80
80
|
server = double('server')
|
81
|
-
server.
|
82
|
-
server.
|
83
|
-
Thin::Server.
|
81
|
+
expect(server).to receive(:timeout=).with(90)
|
82
|
+
expect(server).to receive(:start)
|
83
|
+
expect(Thin::Server).to receive(:new).
|
84
84
|
with(/^(?:\d{1,3}\.){3}\d{1,3}$/, 7654,
|
85
85
|
Flapjack::Gateways::Web, :signals => false).
|
86
86
|
and_return(server)
|
87
87
|
|
88
|
-
Flapjack::Gateways::Web.
|
88
|
+
expect(Flapjack::Gateways::Web).to receive(:instance_variable_set).
|
89
89
|
with('@config', config)
|
90
|
-
Flapjack::Gateways::Web.
|
90
|
+
expect(Flapjack::Gateways::Web).to receive(:instance_variable_set).
|
91
91
|
with('@redis_config', redis_config)
|
92
|
-
Flapjack::Gateways::Web.
|
92
|
+
expect(Flapjack::Gateways::Web).to receive(:instance_variable_set).
|
93
93
|
with('@logger', logger)
|
94
94
|
|
95
|
-
Flapjack::Gateways::Web.
|
95
|
+
expect(Flapjack::Gateways::Web).to receive(:start)
|
96
96
|
|
97
97
|
pik = Flapjack::Pikelet.create('web', :config => config,
|
98
98
|
:redis_config => redis_config)
|
99
|
-
pik.
|
99
|
+
expect(pik).to be_a(Flapjack::Pikelet::Thin)
|
100
100
|
pik.start
|
101
101
|
end
|
102
102
|
|