flapjack 0.7.28 → 0.7.29

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +10 -0
  3. data/features/notification_rules.feature +25 -25
  4. data/features/rollup.feature +38 -18
  5. data/features/steps/events_steps.rb +10 -5
  6. data/features/steps/notifications_steps.rb +8 -4
  7. data/lib/flapjack/data/alert.rb +207 -0
  8. data/lib/flapjack/data/contact.rb +14 -7
  9. data/lib/flapjack/data/entity_check.rb +4 -3
  10. data/lib/flapjack/data/notification.rb +28 -27
  11. data/lib/flapjack/gateways/api/contact_methods.rb +32 -12
  12. data/lib/flapjack/gateways/email.rb +49 -53
  13. data/lib/flapjack/gateways/email/alert.html.erb +15 -15
  14. data/lib/flapjack/gateways/email/alert.text.erb +15 -15
  15. data/lib/flapjack/gateways/email/alert_subject.text.erb +3 -13
  16. data/lib/flapjack/gateways/email/rollup.html.erb +6 -6
  17. data/lib/flapjack/gateways/email/rollup.text.erb +7 -7
  18. data/lib/flapjack/gateways/email/rollup_subject.text.erb +1 -19
  19. data/lib/flapjack/gateways/jabber.rb +57 -47
  20. data/lib/flapjack/gateways/jabber/alert.text.erb +12 -0
  21. data/lib/flapjack/gateways/jabber/rollup.text.erb +2 -0
  22. data/lib/flapjack/gateways/pagerduty.rb +60 -30
  23. data/lib/flapjack/gateways/pagerduty/alert.text.erb +10 -0
  24. data/lib/flapjack/gateways/sms_messagenet.rb +29 -36
  25. data/lib/flapjack/gateways/sms_messagenet/alert.text.erb +4 -14
  26. data/lib/flapjack/gateways/sms_messagenet/rollup.text.erb +2 -34
  27. data/lib/flapjack/gateways/web.rb +23 -14
  28. data/lib/flapjack/gateways/web/views/check.html.erb +16 -11
  29. data/lib/flapjack/gateways/web/views/contact.html.erb +58 -16
  30. data/lib/flapjack/gateways/web/views/self_stats.html.erb +80 -71
  31. data/lib/flapjack/notifier.rb +8 -2
  32. data/lib/flapjack/pikelet.rb +17 -3
  33. data/lib/flapjack/processor.rb +0 -1
  34. data/lib/flapjack/redis_pool.rb +1 -1
  35. data/lib/flapjack/utility.rb +13 -0
  36. data/lib/flapjack/version.rb +1 -1
  37. data/spec/lib/flapjack/data/contact_spec.rb +44 -29
  38. data/spec/lib/flapjack/gateways/api/contact_methods_spec.rb +24 -4
  39. data/spec/lib/flapjack/gateways/email_spec.rb +0 -5
  40. data/spec/lib/flapjack/gateways/jabber_spec.rb +5 -1
  41. data/spec/lib/flapjack/gateways/pagerduty_spec.rb +5 -2
  42. data/spec/lib/flapjack/gateways/{sms_messagenet.spec.rb → sms_messagenet_spec.rb} +16 -12
  43. data/spec/lib/flapjack/gateways/web_spec.rb +1 -1
  44. data/spec/spec_helper.rb +28 -6
  45. metadata +43 -89
@@ -92,6 +92,15 @@ module Flapjack
92
92
  def stop
93
93
  @status = 'stopping'
94
94
  end
95
+
96
+ def configure_resque
97
+ unless ::Resque.instance_variable_defined?('@flapjack_pool') && !::Resque.instance_variable_get('@flapjack_pool').nil?
98
+ resque_pool = Flapjack::RedisPool.new(:config => @redis_config)
99
+ ::Resque.instance_variable_set('@flapjack_pool', resque_pool)
100
+ ::Resque.redis = resque_pool
101
+ end
102
+ end
103
+
95
104
  end
96
105
 
97
106
  class Generic < Flapjack::Pikelet::Base
