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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c3317311175764e3c3788fd62a5c77dcc2ceac9
4
- data.tar.gz: 9fed5e93b52806e9876aa39579a309cf72a454dd
3
+ metadata.gz: 08eb6e473cdb410cd9628953cee45bd15105e730
4
+ data.tar.gz: e70c64ec5ee5fbaebcd0a57ea28279637baa9ae8
5
5
  SHA512:
6
- metadata.gz: 89c8564d062e6117d0625cc29fa19724f984357ad8b42c18ef4170cba70e6a6a5a402687a77ab462e4b311591618012141b924d703acc265c2b162417e50e615
7
- data.tar.gz: f2722e5e0d9e22d7126e56713f912274e1808217d4a787c8c10d2c08ab44a67995ad273b64d067b21f5f057088d89f386a216f1fb27426cb4504469378cee872
6
+ metadata.gz: ba9fe3aab9ae6f58038f663737a478991bfc378a263f1e83919ff608f6bcc5b44883a71f36f9568ec38a53f8273df044802034d2ca6540be70d5930aabb3ba07
7
+ data.tar.gz: e95391893e56e8b8fe95c46db61777b861e6b470889d61e578ffd3a856a6da39c95626c6f58519145768346795f57c859d17bbc6bb234cdc91a5766b6a80470c
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.3
1
+ 2.2.0
data/.travis.yml CHANGED
@@ -1,16 +1,8 @@
1
1
  language: ruby
2
- matrix:
3
- include:
4
- - rvm: 1.9.3
5
- gemfile: Gemfile-ruby1.9
6
- script: "bundle exec rspec spec && bundle exec rake pact:verify && bundle exec cucumber features"
7
- env: BUNDLE_GEMFILE=Gemfile-ruby1.9
8
- - rvm: '2.0'
9
- gemfile: Gemfile
10
- script: "bundle exec rspec spec && bundle exec rake pact:verify && bundle exec cucumber features"
11
- - rvm: '2.1'
12
- gemfile: Gemfile
13
- script: "bundle exec rspec spec && bundle exec rake pact:verify && bundle exec cucumber features"
2
+ rvm:
3
+ - '2.0'
4
+ - '2.1'
5
+ - '2.2'
14
6
  services:
15
7
  - redis-server
16
8
  before_script:
@@ -18,6 +10,13 @@ before_script:
18
10
  before_install:
19
11
  - git submodule update --init --recursive
20
12
  - gem install bundler
13
+ install:
14
+ - go get github.com/garyburd/redigo/redis
15
+ - go get github.com/go-martini/martini
16
+ - go get gopkg.in/alecthomas/kingpin.v1
17
+ - go get github.com/oguzbilgic/pandik
18
+ - bundle install
19
+ script: "bundle exec rspec spec && bundle exec rake pact:verify && bundle exec cucumber features && cd src/flapjack && go test -v"
21
20
  notifications:
22
21
  irc:
23
22
  channels:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## Flapjack Changelog
2
2
 
3
+ # 1.2.2 - 2015-02-10
4
+ - Feature: Add the maint subcommand to the chat bot to fix #664 (@someword)
5
+ - Feature: support for Ruby 2.2, drop support for 1.9, removes Resque due to gem dependencies #760 (@ali-graham)
6
+ - Feature: Gammu SMS gateway #759 (@paologlim)
7
+ - Feature: Use microsecond resolution for logs (maint/1.x) #762 (@jgoldschrafe)
8
+ - Feature: Backport notification delays from master #748 (@jgoldschrafe)
9
+ - Feature: make event summary optional, fixes #513 #779 (@ali-graham)
10
+ - Bug: fix purge script #758 (@pulecp)
11
+ - Bug: Fix for orphaned entity data #784 (@ali-graham)
12
+
3
13
  # 1.2.1 - 2014-12-10
4
14
  - Bug: Fix PagerDuty log failure on POST (maint/1.x) #744 (@jgoldschrafe)
5
15
 
data/Gemfile CHANGED
@@ -13,7 +13,6 @@ group :test do
13
13
  gem 'rack-test'
14
14
  gem 'pact'
15
15
  gem 'async_rack_test', '>= 0.0.5'
