flapjack 0.7.18 → 0.7.19
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/bin/flapjack +3 -0
- data/bin/flapjack-nagios-receiver +4 -1
- data/bin/flapjack-netsaint-parser +2 -1
- data/bin/flapjack-populator +6 -3
- data/bin/receive-events +3 -1
- data/bin/simulate-failed-check +2 -1
- data/etc/flapjack_config.yaml.example +20 -0
- data/features/events.feature +1 -1
- data/features/events_check_names.feature +1 -1
- data/features/notification_rules.feature +1 -1
- data/features/notifications.feature +1 -1
- data/features/steps/events_steps.rb +18 -17
- data/features/steps/flapjack-netsaint-parser_steps.rb +1 -2
- data/features/steps/notifications_steps.rb +14 -1
- data/features/support/env.rb +27 -10
- data/flapjack.gemspec +1 -3
- data/lib/flapjack/coordinator.rb +30 -20
- data/lib/flapjack/data/contact.rb +3 -2
- data/lib/flapjack/data/entity.rb +3 -3
- data/lib/flapjack/data/entity_check.rb +116 -43
- data/lib/flapjack/data/event.rb +10 -10
- data/lib/flapjack/data/message.rb +3 -6
- data/lib/flapjack/data/notification.rb +122 -57
- data/lib/flapjack/data/notification_rule.rb +11 -11
- data/lib/flapjack/filters/acknowledgement.rb +2 -2
- data/lib/flapjack/filters/ok.rb +1 -1
- data/lib/flapjack/gateways/api/entity_check_presenter.rb +1 -0
- data/lib/flapjack/gateways/api/entity_methods.rb +4 -6
- data/lib/flapjack/gateways/api/rack/json_params_parser.rb +1 -1
- data/lib/flapjack/gateways/email.rb +3 -5
- data/lib/flapjack/gateways/email/{alert.html.haml → alert.html.erb} +0 -0
- data/lib/flapjack/gateways/jabber.rb +66 -35
- data/lib/flapjack/gateways/oobetet.rb +5 -7
- data/lib/flapjack/gateways/pagerduty.rb +7 -7
- data/lib/flapjack/gateways/web.rb +101 -41
- data/lib/flapjack/gateways/web/public/css/flapjack.css +1 -1
- data/lib/flapjack/gateways/web/views/{_css.haml → _css.html.erb} +2 -1
- data/lib/flapjack/gateways/web/views/_foot.html.erb +3 -0
- data/lib/flapjack/gateways/web/views/_head.html.erb +4 -0
- data/lib/flapjack/gateways/web/views/_nav.html.erb +9 -0
- data/lib/flapjack/gateways/web/views/check.html.erb +204 -0
- data/lib/flapjack/gateways/web/views/checks.html.erb +77 -0
- data/lib/flapjack/gateways/web/views/contact.html.erb +114 -0
- data/lib/flapjack/gateways/web/views/contacts.html.erb +42 -0
- data/lib/flapjack/gateways/web/views/entities.html.erb +39 -0
- data/lib/flapjack/gateways/web/views/entity.html.erb +67 -0
- data/lib/flapjack/gateways/web/views/index.html.erb +27 -0
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +97 -0
- data/lib/flapjack/logger.rb +71 -23
- data/lib/flapjack/notifier.rb +157 -0
- data/lib/flapjack/patches.rb +1 -41
- data/lib/flapjack/pikelet.rb +4 -2
- data/lib/flapjack/{executive.rb → processor.rb} +32 -145
- data/lib/flapjack/version.rb +1 -1
- data/spec/lib/flapjack/coordinator_spec.rb +134 -71
- data/spec/lib/flapjack/data/contact_spec.rb +1 -0
- data/spec/lib/flapjack/data/entity_check_spec.rb +146 -30
- data/spec/lib/flapjack/data/entity_spec.rb +4 -4
- data/spec/lib/flapjack/data/event_spec.rb +4 -4
- data/spec/lib/flapjack/data/message_spec.rb +2 -3
- data/spec/lib/flapjack/data/notification_spec.rb +13 -19
- data/spec/lib/flapjack/gateways/api/entity_methods_spec.rb +2 -2
- data/spec/lib/flapjack/gateways/jabber_spec.rb +34 -0
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +0 -2
- data/spec/lib/flapjack/gateways/web/views/{check.haml_spec.rb → check.html.erb_spec.rb} +2 -2
- data/spec/lib/flapjack/gateways/web/views/{contact.haml_spec.rb → contact.html.erb_spec.rb} +3 -3
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +14 -0
- data/spec/lib/flapjack/gateways/web_spec.rb +20 -8
- data/spec/lib/flapjack/logger_spec.rb +30 -28
- data/spec/lib/flapjack/notifier_spec.rb +6 -0
- data/spec/lib/flapjack/pikelet_spec.rb +8 -8
- data/spec/lib/flapjack/{executive_spec.rb → processor_spec.rb} +4 -4
- data/spec/spec_helper.rb +1 -13
- data/spec/support/erb_view_helper.rb +23 -0
- data/tasks/profile.rake +1 -1
- data/tmp/acknowledge.rb +3 -1
- data/tmp/create_event_ok.rb +3 -1
- data/tmp/create_event_unknown.rb +3 -1
- data/tmp/create_events_failure.rb +3 -1
- data/tmp/create_events_ok.rb +3 -1
- data/tmp/create_events_ok_fail_ack_ok.rb +3 -1
- data/tmp/create_events_ok_failure.rb +3 -1
- data/tmp/create_events_ok_failure_ack.rb +3 -1
- data/tmp/test_json_post.rb +5 -3
- data/tmp/test_notification_rules_api.rb +5 -3
- metadata +32 -61
- data/lib/flapjack/gateways/web/views/_foot.haml +0 -8
- data/lib/flapjack/gateways/web/views/_head.haml +0 -10
- data/lib/flapjack/gateways/web/views/_nav.haml +0 -14
- data/lib/flapjack/gateways/web/views/check.haml +0 -191
- data/lib/flapjack/gateways/web/views/checks.haml +0 -49
- data/lib/flapjack/gateways/web/views/contact.haml +0 -85
- data/lib/flapjack/gateways/web/views/contacts.haml +0 -30
- data/lib/flapjack/gateways/web/views/entities.haml +0 -28
- data/lib/flapjack/gateways/web/views/entity.haml +0 -50
- data/lib/flapjack/gateways/web/views/index.haml +0 -32
- data/lib/flapjack/gateways/web/views/self_stats.haml +0 -70
- data/spec/lib/flapjack/gateways/web/views/index.haml_spec.rb +0 -13
- data/spec/support/haml_view_helper.rb +0 -15
@@ -209,6 +209,7 @@ describe Flapjack::Data::Contact, :redis => true do
|
|
209
209
|
ec = Flapjack::Data::EntityCheck.for_entity_name(entity_name, 'PING', :redis => @redis)
|
210
210
|
t = Time.now.to_i
|
211
211
|
ec.update_state('ok', :timestamp => t, :summary => 'a')
|
212
|
+
ec.last_update = t
|
212
213
|
|
213
214
|
contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
|
214
215
|
eandcs = contact.entities(:checks => true)
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'yajl/json_gem'
|
4
|
-
|
5
3
|
require 'flapjack/data/entity'
|
6
4
|
require 'flapjack/data/entity_check'
|
7
5
|
|
@@ -104,14 +102,24 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
104
102
|
ec.should_not be_in_scheduled_maintenance
|
105
103
|
end
|
106
104
|
|
105
|
+
it "returns its current maintenance period" do
|
106
|
+
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
107
|
+
ec.current_maintenance(:scheduled => true).should be_nil
|
108
|
+
|
109
|
+
t = Time.now.to_i
|
110
|
+
|
111
|
+
ec.create_unscheduled_maintenance(t, half_an_hour, :summary => 'oops')
|
112
|
+
ec.current_maintenance.should == {:start_time => t,
|
113
|
+
:duration => half_an_hour,
|
114
|
+
:summary => 'oops'}
|
115
|
+
end
|
116
|
+
|
107
117
|
it "creates an unscheduled maintenance period" do
|
108
118
|
t = Time.now.to_i
|
109
119
|
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
110
|
-
ec.create_unscheduled_maintenance(
|
120
|
+
ec.create_unscheduled_maintenance(t, half_an_hour, :summary => 'oops')
|
111
121
|
|
112
|
-
|
113
|
-
timestamp.should_not be_nil
|
114
|
-
timestamp.should == t.to_s
|
122
|
+
ec.should be_in_unscheduled_maintenance
|
115
123
|
|
116
124
|
umps = ec.maintenances(nil, nil, :scheduled => false)
|
117
125
|
umps.should_not be_nil
|
@@ -134,11 +142,78 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
134
142
|
summary.should == 'oops'
|
135
143
|
end
|
136
144
|
|
145
|
+
it "creates an unscheduled maintenance period and ends the current one early", :time => true do
|
146
|
+
t = Time.now.to_i
|
147
|
+
later_t = t + (15 * 60)
|
148
|
+
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
149
|
+
ec.create_unscheduled_maintenance(t, half_an_hour, :summary => 'oops')
|
150
|
+
Delorean.time_travel_to( Time.at(later_t) )
|
151
|
+
ec.create_unscheduled_maintenance(later_t, half_an_hour, :summary => 'spoo')
|
152
|
+
|
153
|
+
ec.should be_in_unscheduled_maintenance
|
154
|
+
|
155
|
+
umps = ec.maintenances(nil, nil, :scheduled => false)
|
156
|
+
umps.should_not be_nil
|
157
|
+
umps.should be_an(Array)
|
158
|
+
umps.should have(2).unscheduled_maintenance_periods
|
159
|
+
umps[0].should be_a(Hash)
|
160
|
+
|
161
|
+
start_time = umps[0][:start_time]
|
162
|
+
start_time.should_not be_nil
|
163
|
+
start_time.should be_an(Integer)
|
164
|
+
start_time.should == t
|
165
|
+
|
166
|
+
duration = umps[0][:duration]
|
167
|
+
duration.should_not be_nil
|
168
|
+
duration.should be_a(Float)
|
169
|
+
duration.should == (15 * 60)
|
170
|
+
|
171
|
+
start_time_curr = umps[1][:start_time]
|
172
|
+
start_time_curr.should_not be_nil
|
173
|
+
start_time_curr.should be_an(Integer)
|
174
|
+
start_time_curr.should == later_t
|
175
|
+
|
176
|
+
duration_curr = umps[1][:duration]
|
177
|
+
duration_curr.should_not be_nil
|
178
|
+
duration_curr.should be_a(Float)
|
179
|
+
duration_curr.should == half_an_hour
|
180
|
+
end
|
181
|
+
|
182
|
+
it "ends an unscheduled maintenance period" do
|
183
|
+
t = Time.now.to_i
|
184
|
+
later_t = t + (15 * 60)
|
185
|
+
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
186
|
+
|
187
|
+
ec.create_unscheduled_maintenance(t, half_an_hour, :summary => 'oops')
|
188
|
+
ec.should be_in_unscheduled_maintenance
|
189
|
+
|
190
|
+
Delorean.time_travel_to( Time.at(later_t) )
|
191
|
+
ec.should be_in_unscheduled_maintenance
|
192
|
+
ec.end_unscheduled_maintenance(later_t)
|
193
|
+
ec.should_not be_in_unscheduled_maintenance
|
194
|
+
|
195
|
+
umps = ec.maintenances(nil, nil, :scheduled => false)
|
196
|
+
umps.should_not be_nil
|
197
|
+
umps.should be_an(Array)
|
198
|
+
umps.should have(1).unscheduled_maintenance_period
|
199
|
+
umps[0].should be_a(Hash)
|
200
|
+
|
201
|
+
start_time = umps[0][:start_time]
|
202
|
+
start_time.should_not be_nil
|
203
|
+
start_time.should be_an(Integer)
|
204
|
+
start_time.should == t
|
205
|
+
|
206
|
+
duration = umps[0][:duration]
|
207
|
+
duration.should_not be_nil
|
208
|
+
duration.should be_a(Float)
|
209
|
+
duration.should == (15 * 60)
|
210
|
+
end
|
211
|
+
|
137
212
|
it "creates a scheduled maintenance period for a future time" do
|
138
213
|
t = Time.now.to_i
|
139
214
|
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
140
|
-
ec.create_scheduled_maintenance(
|
141
|
-
|
215
|
+
ec.create_scheduled_maintenance(t + (60 * 60),
|
216
|
+
half_an_hour, :summary => "30 minutes")
|
142
217
|
|
143
218
|
smps = ec.maintenances(nil, nil, :scheduled => true)
|
144
219
|
smps.should_not be_nil
|
@@ -161,8 +236,8 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
161
236
|
it "creates a scheduled maintenance period covering the current time" do
|
162
237
|
t = Time.now.to_i
|
163
238
|
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
164
|
-
ec.create_scheduled_maintenance(
|
165
|
-
|
239
|
+
ec.create_scheduled_maintenance(t - (60 * 60),
|
240
|
+
2 * (60 * 60), :summary => "2 hours")
|
166
241
|
|
167
242
|
smps = ec.maintenances(nil, nil, :scheduled => true)
|
168
243
|
smps.should_not be_nil
|
@@ -184,8 +259,8 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
184
259
|
it "removes a scheduled maintenance period for a future time" do
|
185
260
|
t = Time.now.to_i
|
186
261
|
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
187
|
-
ec.create_scheduled_maintenance(
|
188
|
-
|
262
|
+
ec.create_scheduled_maintenance(t + (60 * 60),
|
263
|
+
2 * (60 * 60), :summary => "2 hours")
|
189
264
|
|
190
265
|
ec.end_scheduled_maintenance(t + (60 * 60))
|
191
266
|
|
@@ -200,8 +275,8 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
200
275
|
it "shortens a scheduled maintenance period covering a current time", :time => true do
|
201
276
|
t = Time.now.to_i
|
202
277
|
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
203
|
-
ec.create_scheduled_maintenance(
|
204
|
-
|
278
|
+
ec.create_scheduled_maintenance(t + (60 * 60),
|
279
|
+
2 * (60 * 60), :summary => "2 hours")
|
205
280
|
|
206
281
|
Delorean.time_travel_to( Time.at(t + (90 * 60)) )
|
207
282
|
|
@@ -218,8 +293,8 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
218
293
|
it "does not alter or remove a scheduled maintenance period covering a past time", :time => true do
|
219
294
|
t = Time.now.to_i
|
220
295
|
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
221
|
-
ec.create_scheduled_maintenance(
|
222
|
-
|
296
|
+
ec.create_scheduled_maintenance(t + (60 * 60),
|
297
|
+
2 * (60 * 60), :summary => "2 hours")
|
223
298
|
|
224
299
|
Delorean.time_travel_to( Time.at(t + (6 * (60 * 60)) ))
|
225
300
|
|
@@ -239,10 +314,10 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
239
314
|
three_hours_ago = t - (60 * 60 * 3)
|
240
315
|
|
241
316
|
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
242
|
-
ec.create_scheduled_maintenance(
|
243
|
-
:
|
244
|
-
ec.create_scheduled_maintenance(
|
245
|
-
:
|
317
|
+
ec.create_scheduled_maintenance(five_hours_ago, half_an_hour,
|
318
|
+
:summary => "first")
|
319
|
+
ec.create_scheduled_maintenance(three_hours_ago, half_an_hour,
|
320
|
+
:summary => "second")
|
246
321
|
|
247
322
|
smp = ec.maintenances(nil, nil, :scheduled => true)
|
248
323
|
smp.should_not be_nil
|
@@ -264,10 +339,10 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
264
339
|
three_hours_ago = t - (60 * 60 * 3)
|
265
340
|
|
266
341
|
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
267
|
-
ec.create_unscheduled_maintenance(
|
268
|
-
|
269
|
-
ec.create_unscheduled_maintenance(
|
270
|
-
|
342
|
+
ec.create_unscheduled_maintenance(five_hours_ago,
|
343
|
+
half_an_hour, :summary => "first")
|
344
|
+
ec.create_unscheduled_maintenance(three_hours_ago,
|
345
|
+
half_an_hour, :summary => "second")
|
271
346
|
|
272
347
|
ump = ec.maintenances(nil, nil, :scheduled => false)
|
273
348
|
ump.should_not be_nil
|
@@ -305,6 +380,47 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
305
380
|
state.should == 'critical'
|
306
381
|
end
|
307
382
|
|
383
|
+
it "updates enabled checks" do
|
384
|
+
ts = Time.now.to_i
|
385
|
+
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
386
|
+
ec.last_update = ts
|
387
|
+
|
388
|
+
saved_check_ts = @redis.zscore("current_checks:#{name}", check)
|
389
|
+
saved_check_ts.should_not be_nil
|
390
|
+
saved_check_ts.should == ts
|
391
|
+
saved_entity_ts = @redis.zscore("current_entities", name)
|
392
|
+
saved_entity_ts.should_not be_nil
|
393
|
+
saved_entity_ts.should == ts
|
394
|
+
end
|
395
|
+
|
396
|
+
it "exposes that it is enabled" do
|
397
|
+
@redis.zadd("current_checks:#{name}", Time.now.to_i, check)
|
398
|
+
@redis.zadd("current_entities", Time.now.to_i, name)
|
399
|
+
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
400
|
+
|
401
|
+
e = ec.enabled?
|
402
|
+
e.should be_true
|
403
|
+
end
|
404
|
+
|
405
|
+
it "exposes that it is disabled" do
|
406
|
+
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
407
|
+
|
408
|
+
e = ec.enabled?
|
409
|
+
e.should be_false
|
410
|
+
end
|
411
|
+
|
412
|
+
it "disables checks" do
|
413
|
+
@redis.zadd("current_checks:#{name}", Time.now.to_i, check)
|
414
|
+
@redis.zadd("current_entities", Time.now.to_i, name)
|
415
|
+
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
416
|
+
ec.disable!
|
417
|
+
|
418
|
+
saved_check_ts = @redis.zscore("current_checks:#{name}", check)
|
419
|
+
saved_entity_ts = @redis.zscore("current_entities", name)
|
420
|
+
saved_check_ts.should be_nil
|
421
|
+
saved_entity_ts.should be_nil
|
422
|
+
end
|
423
|
+
|
308
424
|
it "does not update state with invalid value" do
|
309
425
|
@redis.hset("check:#{name}:#{check}", 'state', 'ok')
|
310
426
|
|
@@ -386,12 +502,12 @@ describe Flapjack::Data::EntityCheck, :redis => true do
|
|
386
502
|
|
387
503
|
t = Time.now.to_i
|
388
504
|
|
389
|
-
ec.create_scheduled_maintenance(
|
390
|
-
|
391
|
-
ec.create_scheduled_maintenance(
|
392
|
-
|
393
|
-
ec.create_scheduled_maintenance(
|
394
|
-
|
505
|
+
ec.create_scheduled_maintenance(time_before(t, 180),
|
506
|
+
half_an_hour, :summary => "a")
|
507
|
+
ec.create_scheduled_maintenance(time_before(t, 120),
|
508
|
+
half_an_hour, :summary => "b")
|
509
|
+
ec.create_scheduled_maintenance(time_before(t, 60),
|
510
|
+
half_an_hour, :summary => "c")
|
395
511
|
|
396
512
|
sched_maint_periods = ec.maintenances(time_before(t, 150), t,
|
397
513
|
:scheduled => true)
|
@@ -90,8 +90,8 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
90
90
|
'name' => name},
|
91
91
|
:redis => @redis)
|
92
92
|
|
93
|
-
@redis.
|
94
|
-
@redis.
|
93
|
+
@redis.zadd("current_checks:#{name}", Time.now.to_i, "ping")
|
94
|
+
@redis.zadd("current_checks:#{name}", Time.now.to_i, "ssh")
|
95
95
|
|
96
96
|
entity = Flapjack::Data::Entity.find_by_name(name, :redis => @redis)
|
97
97
|
check_list = entity.check_list
|
@@ -108,8 +108,8 @@ describe Flapjack::Data::Entity, :redis => true do
|
|
108
108
|
'contacts' => []},
|
109
109
|
:redis => @redis)
|
110
110
|
|
111
|
-
@redis.
|
112
|
-
@redis.
|
111
|
+
@redis.zadd("current_checks:#{name}", Time.now.to_i, "ping")
|
112
|
+
@redis.zadd("current_checks:#{name}", Time.now.to_i, "ssh")
|
113
113
|
|
114
114
|
entity = Flapjack::Data::Entity.find_by_id(5000, :redis => @redis)
|
115
115
|
check_count = entity.check_count
|
@@ -26,14 +26,14 @@ describe Flapjack::Data::Event do
|
|
26
26
|
mock_redis.should_receive(:brpoplpush).with('events', /^events_archive:/, 0).and_return(event_data.to_json)
|
27
27
|
mock_redis.should_receive(:expire)
|
28
28
|
|
29
|
-
result = Flapjack::Data::Event.next(:block => true, :archive_events => true, :redis => mock_redis)
|
29
|
+
result = Flapjack::Data::Event.next('events', :block => true, :archive_events => true, :redis => mock_redis)
|
30
30
|
result.should be_an_instance_of(Flapjack::Data::Event)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns the next event (blocking, not archiving)" do
|
34
34
|
mock_redis.should_receive(:brpop).with('events', 0).and_return(['events', event_data.to_json])
|
35
35
|
|
36
|
-
result = Flapjack::Data::Event.next(:block => true, :archive_events => false, :redis => mock_redis)
|
36
|
+
result = Flapjack::Data::Event.next('events', :block => true, :archive_events => false, :redis => mock_redis)
|
37
37
|
result.should be_an_instance_of(Flapjack::Data::Event)
|
38
38
|
end
|
39
39
|
|
@@ -41,14 +41,14 @@ describe Flapjack::Data::Event do
|
|
41
41
|
mock_redis.should_receive(:rpoplpush).with('events', /^events_archive:/).and_return(event_data.to_json)
|
42
42
|
mock_redis.should_receive(:expire)
|
43
43
|
|
44
|
-
result = Flapjack::Data::Event.next(:block => false, :archive_events => true, :redis => mock_redis)
|
44
|
+
result = Flapjack::Data::Event.next('events', :block => false, :archive_events => true, :redis => mock_redis)
|
45
45
|
result.should be_an_instance_of(Flapjack::Data::Event)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "returns the next event (non-blocking, not archiving)" do
|
49
49
|
mock_redis.should_receive(:rpop).with('events').and_return(event_data.to_json)
|
50
50
|
|
51
|
-
result = Flapjack::Data::Event.next(:block => false, :archive_events => false, :redis => mock_redis)
|
51
|
+
result = Flapjack::Data::Event.next('events', :block => false, :archive_events => false, :redis => mock_redis)
|
52
52
|
result.should be_an_instance_of(Flapjack::Data::Event)
|
53
53
|
end
|
54
54
|
|
@@ -14,14 +14,13 @@ describe Flapjack::Data::Message do
|
|
14
14
|
|
15
15
|
it "returns its contained data" do
|
16
16
|
message = Flapjack::Data::Message.for_contact(contact, :medium => 'email',
|
17
|
-
:address => 'jja@example.com'
|
17
|
+
:address => 'jja@example.com')
|
18
18
|
|
19
19
|
contact.should_receive(:id).and_return('23')
|
20
20
|
contact.should_receive(:first_name).and_return('James')
|
21
21
|
contact.should_receive(:last_name).and_return('Jameson')
|
22
22
|
|
23
|
-
message.contents.should include('
|
24
|
-
'contact_id' => '23',
|
23
|
+
message.contents.should include('contact_id' => '23',
|
25
24
|
'contact_first_name' => 'James',
|
26
25
|
'contact_last_name' => 'Jameson',
|
27
26
|
'media' => 'email',
|
@@ -9,33 +9,27 @@ describe Flapjack::Data::Notification, :redis => true, :logger => true do
|
|
9
9
|
|
10
10
|
let(:timezone) { mock('timezone') }
|
11
11
|
|
12
|
-
it "generates a notification for an event" do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
12
|
+
it "generates a notification for an event" # do
|
13
|
+
# notification = Flapjack::Data::Notification.for_event(event, :type => 'problem',
|
14
|
+
# :max_notified_severity => nil, :contacts => [contact],
|
15
|
+
# :default_timezone => timezone, :logger => @logger)
|
16
|
+
# notification.should_not be_nil
|
17
|
+
# notification.event.should == event
|
18
|
+
# notification.type.should == 'problem'
|
19
|
+
# end
|
20
20
|
|
21
21
|
it "generates messages for contacts" do
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
# TODO sensible default values for notification, check that they're passed
|
23
|
+
# in message.notification_contents
|
24
|
+
notification = Flapjack::Data::Notification.new
|
25
25
|
|
26
26
|
contact.should_receive(:id).and_return('23')
|
27
27
|
contact.should_receive(:notification_rules).and_return([])
|
28
28
|
contact.should_receive(:media).and_return('email' => 'example@example.com',
|
29
29
|
'sms' => '0123456789')
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
event.should_receive(:summary).and_return('Shiny & happy')
|
34
|
-
event.should_receive(:details).and_return('Really Shiny & happy')
|
35
|
-
event.should_receive(:time).and_return(Time.now.to_i)
|
36
|
-
event.should_receive(:duration).and_return(nil)
|
37
|
-
|
38
|
-
messages = notification.messages
|
31
|
+
messages = notification.messages([contact], :default_timezone => timezone,
|
32
|
+
:logger => @logger)
|
39
33
|
messages.should_not be_nil
|
40
34
|
messages.should have(2).items
|
41
35
|
|
@@ -376,7 +376,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
376
376
|
|
377
377
|
it "deletes an unscheduled maintenance period for an entity check" do
|
378
378
|
end_time = Time.now + (60 * 60) # an hour from now
|
379
|
-
entity_check.should_receive(:end_unscheduled_maintenance).with(
|
379
|
+
entity_check.should_receive(:end_unscheduled_maintenance).with(end_time.to_i)
|
380
380
|
|
381
381
|
Flapjack::Data::EntityCheck.should_receive(:for_entity).
|
382
382
|
with(entity, check, :redis => redis).and_return(entity_check)
|
@@ -396,7 +396,7 @@ describe 'Flapjack::Gateways::API::EntityMethods', :sinatra => true, :logger =>
|
|
396
396
|
Flapjack::Data::EntityCheck.should_receive(:for_entity).
|
397
397
|
with(entity, check, :redis => redis).and_return(entity_check)
|
398
398
|
entity_check.should_receive(:create_scheduled_maintenance).
|
399
|
-
with(
|
399
|
+
with(start.getutc.to_i, duration, :summary => 'test')
|
400
400
|
|
401
401
|
post "/scheduled_maintenances/#{entity_name_esc}/#{check}?" +
|
402
402
|
"start_time=#{CGI.escape(start.iso8601)}&summary=test&duration=#{duration}"
|
@@ -83,6 +83,40 @@ describe Flapjack::Gateways::Jabber, :logger => true do
|
|
83
83
|
fj.on_groupchat(stanza)
|
84
84
|
end
|
85
85
|
|
86
|
+
it "strips XML tags from the received message" do
|
87
|
+
stanza.should_receive(:body).
|
88
|
+
and_return('flapjack: tell me about <span style="text-decoration: underline;">' +
|
89
|
+
'<a href="http://example.org/">example.org</a></span>')
|
90
|
+
|
91
|
+
from = mock('from')
|
92
|
+
from.should_receive(:stripped).and_return('sender')
|
93
|
+
stanza.should_receive(:from).and_return(from)
|
94
|
+
|
95
|
+
redis = mock('redis')
|
96
|
+
entity = mock(Flapjack::Data::Entity)
|
97
|
+
entity.should_receive(:check_list).and_return(['ping'])
|
98
|
+
|
99
|
+
Flapjack::Data::Entity.should_receive(:find_by_name).with('example.org',
|
100
|
+
:redis => redis).and_return(entity)
|
101
|
+
|
102
|
+
entity_check = mock(Flapjack::Data::EntityCheck)
|
103
|
+
entity_check.should_receive(:current_maintenance).with(:scheduled => true).and_return(nil)
|
104
|
+
entity_check.should_receive(:current_maintenance).with(:unscheduled => true).and_return(nil)
|
105
|
+
entity_check.should_receive(:check).and_return('ping')
|
106
|
+
|
107
|
+
Flapjack::Data::EntityCheck.should_receive(:for_entity).with(entity, 'ping',
|
108
|
+
:redis => redis).and_return(entity_check)
|
109
|
+
|
110
|
+
Flapjack::RedisPool.should_receive(:new).and_return(redis)
|
111
|
+
fj = Flapjack::Gateways::Jabber.new(:config => config, :logger => @logger)
|
112
|
+
|
113
|
+
EventMachine::Synchrony.should_receive(:next_tick).and_yield
|
114
|
+
fj.should_receive(:connected?).and_return(true)
|
115
|
+
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Message))
|
116
|
+
|
117
|
+
fj.on_groupchat(stanza)
|
118
|
+
end
|
119
|
+
|
86
120
|
it "receives a message it doesn't understand" do
|
87
121
|
stanza.should_receive(:body).once.and_return('flapjack: hello!')
|
88
122
|
from = mock('from')
|