@@ -111,6 +120,9 @@ module Flapjack
111
120
 
112
121
  def initialize(type, pikelet_klass, opts = {})
113
122
  super(type, pikelet_klass, opts)
123
+
124
+ configure_resque if type == 'notifier'
125
+
114
126
  @pikelet = @klass.new(opts.merge(:logger => @logger))
115
127
  end
116
128
 
@@ -138,6 +150,7 @@ module Flapjack
138
150
  return @status unless 'stopping'.eql?(@status)
139
151
  @status = 'stopped' if @fiber && !@fiber.alive?
140
152
  end
153
+
141
154
  end
142
155
 
143
156
  class Resque < Flapjack::Pikelet::Base
@@ -154,9 +167,10 @@ module Flapjack
154
167
  def initialize(type, pikelet_klass, opts = {})
155
168
  super(type, pikelet_klass, opts)
156
169
 
157
- unless defined?(@@resque_pool) && !@@resque_pool.nil?
158
- @@resque_pool = Flapjack::RedisPool.new(:config => @redis_config)
159
- ::Resque.redis = @@resque_pool
170
+ configure_resque
171
+
172
+ # guard against another Resque pikelet having created the pool already
173
+ unless defined?(@@redis_connection) && !@@redis_connection.nil?
160
174
  @@redis_connection = Flapjack::RedisPool.new(:config => @redis_config)
161
175
  end
162
176
 
@@ -66,7 +66,6 @@ module Flapjack
66
66
  @redis.hset('event_counters', 'action', 0)
67
67
  end
68
68
 
69
- #@redis.zadd('executive_instances', boot_time.to_i, @instance_id)
70
69
  @redis.hset("executive_instance:#{@instance_id}", 'boot_time', boot_time.to_i)
71
70
  @redis.hset("event_counters:#{@instance_id}", 'all', 0)
72
71
  @redis.hset("event_counters:#{@instance_id}", 'ok', 0)
@@ -22,4 +22,4 @@ module Flapjack
22
22
  end
23
23
 
24
24
  end
25
- end
25
+ end
@@ -4,6 +4,7 @@ module Flapjack
4
4
  module Utility
5
5
 
6
6
  def time_period_in_words(period)
7
+ return "0 seconds" unless period.is_a?(Integer) && period > 0
7
8
  period_mm, period_ss = period.divmod(60)
8
9
  period_hh, period_mm = period_mm.divmod(60)
9
10
  period_dd, period_hh = period_hh.divmod(24)
@@ -68,6 +69,18 @@ module Flapjack
68
69
  Hash[ *( key_value_pairs.flatten(1) )]
69
70
  end
70
71
 
72
+ # copied from ActiveSupport
73
+ def truncate(str, length, options = {})
74
+ text = str.dup
75
+ options[:omission] ||= "..."
76
+
77
+ length_with_room_for_omission = length - options[:omission].length
78
+ stop = options[:separator] ?
79
+ (text.rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission) : length_with_room_for_omission
80
+
81
+ (text.length > length ? text[0...stop] + options[:omission] : text).to_s
82
+ end
83
+
71
84
  private
72
85
 
73
86
  def plural_s(value)
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Flapjack
4
- VERSION = "0.7.28"
4
+ VERSION = "0.7.29"
5
5
  end
@@ -37,7 +37,7 @@ describe Flapjack::Data::Contact, :redis => true do
37
37
 
38
38
  before(:each) do