16
- gem 'resque_spec'
17
16
  gem 'webmock'
18
17
  gem 'guard'
19
18
  gem 'rb-fsevent'
@@ -21,10 +20,4 @@ group :test do
21
20
  gem 'guard-cucumber'
22
21
  gem 'fuubar'
23
22
  gem 'simplecov', :require => false
24
-
25
- # # Not compiling under 1.9.3-p550 anyway
26
- # if RUBY_VERSION.split('.')[0] == '1' && RUBY_VERSION.split('.')[1] == '9'
27
- # gem 'debugger-ruby_core_source', '>= 1.3.4' # required for perftools.rb
28
- # gem 'perftools.rb'
29
- # end
30
23
  end
data/Rakefile CHANGED
@@ -7,7 +7,6 @@ end
7
7
  require 'fileutils'
8
8
  require 'rake'
9
9
 
10
- require 'resque/tasks'
11
10
  require 'pact/tasks'
12
11
 
13
12
  Dir['tasks/**/*.rake'].each { |t| load t }
data/bin/flapjack CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'gli'
4
4
 
5
+ $stdout.sync = true
6
+
5
7
  include GLI::App
6
8
  subcommand_option_handling :normal
7
9
  sort_help :manually
@@ -40,6 +40,7 @@ production:
40
40
  email_queue: email_notifications
41
41
  sms_queue: sms_notifications
42
42
  sms_twilio_queue: sms_twilio_notifications
43
+ sms_gammu_queue: sms_gammu_notifications
43
44
  sns_queue: sns_notifications
44
45
  jabber_queue: jabber_notifications
45
46
  pagerduty_queue: pagerduty_notifications
@@ -116,6 +117,22 @@ production:
116
117
  #templates:
117
118
  # rollup.text: '/etc/flapjack/templates/sms_twilio/rollup.text.erb'
118
119
  # alert.text: '/etc/flapjack/templates/sms_twilio/alert.text.erb'
120
+ # Sends SMS notifications via Gammu
121
+ sms_gammu:
122
+ enabled: yes
123
+ queue: sms_gammu_notifications
124
+ from: "xxxxxxxxx"
125
+ mysql_host: "x.x.x.x"
126
+ mysql_database: "gammu"
127
+ mysql_username: "gammu"
128
+ mysql_password: "xxxxxxxx"
129
+ logger:
130
+ level: INFO
131
+ syslog_errors: yes
132
+ # location of custom alert templates
133
+ templates:
134
+ rollup.text: '/etc/flapjack/templates/sms_gammu/rollup.text.erb'
135
+ alert.text: '/etc/flapjack/templates/sms_gammu/alert.text.erb'
119
136
  # Generates SNS notifications
120
137
  sns:
121
138
  enabled: no
@@ -169,6 +186,9 @@ production:
169
186
  # Seconds between auto_refresh of entities/checks pages. Set to 0 to disable
170
187
  auto_refresh: 120
171
188
  access_log: "/var/log/flapjack/web_access.log"
189
+ # Main URL for this service eg: "http://flapjack.example/"
190
+ #base_url: "/"
191
+ # URL for accessing the JSONAPI service from the browser
172
192
  api_url: "http://localhost:3081/"
173
193
  # Full path to location of logo file, e.g. /etc/flapjack/custom_logo.png
174
194
  #logo_image_path: "/etc/flapjack/web/custom_logo/flapjack-2013-notext-transparent-300-300.png"
@@ -1,4 +1,4 @@
1
- @rollup @notification_rules @resque @processor @notifier @events
1
+ @rollup @notification_rules @processor @notifier @events
2
2
  Feature: Multiple acknowledgements after scheduled maintenance
3
3
 
4
4
  Background:
data/features/cli.feature CHANGED
@@ -27,7 +27,7 @@ test:
27
27
  processor:
28
28
  enabled: yes
29
29
  logger:
