flapjack 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +11 -12
  4. data/CHANGELOG.md +10 -0
  5. data/Gemfile +0 -7
  6. data/Rakefile +0 -1
  7. data/bin/flapjack +2 -0
  8. data/etc/flapjack_config.yaml.example +20 -0
  9. data/features/ack_after_sched_maint.feature +1 -1
  10. data/features/cli.feature +1 -1
  11. data/features/notification_rules.feature +1 -1
  12. data/features/notifications.feature +0 -9
  13. data/features/rollup.feature +1 -1
  14. data/features/steps/events_steps.rb +20 -8
  15. data/features/steps/notifications_steps.rb +62 -75
  16. data/features/support/env.rb +17 -8
  17. data/flapjack.gemspec +4 -4
  18. data/lib/flapjack.rb +3 -0
  19. data/lib/flapjack/cli/import.rb +1 -0
  20. data/lib/flapjack/cli/maintenance.rb +1 -0
  21. data/lib/flapjack/cli/purge.rb +2 -0
  22. data/lib/flapjack/cli/receiver.rb +1 -0
  23. data/lib/flapjack/cli/simulate.rb +1 -0
  24. data/lib/flapjack/data/alert.rb +28 -1
  25. data/lib/flapjack/data/contact.rb +1 -1
  26. data/lib/flapjack/data/entity.rb +18 -8
  27. data/lib/flapjack/data/entity_check.rb +17 -0
  28. data/lib/flapjack/data/event.rb +33 -15
  29. data/lib/flapjack/data/migration.rb +46 -23
  30. data/lib/flapjack/filters/delays.rb +13 -6
  31. data/lib/flapjack/gateways/aws_sns.rb +115 -88
  32. data/lib/flapjack/gateways/aws_sns/alert.text.erb +2 -1
  33. data/lib/flapjack/gateways/email.rb +145 -135
  34. data/lib/flapjack/gateways/email/alert.html.erb +6 -4
  35. data/lib/flapjack/gateways/email/alert.text.erb +2 -0
  36. data/lib/flapjack/gateways/jabber.rb +61 -1
  37. data/lib/flapjack/gateways/jabber/alert.text.erb +1 -1
  38. data/lib/flapjack/gateways/pagerduty/alert.text.erb +1 -1
  39. data/lib/flapjack/gateways/sms_gammu.rb +119 -0
  40. data/lib/flapjack/gateways/sms_messagenet.rb +95 -67
  41. data/lib/flapjack/gateways/sms_messagenet/alert.text.erb +2 -1
  42. data/lib/flapjack/gateways/sms_twilio.rb +102 -74
  43. data/lib/flapjack/gateways/sms_twilio/alert.text.erb +2 -1
  44. data/lib/flapjack/logger.rb +1 -1
  45. data/lib/flapjack/notifier.rb +5 -14
  46. data/lib/flapjack/patches.rb +0 -58
  47. data/lib/flapjack/pikelet.rb +8 -78
  48. data/lib/flapjack/processor.rb +3 -1
  49. data/lib/flapjack/redis_pool.rb +2 -0
  50. data/lib/flapjack/version.rb +1 -1
  51. data/spec/lib/flapjack/data/contact_spec.rb +2 -2
  52. data/spec/lib/flapjack/data/entity_spec.rb +15 -0
  53. data/spec/lib/flapjack/data/event_spec.rb +2 -2
  54. data/spec/lib/flapjack/data/migration_spec.rb +11 -0
  55. data/spec/lib/flapjack/gateways/aws_sns_spec.rb +12 -8
  56. data/spec/lib/flapjack/gateways/email_spec.rb +56 -51
  57. data/spec/lib/flapjack/gateways/sms_messagenet_spec.rb +17 -12
  58. data/spec/lib/flapjack/gateways/sms_twilio_spec.rb +17 -12
  59. data/spec/lib/flapjack/pikelet_spec.rb +9 -23
  60. data/spec/lib/flapjack/redis_pool_spec.rb +1 -0
  61. data/tasks/profile.rake +25 -109
  62. metadata +37 -39
  63. data/Gemfile-ruby1.9 +0 -30
  64. data/Gemfile-ruby1.9.lock +0 -250
  65. data/tasks/benchmarks.rake +0 -237