39
39
  Flapjack::Data::Contact.add( {
40
- 'id' => '362',
40
+ 'id' => 'c362',
41
41
  'first_name' => 'John',
42
42
  'last_name' => 'Johnson',
43
43
  'email' => 'johnj@example.com',
@@ -53,7 +53,7 @@ describe Flapjack::Data::Contact, :redis => true do
53
53
  :redis => @redis)
54
54
 
55
55
  Flapjack::Data::Contact.add( {
56
- 'id' => '363',
56
+ 'id' => 'c363_a-f@42%*',
57
57
  'first_name' => 'Jane',
58
58
  'last_name' => 'Janeley',
59
59
  'email' => 'janej@example.com',
@@ -78,13 +78,13 @@ describe Flapjack::Data::Contact, :redis => true do
78
78
  end
79
79
 
80
80
  it "finds a contact by id" do
81
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
81
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
82
82
  contact.should_not be_nil
83
83
  contact.name.should == "John Johnson"
84
84
  end
85
85
 
86
86
  it "adds a contact with the same id as an existing one, clears notification rules" do
87
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
87
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
88
88
  contact.should_not be_nil
89
89
 
90
90
  contact.add_notification_rule(notification_rule_data)
@@ -93,13 +93,13 @@ describe Flapjack::Data::Contact, :redis => true do
93
93
  nr.should_not be_nil
94
94
  nr.should have(2).notification_rules
95
95
 
96
- Flapjack::Data::Contact.add({'id' => '363',
96
+ Flapjack::Data::Contact.add({'id' => 'c363_a-f@42%*',
97
97
  'first_name' => 'Smithy',
98
98
  'last_name' => 'Smith',
99
99
  'email' => 'smithys@example.com'},
100
100
  :redis => @redis)
101
101
 
102
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
102
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
103
103
  contact.should_not be_nil
104
104
  contact.name.should == 'Smithy Smith'
105
105
  rules = contact.notification_rules
@@ -108,14 +108,14 @@ describe Flapjack::Data::Contact, :redis => true do
108
108
  end
109
109
 
110
110
  it "updates a contact and clears their media settings" do
111
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
111
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
112
112
 
113
113
  contact.update('media' => {})
114
114
  contact.media.should be_empty
115
115
  end
116
116
 
117
117
  it "updates a contact, does not clear notification rules" do
118
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
118
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
119
119
  contact.should_not be_nil
120
120
 
121
121
  contact.add_notification_rule(notification_rule_data)
@@ -136,7 +136,7 @@ describe Flapjack::Data::Contact, :redis => true do
136
136
  end
137
137
 
138
138
  it "adds a notification rule for a contact" do
139
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
139
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
140
140
  contact.should_not be_nil
141
141
 
142
142
  expect {
@@ -145,7 +145,7 @@ describe Flapjack::Data::Contact, :redis => true do
145
145
  end
146
146
 
147
147
  it "removes a notification rule from a contact" do
148
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
148
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
149
149
  contact.should_not be_nil
150
150
 
151
151
  rule = contact.add_notification_rule(notification_rule_data)
@@ -156,12 +156,12 @@ describe Flapjack::Data::Contact, :redis => true do
156
156
  end
157
157
 
158
158
  it "creates a general notification rule for a pre-existing contact if none exists" do
159
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
159
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
160
160
 
161
- @redis.smembers("contact_notification_rules:363").each do |rule_id|
162
- @redis.srem("contact_notification_rules:363", rule_id)
161
+ @redis.smembers("contact_notification_rules:c363_a-f@42%*").each do |rule_id|
162
+ @redis.srem("contact_notification_rules:c363_a-f@42%*", rule_id)
163
163
  end
164
- @redis.smembers("contact_notification_rules:363").should be_empty
164
+ @redis.smembers("contact_notification_rules:c363_a-f@42%*").should be_empty
165
165
 
166
166
  rules = contact.notification_rules
167
167
  rules.should have(1).rule
@@ -174,7 +174,7 @@ describe Flapjack::Data::Contact, :redis => true do
174
174
  end
175
175
 
176
176
  it "creates a general notification rule for a pre-existing contact if the existing general one was changed" do
177
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
177
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
178
178
  rules = contact.notification_rules
179
179
  rules.should have(1).notification_rule
180
180
  rule = rules.first
@@ -187,14 +187,14 @@ describe Flapjack::Data::Contact, :redis => true do
187
187
  end
188
188
 
189
189
  it "deletes a contact by id, including linked entities, checks, tags and notification rules" do
190
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
190
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
191
191
  contact.add_tags('admin')
192
192
 
193
193
  entity_name = 'abc-123'
194
194
 
195
195
  entity = Flapjack::Data::Entity.add({'id' => '5000',
196
196
  'name' => entity_name,
197
- 'contacts' => ['362']},
197
+ 'contacts' => ['c362']},
198
198
  :redis => @redis)
199
199
 
200
200
  expect {
@@ -213,7 +213,7 @@ describe Flapjack::Data::Contact, :redis => true do
213
213
 
214
214
  Flapjack::Data::Entity.add({'id' => '5000',
215
215
  'name' => entity_name,
216
- 'contacts' => ['362']},
216
+ 'contacts' => ['c362']},
217
217
  :redis => @redis)
218
218
 
219
219
  ec = Flapjack::Data::EntityCheck.for_entity_name(entity_name, 'PING', :redis => @redis)
@@ -221,7 +221,7 @@ describe Flapjack::Data::Contact, :redis => true do
221
221
  ec.update_state('ok', :timestamp => t, :summary => 'a')
222
222
  ec.last_update = t
223
223
 
224
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
224
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
225
225
  eandcs = contact.entities(:checks => true)
226
226
  eandcs.should_not be_nil
227
227
  eandcs.should be_an(Array)
@@ -239,7 +239,7 @@ describe Flapjack::Data::Contact, :redis => true do
239
239
  end
240
240
 
241
241
  it "returns pagerduty credentials for a contact" do
242
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
242
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
243
243
  credentials = contact.pagerduty_credentials
244
244
  credentials.should_not be_nil
245
245
  credentials.should be_a(Hash)
@@ -249,41 +249,56 @@ describe Flapjack::Data::Contact, :redis => true do
249
249
  'password' => 'very_secure'}
250
250
  end
251
251
 
252
+ it "sets pagerduty credentials for a contact" do
253
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
254
+ contact.set_pagerduty_credentials('service_key' => '567890123456789012345678',
255
+ 'subdomain' => 'eggs',
256
+ 'username' => 'flapjack',
257
+ 'password' => 'tomato')
258
+
259
+ @redis.hget('contact_media:c362', 'pagerduty').should == '567890123456789012345678'
260
+ @redis.hgetall('contact_pagerduty:c362').should == {
261
+ 'subdomain' => 'eggs',
262
+ 'username' => 'flapjack',
263
+ 'password' => 'tomato'
264
+ }
265
+ end
266
+
252
267
  it "sets the interval for a contact's media" do
253
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
268
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
254
269
  contact.set_interval_for_media('email', 42)
255
270
  email_interval_raw = @redis.hget("contact_media_intervals:#{contact.id}", 'email')
256
271
  email_interval_raw.should == '42'
257
272
  end
258
273
 
259
274
  it "returns the interval for a contact's media" do
260
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
275
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
261
276
  email_interval = contact.interval_for_media('email')
262
277
  email_interval.should == 60
263
278
  end
264
279
 
265
280
  it "returns default 15 mins for interval for a contact's media that has no set interval" do
266
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
281
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
267
282
  email_interval = contact.interval_for_media('email')
268
283
  email_interval.should == 900
269
284
  end
270
285
 
271
286
  it "removes the interval for a contact's media" do
272
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
287
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
273
288
  contact.set_interval_for_media('email', nil)
274
289
  email_interval_raw = @redis.hget("contact_media_intervals:#{contact.id}", 'email')
275
290
  email_interval_raw.should be_nil
276
291
  end
277
292
 
278
293
  it "sets the rollup threshold for a contact's media" do
279
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
294
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
280
295
  email_rollup_threshold = contact.set_rollup_threshold_for_media('email', 3)
281
296
  email_rollup_threshold_raw = @redis.hget("contact_media_rollup_thresholds:#{contact.id}", 'email')
282
297
  email_rollup_threshold_raw.should == '3'
283
298
  end
284
299
 
285
300
  it "returns the rollup threshold for a contact's media" do
286
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
301
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
287
302
  email_rollup_threshold = contact.rollup_threshold_for_media('email')
288
303
  email_rollup_threshold.should_not be_nil
289
304
  email_rollup_threshold.should be_a(Integer)
@@ -291,21 +306,21 @@ describe Flapjack::Data::Contact, :redis => true do
291
306
  end
292
307
 
293
308
  it "removes the rollup threshold for a contact's media" do
294
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
309
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
295
310
  email_rollup_threshold = contact.set_rollup_threshold_for_media('email', nil)
296
311
  email_rollup_threshold_raw = @redis.hget("contact_media_rollup_thresholds:#{contact.id}", 'email')
297
312
  email_rollup_threshold_raw.should be_nil
298
313
  end
299
314
 
300
315
  it "sets the address for a contact's media" do
301
- contact = Flapjack::Data::Contact.find_by_id('362', :redis => @redis)
316
+ contact = Flapjack::Data::Contact.find_by_id('c362', :redis => @redis)
302
317
  contact.set_address_for_media('email', 'spongebob@example.com')
303
318
  email_address_raw = @redis.hget("contact_media:#{contact.id}", 'email')
304
319
  email_address_raw.should == 'spongebob@example.com'
305
320
  end
306
321
 
307
322
  it "removes a contact's media" do
308
- contact = Flapjack::Data::Contact.find_by_id('363', :redis => @redis)
323
+ contact = Flapjack::Data::Contact.find_by_id('c363_a-f@42%*', :redis => @redis)
309
324
  contact.remove_media('email')
310
325
  email_address_raw = @redis.hget("contac_media:#{contact.id}", 'email')
311
326
  email_address_raw.should be_nil
@@ -434,7 +434,27 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
434
434
  'interval' => alt_media_intervals['sms'],
435
435
  'rollup_threshold' => alt_media_rollup_thresholds['sms']}
436
436
 
437
- put "/contacts/#{contact.id}/media/sms", {:address => '04987654321', :interval => '200', :rollup_threshold => '5'}
437
+ put "/contacts/#{contact.id}/media/sms", :address => '04987654321',
438
+ :interval => '200', :rollup_threshold => '5'
439
+ last_response.should be_ok
440
+ last_response.body.should be_json_eql(result.to_json)
441
+ end
442
+
443
+ it "updates a contact's pagerduty media credentials" do
444
+ result = {'service_key' => "flapjacktest@conference.jabber.sausage.net",
445
+ 'subdomain' => "sausage.pagerduty.com",
446
+ 'username' => "sausage@example.com",
447
+ 'password' => "sausage"}
448
+
449
+ contact.should_receive(:set_pagerduty_credentials).with(result)
450
+ contact.should_receive(:pagerduty_credentials).and_return(result)
451
+ Flapjack::Data::Contact.should_receive(:find_by_id).
452
+ with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
453
+
454
+ put "/contacts/#{contact.id}/media/pagerduty", :service_key => result['service_key'],
455
+ :subdomain => result['subdomain'], :username => result['username'],
456
+ :password => result['password']
457
+
438
458
  last_response.should be_ok
439
459
  last_response.body.should be_json_eql(result.to_json)
440
460
  end
@@ -443,7 +463,7 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
443
463
  Flapjack::Data::Contact.should_receive(:find_by_id).
444
464
  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
445
465
 
446
- put "/contacts/#{contact.id}/media/sms", {:address => '04987654321', :interval => '200'}
466
+ put "/contacts/#{contact.id}/media/sms", :address => '04987654321', :interval => '200'
447
467
  last_response.should be_forbidden
448
468
  end
449
469
 
@@ -451,7 +471,7 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
451
471
  Flapjack::Data::Contact.should_receive(:find_by_id).
452
472
  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
453
473
 
454
- put "/contacts/#{contact.id}/media/sms", {:interval => '200'}
474
+ put "/contacts/#{contact.id}/media/sms", :interval => '200'
455
475
  last_response.should be_forbidden
456
476
  end
457
477
 
@@ -469,7 +489,7 @@ describe 'Flapjack::Gateways::API::ContactMethods', :sinatra => true, :logger =>
469
489
  Flapjack::Data::Contact.should_receive(:find_by_id).
470
490
  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
471
491
 
472
- put "/contacts/#{contact.id}/media/sms", {:address => '04987654321'}
492
+ put "/contacts/#{contact.id}/media/sms", :address => '04987654321'
473
493
  last_response.should be_ok
474
494
  end
475
495
 
@@ -7,13 +7,8 @@ describe Flapjack::Gateways::Email, :logger => true do
7
7
  email = double('email')
8
8
 
9
9
  entity_check = double(Flapjack::Data::EntityCheck)
10
- entity_check.should_receive(:in_scheduled_maintenance?).and_return(false)
11
- entity_check.should_receive(:in_unscheduled_maintenance?).and_return(false)
12
10
  redis = double('redis')
13
11
 
14
- Flapjack::Data::EntityCheck.should_receive(:for_event_id).
15
- with('example.com:ping', :redis => redis).and_return(entity_check)
16
-
17
12
  # TODO better checking of what gets passed here
18
13
  EM::P::SmtpClient.should_receive(:send).with(
19
14
  hash_including(:host => 'localhost',
@@ -177,10 +177,12 @@ describe Flapjack::Gateways::Jabber, :logger => true do
177
177
 
178
178
  blpop_count = 0
179
179
 
180
+ event_json = '{"notification_type":"problem","event_id":"main-example.com:ping",' +
181
+ '"state":"critical","summary":"!!!","duration":43,"state_duration":76}'
180
182
  redis.should_receive(:blpop).twice {
181
183
  blpop_count += 1
182
184
  if blpop_count == 1
183
- ["jabber_notifications", %q{{"notification_type":"problem","event_id":"main-example.com:ping","state":"critical","summary":"!!!"}}]
185
+ ["jabber_notifications", event_json]
184
186
  else
185
187
  fj.instance_variable_set('@should_quit', true)
186
188
  ["jabber_notifications", %q{{"notification_type":"shutdown"}}]
@@ -192,6 +194,8 @@ describe Flapjack::Gateways::Jabber, :logger => true do
192
194
  fj.should_receive(:close)
193
195
 
194
196
  fj.start
197
+
198
+ @logger.errors.should be_empty
195
199
  end
196
200
 
197
201
  end
@@ -107,7 +107,7 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
107
107
  entity_check.should_receive(:contacts).and_return([contact])
108
108
  entity_check.should_receive(:entity_name).exactly(2).times.and_return('foo-app-01.bar.net')
109
109
  Flapjack::Data::Event.should_receive(:create_acknowledgement).with('foo-app-01.bar.net', 'PING',
110
- :summary => 'Acknowledged on PagerDuty', :redis => redis)
110
+ :summary => 'Acknowledged on PagerDuty', :duration => 14400, :redis => redis)
111
111
 
112
112
  Flapjack::Data::Global.should_receive(:unacknowledged_failing_checks).and_return([entity_check])
113
113
 
@@ -131,7 +131,8 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
131
131
  redis.should_receive(:blpop).twice {
132
132
  blpop_count += 1
133
133
  if blpop_count == 1
134
- ["pagerduty_notifications", %q{{"notification_type":"problem","event_id":"main-example.com:ping","state":"critical","summary":"!!!"}}]
134
+ ["pagerduty_notifications", '{"notification_type":"problem","event_id":"main-example.com:ping",' +
135
+ '"state":"critical","summary":"!!!","state_duration":120,"duration":30}']
135
136
  else
136
137
  fp.instance_variable_set('@should_quit', true)
137
138
  ["pagerduty_notifications", %q{{"notification_type":"shutdown"}}]
@@ -142,6 +143,8 @@ describe Flapjack::Gateways::Pagerduty, :logger => true do
142
143
  fp.should_receive(:send_pagerduty_event)
143
144
 
144
145
  fp.start
146
+
147
+ @logger.errors.should be_empty
145
148
  end
146
149
 
147
150
  it "tests the pagerduty connection" do