30
- level: warn
30
+ level: debug
31
31
  """
32
32
 
33
33
  Scenario: Running with --help shows usage information
@@ -1,4 +1,4 @@
1
- @notification_rules @resque @processor @notifier
1
+ @notification_rules @processor @notifier
2
2
  Feature: Notification rules on a per contact basis
3
3
 
4
4
  Background:
@@ -5,28 +5,24 @@ Feature: notifications
5
5
 
6
6
  # TODO test across multiple contacts
7
7
 
8
- @resque
9
8
  Scenario: Queue an SMS notification
10
9
  Given the user wants to receive SMS notifications for entity 'example.com'
11
10
  When an event notification is generated for entity 'example.com'
12
11
  Then an SMS notification for entity 'example.com' should be queued for the user
13
12
  And an email notification for entity 'example.com' should not be queued for the user
14
13
 
15
- @resque
16
14
  Scenario: Queue an SNS notification
17
15
  Given the user wants to receive SNS notifications for entity 'example.com'
18
16
  When an event notification is generated for entity 'example.com'
19
17
  Then an SNS notification for entity 'example.com' should be queued for the user
20
18
  And an email notification for entity 'example.com' should not be queued for the user
21
19
 
22
- @resque
23
20
  Scenario: Queue an email notification
24
21
  Given the user wants to receive email notifications for entity 'example.com'
25
22
  When an event notification is generated for entity 'example.com'
26
23
  Then an email notification for entity 'example.com' should be queued for the user
27
24
  And an SMS notification for entity 'example.com' should not be queued for the user
28
25
 
29
- @resque
30
26
  Scenario: Queue SMS and email notifications
31
27
  Given the user wants to receive SMS notifications for entity 'example.com' and email notifications for entity 'example2.com'
32
28
  When an event notification is generated for entity 'example.com'
@@ -36,11 +32,6 @@ Feature: notifications
36
32
  Then an email notification for entity 'example.com' should not be queued for the user
37
33
  And an email notification for entity 'example2.com' should be queued for the user
38
34
 
39
- # NB: Scenarios below here are those that cover code run by the Resque workers
40
- # We could maybe test resque integration as well, see
41
- # http://corner.squareup.com/2010/08/cucumber-and-resque.html
42
- # http://gist.github.com/532100
43
-
44
35
  Scenario: Send a queued SMS notification
45
36
  Given a user SMS notification has been queued for entity 'example.com'
46
37
  When the SMS notification handler runs successfully
@@ -1,4 +1,4 @@
1
- @rollup @notification_rules @resque @processor @notifier @events
1
+ @rollup @notification_rules @processor @notifier @events
2
2
  Feature: Rollup on a per contact, per media basis
3
3
 
4
4
  Background:
@@ -2,7 +2,8 @@
2
2
 
3
3
  def drain_events
4
4
  loop do
5
- event = Flapjack::Data::Event.next('events', :block => false, :redis => @redis)
5
+ event = Flapjack::Data::Event.next('events', :block => false,
6
+ :redis => @redis)
6
7
  break unless event
7
8
  @processor.send(:process_event, event)
8
9
  end
@@ -12,12 +13,23 @@ end
12
13
  def drain_notifications
13
14
  return unless @notifier_redis
14
15
  loop do
15
- notification = Flapjack::Data::Notification.next('notifications', :block => false, :redis => @notifier_redis)
16
+ notification = Flapjack::Data::Notification.next('notifications',
17
+ :block => false, :redis => @notifier_redis)
16
18
  break unless notification
17
19
  @notifier.send(:process_notification, notification)
18
20
  end
19
21
  end
20
22
 
23
+ def drain_alerts(queue, gateway)
24
+ return unless @notifier_redis
25
+ loop do
26
+ alert = Flapjack::Data::Alert.next(queue, :block => false,
27
+ :redis => @notifier_redis, :logger => @logger)
28
+ break unless alert
29
+ gateway.send(:deliver, alert)
30
+ end
31
+ end
32
+
21
33
  def submit_event(event)
22
34
  @redis.rpush('events', Flapjack.dump_json(event))
23
35
  end
@@ -405,18 +417,18 @@ Then /^(\w+) (\w+) alert(?:s)?(?: of)?(?: type (\w+))?(?: and)?(?: rollup (\w+))
405
417
  when 'no'
406
418
  num_queued = 0
407
419
  end
408
- queue = Resque.peek("#{media}_notifications", 0, 30)
409
- queued_length = queue.find_all {|n|
410
- type_ok = notification_type ? ( n['args'].first['notification_type'] == notification_type ) : true
420
+ queued = redis_peek("#{media}_notifications", 0, 30)
421
+ queued_length = queued.find_all {|n|
422
+ type_ok = notification_type ? ( n['notification_type'] == notification_type ) : true
411
423
  rollup_ok = case rollup
412
424
  when 'none'
413
- n['args'].first['rollup'].nil?
414
- when nil, n['args'].first['rollup']
425
+ n['rollup'].nil?
426
+ when nil, n['rollup']
415
427
  true
416
428
  else
417
429
  false
418
430
  end
419
- type_ok && rollup_ok && ( n['args'].first['address'] == address )
431
+ type_ok && rollup_ok && ( n['address'] == address )
420
432
  }.length
421
433
  expect(queued_length).to eq(num_queued.to_i)
422
434
  end
@@ -2,7 +2,7 @@
2
2
  # copied from flapjack-populator
3
3
  # TODO use Flapjack::Data::Contact.add
4
4
  def add_contact(contact = {})
5
- @redis.multi do |multi|
5
+ @notifier_redis.multi do |multi|
6
6
  multi.del("contact:#{contact['id']}")
7
7
  multi.del("contact_media:#{contact['id']}")
8
8
  multi.hset("contact:#{contact['id']}", 'first_name', contact['first_name'])
@@ -23,7 +23,7 @@ Given /^the user wants to receive SMS notifications for entity '([\w\.\-]+)'$/ d
23
23
  Flapjack::Data::Entity.add({'id' => '5000',
24
24
  'name' => entity,
25
25
  'contacts' => ["0999"]},
26
- :redis => @redis )
26
+ :redis => @notifier_redis )
27
27
  end
28
28
 
29
29
  Given /^the user wants to receive SNS notifications for entity '([\w\.\-]+)'$/ do |entity|
@@ -35,7 +35,7 @@ Given /^the user wants to receive SNS notifications for entity '([\w\.\-]+)'$/ d
35
35
  Flapjack::Data::Entity.add({'id' => '5000',
36
36
  'name' => entity,
37
37
  'contacts' => ["0999"]},
38
- :redis => @redis )
38
+ :redis => @notifier_redis )
39
39
  end
40
40
 
41
41
  Given /^the user wants to receive email notifications for entity '([\w\.\-]+)'$/ do |entity|
@@ -47,7 +47,7 @@ Given /^the user wants to receive email notifications for entity '([\w\.\-]+)'$/
47
47
  Flapjack::Data::Entity.add({'id' => '5000',
48
48
  'name' => entity,
49
49
  'contacts' => ["0999"]},
50
- :redis => @redis )
50
+ :redis => @notifier_redis )
51
51
  end
52
52
 
53
53
  Given /^the user wants to receive SMS notifications for entity '([\w\.\-]+)' and email notifications for entity '([\w\.\-]+)'$/ do |entity1, entity2|
@@ -64,11 +64,11 @@ Given /^the user wants to receive SMS notifications for entity '([\w\.\-]+)' and
64
64
  Flapjack::Data::Entity.add({'id' => '5000',
65
65
  'name' => entity1,
66
66
  'contacts' => ["0998"]},
67
- :redis => @redis )
67
+ :redis => @notifier_redis )
68
68
  Flapjack::Data::Entity.add({'id' => '5001',
69
69
  'name' => entity2,
70
70
  'contacts' => ["0999"]},
71
- :redis => @redis )
71
+ :redis => @notifier_redis )
72
72
  end
73
73
 
74
74
  # TODO create the notification object in redis, flag the relevant operation as
@@ -90,33 +90,33 @@ When /^an event notification is generated for entity '([\w\.\-]+)'$/ do |entity|
90
90
 
91
91
  Flapjack::Data::Notification.add('notifications', event,
92
92
  :type => notification_type, :severity => severity, :last_state => last_state,
93
- :redis => @redis)
93
+ :redis => @notifier_redis)
94
94
  drain_notifications
95
95
  end
96
96
 
97
97
  Then /^an SMS notification for entity '([\w\.\-]+)' should be queued for the user$/ do |entity|
98
- queue = ResqueSpec.peek('sms_notifications')
99
- expect(queue.select {|n| n[:args].first['event_id'] =~ /#{entity}:ping/ }).not_to be_empty
98
+ queue = redis_peek('sms_notifications')
99
+ expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).not_to be_empty
100
100
  end
101
101
 
102
102
  Then /^an SNS notification for entity '([\w\.\-]+)' should be queued for the user$/ do |entity|
103
- queue = ResqueSpec.peek('sns_notifications')
104
- expect(queue.select {|n| n[:args].first['event_id'] =~ /#{entity}:ping/ }).not_to be_empty
103
+ queue = redis_peek('sns_notifications')
104
+ expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).not_to be_empty
105
105
  end
106
106
 
107
107
  Then /^an email notification for entity '([\w\.\-]+)' should be queued for the user$/ do |entity|
108
- queue = ResqueSpec.peek('email_notifications')
109
- expect(queue.select {|n| n[:args].first['event_id'] =~ /#{entity}:ping/ }).not_to be_empty
108
+ queue = redis_peek('email_notifications')
109
+ expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).not_to be_empty
110
110
  end
111
111
 
112
112
  Then /^an SMS notification for entity '([\w\.\-]+)' should not be queued for the user$/ do |entity|
113
- queue = ResqueSpec.peek('sms_notifications')
114
- expect(queue.select {|n| n[:args].first['event_id'] =~ /#{entity}:ping/ }).to be_empty
113
+ queue = redis_peek('sms_notifications')
114
+ expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).to be_empty
115
115
  end
116
116
 
117
117
  Then /^an email notification for entity '([\w\.\-]+)' should not be queued for the user$/ do |entity|
118
- queue = ResqueSpec.peek('email_notifications')
119
- expect(queue.select {|n| n[:args].first['event_id'] =~ /#{entity}:ping/ }).to be_empty
118
+ queue = redis_peek('email_notifications')
119
+ expect(queue.select {|n| n['event_id'] =~ /#{entity}:ping/ }).to be_empty
120
120
  end
121
121
 
122
122
  Given /^a user SMS notification has been queued for entity '([\w\.\-]+)'$/ do |entity|
@@ -134,13 +134,16 @@ Given /^a user SMS notification has been queued for entity '([\w\.\-]+)'$/ do |e
134
134
  'id' => 1,
135
135
  'state_duration' => 30,
136
136
  'duration' => 45}
137
+
138
+ Flapjack::Data::Alert.add('sms_notifications', @sms_notification,
139
+ :redis => @notifier_redis)
137
140
  end
138
141
 
139
142
  Given /^a user SNS notification has been queued for entity '([\w\.\-]+)'$/ do |entity|
140
143
  Flapjack::Data::Entity.add({'id' => '5000',
141
144
  'name' => entity},
142
145
  :redis => @redis )
143
- @sms_notification = {'notification_type' => 'problem',
146
+ @sns_notification = {'notification_type' => 'problem',
144
147
  'contact_first_name' => 'John',
145
148
  'contact_last_name' => 'Smith',
146
149
  'state' => 'critical',
@@ -151,6 +154,9 @@ Given /^a user SNS notification has been queued for entity '([\w\.\-]+)'$/ do |e
151
154
  'id' => 1,
152
155
  'state_duration' => 30,
153
156
  'duration' => 45}
157
+
158
+ Flapjack::Data::Alert.add('sns_notifications', @sns_notification,
159
+ :redis => @notifier_redis)
154
160
  end
155
161
 
156
162
  Given /^a user email notification has been queued for entity '([\w\.\-]+)'$/ do |entity|
@@ -168,66 +174,54 @@ Given /^a user email notification has been queued for entity '([\w\.\-]+)'$/ do
168
174
  'id' => 2,
169
175
  'state_duration' => 30,
170
176
  'duration' => 3600}
171
- end
172
177
 
173
- # NB using perform, the notifiers were accessing the wrong Redis DB number
178
+ Flapjack::Data::Alert.add('email_notifications', @email_notification,
179
+ :redis => @notifier_redis)
180
+ end
174
181
 
175
- # TODO may need to get more complex, depending which SMS provider is used
176
182
  When /^the SMS notification handler runs successfully$/ do
177
183
  @request = stub_request(:get, /^#{Regexp.escape(Flapjack::Gateways::SmsMessagenet::MESSAGENET_DEFAULT_URL)}/)
178
184
 
179
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@config', {'username' => 'abcd', 'password' => 'efgh'})
180
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@redis', @redis)
181
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@logger', @logger)
182
- Flapjack::Gateways::SmsMessagenet.start
185
+ @sms_messagenet = Flapjack::Gateways::SmsMessagenet.new(:config => {
186
+ 'username' => 'abcd', 'password' => 'efgh'
187
+ }, :redis_config => @redis_opts, :logger => @logger)
183
188
 
184
- Flapjack::Gateways::SmsMessagenet.perform(@sms_notification)
189
+ drain_alerts('sms_notifications', @sms_messagenet)
185
190
  end
186
191
 
187
192
  When /^the SNS notification handler runs successfully$/ do
188
193
  @request = stub_request(:post, /amazonaws\.com/)
189
194
 
190
- Flapjack::Gateways::AwsSns.instance_variable_set('@config', {
195
+ @aws_sns = Flapjack::Gateways::AwsSns.new(:config => {
191
196
  'access_key' => "AKIAIOSFODNN7EXAMPLE",
192
197
  'secret_key' => "secret"
193
- })
194
- Flapjack::Gateways::AwsSns.instance_variable_set('@redis', @redis)
195
- Flapjack::Gateways::AwsSns.instance_variable_set('@logger', @logger)
196
- Flapjack::Gateways::AwsSns.start
198
+ }, :redis_config => @redis_opts, :logger => @logger)
197
199
 
198
- Flapjack::Gateways::AwsSns.perform(@sms_notification)
200
+ drain_alerts('sns_notifications', @aws_sns)
199
201
  end
200
202
 
201
203
  When /^the SMS notification handler fails to send an SMS$/ do
202
204
  @request = stub_request(:get, /^#{Regexp.escape(Flapjack::Gateways::SmsMessagenet::MESSAGENET_DEFAULT_URL)}/).to_return(:status => [500, "Internal Server Error"])
203
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@config', {'username' => 'abcd', 'password' => 'efgh'})
204
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@redis', @redis)
205
- Flapjack::Gateways::SmsMessagenet.instance_variable_set('@logger', @logger)
206
- Flapjack::Gateways::SmsMessagenet.start
207
205
 
208
- Flapjack::Gateways::SmsMessagenet.perform(@sms_notification)
206
+ @sms_messagenet = Flapjack::Gateways::SmsMessagenet.new(:config => {
207
+ 'username' => 'abcd', 'password' => 'efgh'
208
+ }, :redis_config => @redis_opts, :logger => @logger)
209
+
210
+ drain_alerts('sms_notifications', @sms_messagenet)
209
211
  end
210
212
 
211
213
  When /^the SNS notification handler fails to send an SMS$/ do
212
214
  @request = stub_request(:post, /amazonaws\.com/).to_return(:status => [500, "Internal Server Error"])
213
- Flapjack::Gateways::AwsSns.instance_variable_set('@config', {
215
+
216
+ @aws_sns = Flapjack::Gateways::AwsSns.new(:config => {
214
217
  'access_key' => "AKIAIOSFODNN7EXAMPLE",
215
218
  'secret_key' => "secret"
216
- })
217
- Flapjack::Gateways::AwsSns.instance_variable_set('@redis', @redis)
218
- Flapjack::Gateways::AwsSns.instance_variable_set('@logger', @logger)
219
- Flapjack::Gateways::AwsSns.start
219
+ }, :redis_config => @redis_opts, :logger => @logger)
220
220
 
221
- Flapjack::Gateways::AwsSns.perform(@sms_notification)
221
+ drain_alerts('sns_notifications', @aws_sns)
222
222
  end
223
223
 
224
224
  When /^the email notification handler runs successfully$/ do
225
- Resque.redis = @redis
226
- Flapjack::Gateways::Email.instance_variable_set('@config', {'smtp_config' => {'host' => '127.0.0.1', 'port' => 2525, 'from' => 'flapjack@example'}})
227
- Flapjack::Gateways::Email.instance_variable_set('@redis', @redis)
228
- Flapjack::Gateways::Email.instance_variable_set('@logger', @logger)
229
- Flapjack::Gateways::Email.start
230
-
231
225
  # poor man's stubbing
232
226
  EM::P::SmtpClient.class_eval {
233
227
  def self.send(args = {})
@@ -237,16 +231,16 @@ When /^the email notification handler runs successfully$/ do
237
231
  end
238
232
  }
239
233
 
240
- Flapjack::Gateways::Email.perform(@email_notification)
234
+ @email = Flapjack::Gateways::Email.new(:config => {
235
+ 'smtp_config' => {'host' => '127.0.0.1',
236
+ 'port' => 2525,
237
+ 'from' => 'flapjack@example'}
238
+ }, :redis_config => @redis_opts, :logger => @logger)
239
+
240
+ drain_alerts('email_notifications', @email)
241
241
  end
242
242
 
243
243
  When /^the email notification handler fails to send an email$/ do
244
- Resque.redis = @redis
245
- Flapjack::Gateways::Email.instance_variable_set('@config', {'smtp_config' => {'host' => '127.0.0.1', 'port' => 2525, 'from' => 'flapjack@example'}})
246
- Flapjack::Gateways::Email.instance_variable_set('@redis', @redis)
247
- Flapjack::Gateways::Email.instance_variable_set('@logger', @logger)
248
- Flapjack::Gateways::Email.start
249
-
250
244
  # poor man's stubbing
251
245
  EM::P::SmtpClient.class_eval {
252
246
  def self.send(args = {})
@@ -256,33 +250,26 @@ When /^the email notification handler fails to send an email$/ do
256
250
  end
257
251
  }
258
252
 
259
- Flapjack::Gateways::Email.perform(@email_notification)
260
- end
253
+ @email = Flapjack::Gateways::Email.new(:config => {
254
+ 'smtp_config' => {'host' => '127.0.0.1',
255
+ 'port' => 2525,
256
+ 'from' => 'flapjack@example'}
257
+ }, :redis_config => @redis_opts, :logger => @logger)
261
258
 
262
- Then /^the user should receive an SMS notification$/ do
263
- expect(@request).to have_been_requested
264
- expect(Flapjack::Gateways::SmsMessagenet.instance_variable_get('@sent')).to eq(1)
259
+ drain_alerts('email_notifications', @email)
265
260
  end
266
261
 
267
- Then /^the user should receive an SNS notification$/ do
262
+ Then /^the user should( not)? receive an SMS notification$/ do |negativity|
268
263
  expect(@request).to have_been_requested
269
- expect(Flapjack::Gateways::AwsSns.instance_variable_get('@sent')).to eq(1)
270
- end
271
-
272
- Then /^the user should receive an email notification$/ do
273
- expect(Flapjack::Gateways::Email.instance_variable_get('@sent')).to eq(1)
264
+ expect(@sms_messagenet.instance_variable_get('@sent')).to eq(negativity.nil? ? 1 : 0)
274
265
  end
275
266
 
276
- Then /^the user should not receive an SMS notification$/ do
267
+ Then /^the user should( not)? receive an SNS notification$/ do |negativity|
277
268
  expect(@request).to have_been_requested
278
- expect(Flapjack::Gateways::SmsMessagenet.instance_variable_get('@sent')).to eq(0)
269
+ expect(@aws_sns.instance_variable_get('@sent')).to eq(negativity.nil? ? 1 : 0)
279
270
  end
280
271
 
281
- Then /^the user should not receive an SNS notification$/ do
282
- expect(@request).to have_been_requested
283
- expect(Flapjack::Gateways::AwsSns.instance_variable_get('@sent')).to eq(0)
272
+ Then /^the user should( not)? receive an email notification$/ do |negativity|
273
+ expect(@email.instance_variable_get('@sent')).to eq(negativity.nil? ? 1 : 0)
284
274
  end
285
275
 
286
- Then /^the user should not receive an email notification$/ do
287
- expect(Flapjack::Gateways::Email.instance_variable_get('@sent')).to eq(0)
288
- end