@@ -226,7 +226,9 @@ module Flapjack
226
226
 
227
227
  entity_check.update_state(event.state, :timestamp => timestamp,
228
228
  :summary => event.summary, :count => event.counter,
229
- :details => event.details, :perfdata => event.perfdata)
229
+ :details => event.details, :perfdata => event.perfdata,
230
+ :initial_failure_delay => event.initial_failure_delay,
231
+ :repeat_failure_delay => event.repeat_failure_delay)
230
232
 
231
233
  entity_check.update_current_scheduled_maintenance
232
234
 
@@ -27,6 +27,8 @@ module Flapjack
27
27
  :logger => logger)
28
28
  Flapjack::Data::Migration.create_entity_ids_if_required(:redis => redis,
29
29
  :logger => logger)
30
+ Flapjack::Data::Migration.clear_orphaned_entity_ids(:redis => redis,
31
+ :logger => logger)
30
32
  Flapjack::Data::Migration.refresh_archive_index(:redis => redis)
31
33
  Flapjack::Data::Migration.validate_scheduled_maintenance_periods(:redis => redis,
32
34
  :logger => logger)
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Flapjack
4
- VERSION = "1.2.1"
4
+ VERSION = "1.2.2"
5
5
  end
6
6
 
@@ -22,8 +22,8 @@ describe Flapjack::Data::Contact, :redis => true do
22
22
  :tags => Set.new([]),
23
23
  :time_restrictions => [],
24
24
  :unknown_media => [],
25
- :warning_media => ['email', 'sms', 'sms_twilio', 'jabber', 'pagerduty', 'sns'],
26
- :critical_media => ['email', 'sms', 'sms_twilio', 'jabber', 'pagerduty', 'sns'],
25
+ :warning_media => ['email', 'sms', 'sms_twilio', 'sms_gammu', 'jabber', 'pagerduty', 'sns'],
26
+ :critical_media => ['email', 'sms', 'sms_twilio', 'sms_gammu', 'jabber', 'pagerduty', 'sns'],
27
27
  :unknown_blackhole => false,
28
28
  :warning_blackhole => false,
29
29
  :critical_blackhole => false}
@@ -223,6 +223,8 @@ describe Flapjack::Data::Entity, :redis => true do
223
223
  :redis => @redis)
224
224
  end
225
225
 
226
+ context 'check that rename and merge are called by add'
227
+
226
228
  context 'entity renaming on #add' do
227
229
 
228
230
  let(:time_i) { Time.now.to_i }
@@ -490,6 +492,19 @@ describe Flapjack::Data::Entity, :redis => true do
490
492
  add_name2
491
493
  end
492
494
 
495
+ it 'clears the old id when a name exists' do
496
+ expect(@redis.hget('all_entity_ids_by_name', 'name2')).to eq('5000')
497
+ expect(@redis.hget('all_entity_names_by_id', '5000')).to eq('name2')
498
+
499
+ Flapjack::Data::Entity.add({'id' => '5001',
500
+ 'name' => 'name2'},
501
+ :redis => @redis)
502
+
503
+ expect(@redis.hget('all_entity_ids_by_name', 'name2')).to eq('5001')
504
+ expect(@redis.hget('all_entity_names_by_id', '5000')).to be_nil
505
+ expect(@redis.hget('all_entity_names_by_id', '5001')).to eq('name2')
506
+ end
507
+
493
508
  it 'does not overwrite current state for a check' do
494
509
  add_state1
495
510
  data_2 = {'state' => 'critical', 'last_change' => time_2_i.to_s, 'last_update' => time_2_i.to_s}
@@ -101,7 +101,7 @@ describe Flapjack::Data::Event do
101
101
  expect(result).to be_nil
102
102
  end
103
103
 
104
- ['type', 'state', 'entity', 'check', 'summary'].each do |required_key|
104
+ ['type', 'state', 'entity', 'check'].each do |required_key|
105
105
 
106
106
  it "rejects an event with missing '#{required_key}' key (archiving)" do
107
107
  bad_event_data = event_data.clone
@@ -168,7 +168,7 @@ describe Flapjack::Data::Event do
168
168
  end
169
169
  end
170
170
 
171
- ['time', 'details', 'perfdata', 'acknowledgement_id', 'duration', 'tags'].each do |optional_key|
171
+ ['time', 'summary', 'details', 'perfdata', 'acknowledgement_id', 'duration', 'tags'].each do |optional_key|
172
172
  it "rejects an event with invalid '#{optional_key}' key (archiving)" do
173
173
  bad_event_data = event_data.clone
174
174
  bad_event_data[optional_key] = {'hello' => 'there'}
@@ -4,6 +4,17 @@ require 'flapjack/data/notification_rule'
4
4
 
5
5
  describe Flapjack::Data::Migration, :redis => true do
6
6
 
7
+ it 'removes an orphaned entity id' do
8
+ @redis.hset('all_entity_ids_by_name', 'name_1', 'id_2')
9
+ @redis.hset('all_entity_names_by_id', 'id_1', 'name_1')
10
+ @redis.hset('all_entity_names_by_id', 'id_2', 'name_1')
11
+
12
+ Flapjack::Data::Migration.clear_orphaned_entity_ids(:redis => @redis)
13
+
14
+ expect(@redis.hgetall('all_entity_ids_by_name')).to eq('name_1' => 'id_2')
15
+ expect(@redis.hgetall('all_entity_names_by_id')).to eq('id_2' => 'name_1')
16
+ end
17
+
7
18
  it "fixes a notification rule wih no contact association" do
8
19
  contact = Flapjack::Data::Contact.add( {
9
20
  'id' => 'c362',
@@ -5,6 +5,8 @@ describe Flapjack::Gateways::AwsSns, :logger => true do
5
5
 
6
6
  let(:lock) { double(Monitor) }
7
7
 
8
+ let(:redis) { double('redis') }
9
+
8
10
  let(:time) { Time.new(2013, 10, 31, 13, 45) }
9
11
 
10
12
  let(:time_str) { Time.at(time).strftime('%-d %b %H:%M') }
@@ -41,10 +43,11 @@ describe Flapjack::Gateways::AwsSns, :logger => true do
41
43
  to_return(:status => 200)
42
44
 
43
45
  EM.synchrony do
44
- Flapjack::Gateways::AwsSns.instance_variable_set('@config', config)
45
- Flapjack::Gateways::AwsSns.instance_variable_set('@logger', @logger)
46
- Flapjack::Gateways::AwsSns.start
47
- Flapjack::Gateways::AwsSns.perform(message)
46
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
47
+
48
+ alert = Flapjack::Data::Alert.new(message, :logger => @logger)
49
+ aws_sns = Flapjack::Gateways::AwsSns.new(:config => config, :logger => @logger)
50
+ aws_sns.deliver(alert)
48
51
  EM.stop
49
52
  end
50
53
  expect(req).to have_been_requested
@@ -52,10 +55,11 @@ describe Flapjack::Gateways::AwsSns, :logger => true do
52
55
 
53
56
  it "does not send an SMS message with an invalid config" do
54
57
  EM.synchrony do
55
- Flapjack::Gateways::AwsSns.instance_variable_set('@config', config.reject {|k, v| k == 'secret_key'})
56
- Flapjack::Gateways::AwsSns.instance_variable_set('@logger', @logger)
57
- Flapjack::Gateways::AwsSns.start
58
- Flapjack::Gateways::AwsSns.perform(message)
58
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
59
+
60
+ alert = Flapjack::Data::Alert.new(message, :logger => @logger)
61
+ aws_sns = Flapjack::Gateways::AwsSns.new(:config => config.reject {|k, v| k == 'secret_key'}, :logger => @logger)
62
+ aws_sns.deliver(alert)
59
63
  EM.stop
60
64
  end
61
65
 
@@ -3,21 +3,21 @@ require 'flapjack/gateways/email'
3
3
 
4
4
  describe Flapjack::Gateways::Email, :logger => true do
5
5
 
6
- it "can have a custom from email address" do
7
- email = double('email')
8
- redis = double('redis')
6
+ let(:client) { double('client') }
7
+ let(:redis) { double('redis') }
9
8
 
9
+ it "can have a custom from email address" do
10
10
  expect(EM::P::SmtpClient).to receive(:send).with(
11
11
  hash_including(host: 'localhost',
12
12
  port: 25,
13
13
  from: "from@example.org")
14
- ).and_return(email)
14
+ ).and_return(client)
15
15
 
16
16
  response = double(response)
17
17
  expect(response).to receive(:"respond_to?").with(:code).and_return(true)
18
18
  expect(response).to receive(:code).and_return(250)
19
19
 
20
- expect(EM::Synchrony).to receive(:sync).with(email).and_return(response)
20
+ expect(EM::Synchrony).to receive(:sync).with(client).and_return(response)
21
21
 
22
22
  notification = {'notification_type' => 'recovery',
23
23
  'contact_first_name' => 'John',
@@ -31,28 +31,29 @@ describe Flapjack::Gateways::Email, :logger => true do
31
31
  'event_id' => 'example.com:ping'}
32
32
 
33
33
  config = {"smtp_config" => {'from' => 'from@example.org'}}
34
- Flapjack::Gateways::Email.instance_variable_set('@config', config)
35
- Flapjack::Gateways::Email.instance_variable_set('@redis', redis)
36
- Flapjack::Gateways::Email.instance_variable_set('@logger', @logger)
37
- Flapjack::Gateways::Email.start
38
- Flapjack::Gateways::Email.perform(notification)
34
+
35
+ EM.synchrony do
36
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
37
+
38
+ alert = Flapjack::Data::Alert.new(notification, :logger => @logger)
39
+ email = Flapjack::Gateways::Email.new(:config => config, :logger => @logger)
40
+ email.deliver(alert)
41
+ EM.stop
42
+ end
39
43
  end
40
44
 
41
45
  it "can have a full name in custom from email address" do
42
- email = double('email')
43
- redis = double('redis')
44
-
45
46
  expect(EM::P::SmtpClient).to receive(:send).with(
46
47
  hash_including(host: 'localhost',
47
48
  port: 25,
48
49
  from: "from@example.org")
49
- ).and_return(email)
50
+ ).and_return(client)
50
51
 
51
52
  response = double(response)
52
53
  expect(response).to receive(:"respond_to?").with(:code).and_return(true)
53
54
  expect(response).to receive(:code).and_return(250)
54
55
 
55
- expect(EM::Synchrony).to receive(:sync).with(email).and_return(response)
56
+ expect(EM::Synchrony).to receive(:sync).with(client).and_return(response)
56
57
 
57
58
  notification = {'notification_type' => 'recovery',
58
59
  'contact_first_name' => 'John',
@@ -66,17 +67,18 @@ describe Flapjack::Gateways::Email, :logger => true do
66
67
  'event_id' => 'example.com:ping'}
67
68
 
68
69
  config = {"smtp_config" => {'from' => 'Full Name <from@example.org>'}}
69
- Flapjack::Gateways::Email.instance_variable_set('@config', config)
70
- Flapjack::Gateways::Email.instance_variable_set('@redis', redis)
71
- Flapjack::Gateways::Email.instance_variable_set('@logger', @logger)
72
- Flapjack::Gateways::Email.start
73
- Flapjack::Gateways::Email.perform(notification)
70
+
71
+ EM.synchrony do
72
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
73
+
74
+ alert = Flapjack::Data::Alert.new(notification, :logger => @logger)
75
+ email = Flapjack::Gateways::Email.new(:config => config, :logger => @logger)
76
+ email.deliver(alert)
77
+ EM.stop
78
+ end
74
79
  end
75
80
 
76
81
  it "can have a custom reply-to address" do
77
- email = double('email')
78
- redis = double('redis')
79
-
80
82
  expect(EM::P::SmtpClient).to receive(:send) { |message|
81
83
  # NOTE No access to headers directly. Must be determined from message content
82
84
  expect( message[:content] ).to include("Reply-To: reply-to@example.com")
@@ -84,13 +86,13 @@ describe Flapjack::Gateways::Email, :logger => true do
84
86
  expect( message[:host] ).to eql('localhost')
85
87
  expect( message[:port] ).to eql(25)
86
88
  expect( message[:from] ).to eql('from@example.org')
87
- }.and_return(email)
89
+ }.and_return(client)
88
90
 
89
91
  response = double(response)
90
92
  expect(response).to receive(:"respond_to?").with(:code).and_return(true)
91
93
  expect(response).to receive(:code).and_return(250)
92
94
 
93
- expect(EM::Synchrony).to receive(:sync).with(email).and_return(response)
95
+ expect(EM::Synchrony).to receive(:sync).with(client).and_return(response)
94
96
 
95
97
  notification = {'notification_type' => 'recovery',
96
98
  'contact_first_name' => 'John',
@@ -105,27 +107,27 @@ describe Flapjack::Gateways::Email, :logger => true do
105
107
 
106
108
  config = {"smtp_config" => {'from' => 'from@example.org', 'reply_to' => 'reply-to@example.com'}}
107
109
 
108
- Flapjack::Gateways::Email.instance_variable_set('@config', config)
109
- Flapjack::Gateways::Email.instance_variable_set('@redis', redis)
110
- Flapjack::Gateways::Email.instance_variable_set('@logger', @logger)
111
- Flapjack::Gateways::Email.start
112
- Flapjack::Gateways::Email.perform(notification)
110
+ EM.synchrony do
111
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
112
+
113
+ alert = Flapjack::Data::Alert.new(notification, :logger => @logger)
114
+ email = Flapjack::Gateways::Email.new(:config => config, :logger => @logger)
115
+ email.deliver(alert)
116
+ EM.stop
117
+ end
113
118
  end
114
119
 
115
120
  it "must default to from address if no reply-to given" do
116
- email = double('email')
117
- redis = double('redis')
118
-
119
121
  expect(EM::P::SmtpClient).to receive(:send) { |message|
120
122
  # NOTE No access to headers directly. Must be determined from message content
121
123
  expect( message[:content] ).to include("Reply-To: from@example.org")
122
- }.and_return(email)
124
+ }.and_return(client)
123
125
 
124
126
  response = double(response)
125
127
  expect(response).to receive(:"respond_to?").with(:code).and_return(true)
126
128
  expect(response).to receive(:code).and_return(250)
127
129
 
128
- expect(EM::Synchrony).to receive(:sync).with(email).and_return(response)
130
+ expect(EM::Synchrony).to receive(:sync).with(client).and_return(response)
129
131
 
130
132
  notification = {'notification_type' => 'recovery',
131
133
  'contact_first_name' => 'John',
@@ -140,31 +142,31 @@ describe Flapjack::Gateways::Email, :logger => true do
140
142
 
141
143
  config = {"smtp_config" => {'from' => 'from@example.org'}}
142
144
 
143
- Flapjack::Gateways::Email.instance_variable_set('@config', config)
144
- Flapjack::Gateways::Email.instance_variable_set('@redis', redis)
145
- Flapjack::Gateways::Email.instance_variable_set('@logger', @logger)
146
- Flapjack::Gateways::Email.start
147
- Flapjack::Gateways::Email.perform(notification)
145
+ EM.synchrony do
146
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
147
+
148
+ alert = Flapjack::Data::Alert.new(notification, :logger => @logger)
149
+ email = Flapjack::Gateways::Email.new(:config => config, :logger => @logger)
150
+ email.deliver(alert)
151
+ EM.stop
152
+ end
148
153
  end
149
154
 
150
155
  it "sends a mail with text, html parts and default from address" do
151
- email = double('email')
152
-
153
156
  entity_check = double(Flapjack::Data::EntityCheck)
154
- redis = double('redis')
155
157
 
156
158
  # TODO better checking of what gets passed here
157
159
  expect(EM::P::SmtpClient).to receive(:send).with(
158
160
  hash_including(:host => 'localhost',
159
161
  :port => 25,
160
162
  :from => "flapjack@example.com"
161
- )).and_return(email)
163
+ )).and_return(client)
162
164
 
163
165
  response = double(response)
164
166
  expect(response).to receive(:"respond_to?").with(:code).and_return(true)
165
167
  expect(response).to receive(:code).and_return(250)
166
168
 
167
- expect(EM::Synchrony).to receive(:sync).with(email).and_return(response)
169
+ expect(EM::Synchrony).to receive(:sync).with(client).and_return(response)
168
170
 
169
171
  notification = {'notification_type' => 'recovery',
170
172
  'contact_first_name' => 'John',
@@ -177,12 +179,15 @@ describe Flapjack::Gateways::Email, :logger => true do
177
179
  'time' => Time.now.to_i,
178
180
  'event_id' => 'example.com:ping'}
179
181
 
180
- Flapjack::Gateways::Email.instance_variable_set('@config', {})
181
- Flapjack::Gateways::Email.instance_variable_set('@redis', redis)
182
- Flapjack::Gateways::Email.instance_variable_set('@logger', @logger)
183
- Flapjack::Gateways::Email.start
184
- Flapjack::Gateways::Email.instance_variable_set('@fqdn', "example.com")
185
- Flapjack::Gateways::Email.perform(notification)
182
+ EM.synchrony do
183
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
184
+
185
+ alert = Flapjack::Data::Alert.new(notification, :logger => @logger)
186
+ email = Flapjack::Gateways::Email.new(:config => {}, :logger => @logger)
187
+ email.instance_variable_set('@fqdn', "example.com")
188
+ email.deliver(alert)
189
+ EM.stop
190
+ end
186
191
  end
187
192
 
188
193
  end
@@ -5,6 +5,8 @@ describe Flapjack::Gateways::SmsMessagenet, :logger => true do
5
5
 
6
6
  let(:lock) { double(Monitor) }
7
7
 
8
+ let(:redis) { double('redis') }
9
+
8
10
  let(:config) { {'username' => 'user',
9
11
  'password' => 'password'
10
12
  }
@@ -39,10 +41,11 @@ describe Flapjack::Gateways::SmsMessagenet, :logger => true do
39
41
  to_return(:status => 200)
40
42
 
41
43
  EM.synchrony do
42
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@config', config)
43
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@logger', @logger)
44
- Flapjack::Gateways::SmsMessagenet.start
45
- Flapjack::Gateways::SmsMessagenet.perform(message)
44
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
45
+
46
+ alert = Flapjack::Data::Alert.new(message, :logger => @logger)
47
+ sms_messagenet = Flapjack::Gateways::SmsMessagenet.new(:config => config, :logger => @logger)
48
+ sms_messagenet.deliver(alert)
46
49
  EM.stop
47
50
  end
48
51
  expect(req).to have_been_requested
@@ -64,10 +67,11 @@ describe Flapjack::Gateways::SmsMessagenet, :logger => true do
64
67
  to_return(:status => 200)
65
68
 
66
69
  EM.synchrony do
67
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@config', config)
68
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@logger', @logger)
69
- Flapjack::Gateways::SmsMessagenet.start
70
- Flapjack::Gateways::SmsMessagenet.perform(long_msg)
70
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
71
+
72
+ alert = Flapjack::Data::Alert.new(long_msg, :logger => @logger)
73
+ sms_messagenet = Flapjack::Gateways::SmsMessagenet.new(:config => config, :logger => @logger)
74
+ sms_messagenet.deliver(alert)
71
75
  EM.stop
72
76
  end
73
77
  expect(req).to have_been_requested
@@ -75,10 +79,11 @@ describe Flapjack::Gateways::SmsMessagenet, :logger => true do
75
79
 
76
80
  it "does not send an SMS message with an invalid config" do
77
81
  EM.synchrony do
78
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@config', config.reject {|k, v| k == 'password'})
79
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@logger', @logger)
80
- Flapjack::Gateways::SmsMessagenet.start
81
- Flapjack::Gateways::SmsMessagenet.perform(message)
82
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
83
+
84
+ alert = Flapjack::Data::Alert.new(message, :logger => @logger)
85
+ sms_messagenet = Flapjack::Gateways::SmsMessagenet.new(:config => config.reject {|k, v| k == 'password'}, :logger => @logger)
86
+ sms_messagenet.deliver(alert)
82
87
  EM.stop
83
88
  end
84
89
 
@@ -5,6 +5,8 @@ describe Flapjack::Gateways::SmsTwilio, :logger => true do
5
5
 
6
6
  let(:lock) { double(Monitor) }
7
7
 
8
+ let(:redis) { double('redis') }
9
+
8
10
  let(:config) { {'account_sid' => 'the_account_sid',
9
11
  'auth_token' => 'the_auth_token',
10
12
  'from' => 'the_from_address'
@@ -36,10 +38,11 @@ describe Flapjack::Gateways::SmsTwilio, :logger => true do
36
38
  to_return(:status => 201)
37
39
 
38
40
  EM.synchrony do
39
- Flapjack::Gateways::SmsTwilio.instance_variable_set('@config', config)
40
- Flapjack::Gateways::SmsTwilio.instance_variable_set('@logger', @logger)
41
- Flapjack::Gateways::SmsTwilio.start
42
- Flapjack::Gateways::SmsTwilio.perform(message)
41
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
42
+
43
+ alert = Flapjack::Data::Alert.new(message, :logger => @logger)
44
+ sms_twilio = Flapjack::Gateways::SmsTwilio.new(:config => config, :logger => @logger)
45
+ sms_twilio.deliver(alert)
43
46
  EM.stop
44
47
  end
45
48
  expect(req).to have_been_requested
@@ -63,10 +66,11 @@ describe Flapjack::Gateways::SmsTwilio, :logger => true do
63
66
  to_return(:status => 200)
64
67
 
65
68
  EM.synchrony do
66
- Flapjack::Gateways::SmsTwilio.instance_variable_set('@config', config)
67
- Flapjack::Gateways::SmsTwilio.instance_variable_set('@logger', @logger)
68
- Flapjack::Gateways::SmsTwilio.start
69
- Flapjack::Gateways::SmsTwilio.perform(long_msg)
69
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
70
+
71
+ alert = Flapjack::Data::Alert.new(long_msg, :logger => @logger)
72
+ sms_twilio = Flapjack::Gateways::SmsTwilio.new(:config => config, :logger => @logger)
73
+ sms_twilio.deliver(alert)
70
74
  EM.stop
71
75
  end
72
76
  expect(req).to have_been_requested
@@ -74,10 +78,11 @@ describe Flapjack::Gateways::SmsTwilio, :logger => true do
74
78
 
75
79
  it "does not send an SMS message with an invalid config" do
76
80
  EM.synchrony do
77
- Flapjack::Gateways::SmsTwilio.instance_variable_set('@config', config.reject {|k, v| k == 'auth_token'})
78
- Flapjack::Gateways::SmsTwilio.instance_variable_set('@logger', @logger)
79
- Flapjack::Gateways::SmsTwilio.start
80
- Flapjack::Gateways::SmsTwilio.perform(message)
81
+ expect(Flapjack::RedisPool).to receive(:new).and_return(redis)
82
+
83
+ alert = Flapjack::Data::Alert.new(message, :logger => @logger)
84
+ sms_twilio = Flapjack::Gateways::SmsTwilio.new(:config => config.reject {|k, v| k == 'auth_token'}, :logger => @logger)
85
+ sms_twilio.deliver(alert)
81
86
  EM.stop
82
87
  end
83
88