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
@@ -12,10 +12,6 @@ describe Flapjack::Pikelet do
12
12
 
13
13
  let(:time) { Time.now }
14
14
 
15
- before do
16
- Flapjack::Pikelet::Resque.class_variable_set(:@@resque_pool, nil)
17
- end
18
-
19
15
  it "creates and starts a processor pikelet" do
20
16
  expect(Flapjack::Logger).to receive(:new).and_return(logger)
21
17
 
@@ -38,35 +34,25 @@ describe Flapjack::Pikelet do
38
34
  pik.start
39
35
  end
40
36
 
41
- it "creates and starts a resque worker gateway" do
37
+ it "creates and starts a generic worker gateway" do
42
38
  expect(Flapjack::Logger).to receive(:new).and_return(logger)
43
39
 
44
40
  expect(config).to receive(:[]).with('logger').and_return(nil)
45
- expect(config).to receive(:[]).with('queue').and_return('email_notif')
46
-
47
- resque_redis = double('resque_redis')
48
- redis = double('redis')
49
- expect(Flapjack::RedisPool).to receive(:new).twice.and_return(resque_redis, redis)
50
- expect(Resque).to receive(:redis=).with(resque_redis)
51
41
 
52
- expect(Flapjack::Gateways::Email).to receive(:instance_variable_set).
53
- with('@config', config)
54
- expect(Flapjack::Gateways::Email).to receive(:instance_variable_set).
55
- with('@redis', redis)
56
- expect(Flapjack::Gateways::Email).to receive(:instance_variable_set).
57
- with('@logger', logger)
42
+ fc = double('coordinator')
58
43
 
59
- worker = double('worker')
60
- expect(worker).to receive(:work).with(0.1)
61
- expect(Flapjack::Gateways::Email).to receive(:start)
62
- expect(EM::Resque::Worker).to receive(:new).with('email_notif').and_return(worker)
44
+ email = double('email')
45
+ expect(email).to receive(:start)
46
+ expect(Flapjack::Gateways::Email).to receive(:new).with(:config => config,
47
+ :redis_config => redis_config, :boot_time => time, :logger => logger, :coordinator => fc).
48
+ and_return(email)
63
49
 
64
50
  expect(fiber).to receive(:resume)
65
51
  expect(Fiber).to receive(:new).and_yield.and_return(fiber)
66
52
 
67
53
  pik = Flapjack::Pikelet.create('email', :config => config,
68
- :redis_config => redis_config)
69
- expect(pik).to be_a(Flapjack::Pikelet::Resque)
54
+ :redis_config => redis_config, :boot_time => time, :coordinator => fc)
55
+ expect(pik).to be_a(Flapjack::Pikelet::Generic)
70
56
  pik.start
71
57
  end
72
58
 
@@ -15,6 +15,7 @@ describe Flapjack::RedisPool do
15
15
  expect(Flapjack::Data::Migration).to receive(:correct_notification_rule_contact_linkages).exactly(redis_count).times
16
16
  expect(Flapjack::Data::Migration).to receive(:migrate_entity_check_data_if_required).exactly(redis_count).times
17
17
  expect(Flapjack::Data::Migration).to receive(:create_entity_ids_if_required).exactly(redis_count).times
18
+ expect(Flapjack::Data::Migration).to receive(:clear_orphaned_entity_ids).exactly(redis_count).times
18
19
  expect(Flapjack::Data::Migration).to receive(:refresh_archive_index).exactly(redis_count).times
19
20
  expect(Flapjack::Data::Migration).to receive(:validate_scheduled_maintenance_periods).exactly(redis_count).times
20
21
 
data/tasks/profile.rake CHANGED
@@ -11,7 +11,6 @@ namespace :profile do
11
11
  FLAPJACK_PORT = ((port > 1024) && (port <= 65535)) ? port : 8075
12
12
 
13
13
  REPETITIONS = 10
14
- RESQUE_REPETITIONS = 2
15
14
 
16
15
  require 'ruby-prof'
17
16
 
@@ -46,78 +45,6 @@ namespace :profile do
46
45
  redis.quit
47
46
  end
48
47
 
49
- # rubyprof doesn't like the mail gem, possibly due to treetop -- crashes
50
- # with "stack level too deep" errors when generating if the profiling
51
- # runs over 3 or more mails.
52
- def profile_resque(cfg_name, config, redis_options, &block)
53
- redis = Redis.new(redis_options.merge(:driver => 'ruby'))
54
- check_db_empty(:redis => redis, :redis_options => redis_options)
55
- setup_baseline_data(:redis => redis)
56
-
57
- ::Resque.redis = redis
58
-
59
- EM.synchrony do
60
- FlapjackProfileResque.instance_eval {
61
-
62
- class << self
63
-
64
- alias_method :orig_perform, :perform
65
-
66
- # NB: this is very brittle in the case of exceptions; Resque swallows them,
67
- # so you'll need to turn on the worker's verbose switches below to see what's
68
- # really going on
69
- def perform(notification)
70
- r = nil
71
- begin
72
- count = if FlapjackProfileResque.class_variable_defined?('@@profile_count')
73
- FlapjackProfileResque.class_variable_get('@@profile_count')
74
- else
75
- FlapjackProfileResque.class_variable_set('@@profile_count', 0)
76
- end
77
-
78
- RubyProf.send( (count.zero? ? :start : :resume) )
79
- r = orig_perform(notification)
80
- RubyProf.pause
81
-
82
- count += 1
83
- FlapjackProfileResque.class_variable_set('@@profile_count', count)
84
- rescue Exception => e
85
- puts e.message
86
- end
87
- r
88
- end
89
- end
90
-
91
- }
92
-
93
- FlapjackProfileResque.bootstrap(:config => config)
94
-
95
- worker = EM::Resque::Worker.new(config['queue'])
96
- worker.verbose = true
97
- worker.very_verbose = true
98
-
99
- EM.defer(block)
100
-
101
- worker.work(0.1) {|job|
102
- if FlapjackProfileResque.class_variable_defined?('@@profile_count') &&
103
- (FlapjackProfileResque.class_variable_get('@@profile_count') >= RESQUE_REPETITIONS)
104
- job.worker.shutdown
105
- end
106
- }
107
-
108
- result = RubyProf.stop
109
- printer = RubyProf::MultiPrinter.new(result)
110
- output_dir = File.join('tmp', 'profiles')
111
- FileUtils.mkdir_p(output_dir)
112
- printer.print(:path => output_dir, :profile => cfg_name)
113
-
114
- EM.stop
115
- end
116
-
117
- empty_db(:redis => redis)
118
- redis.quit
119
- end
120
-
121
48
  def profile_thin(klass, name, config, redis_options, &block)
122
49
  redis = Redis.new(redis_options.merge(:driver => 'ruby'))
123
50
  check_db_empty(:redis => redis, :redis_options => redis_options)
@@ -252,13 +179,14 @@ namespace :profile do
252
179
  task :jabber do
253
180
 
254
181
  require 'flapjack/jabber'
182
+ require 'flapjack/data/alert'
255
183
  require 'flapjack/data/contact'
256
184
  require 'flapjack/data/event'
257
185
  require 'flapjack/data/notification'
258
186
 
259
187
  FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'profile'
260
188
  config_env, redis_options = load_config
261
- profile_pikelet(Flapjack::Jabber, 'jabber', config_env['jabber_gateway'],
189
+ profile_pikelet(Flapjack::Gateways::Jabber, 'jabber', config_env['jabber_gateway'],
262
190
  redis_options) {
263
191
 
264
192
  # this executes in a separate thread, so no Fibery stuff is allowed
@@ -277,8 +205,8 @@ namespace :profile do
277
205
  notification.messages(:contacts => [contact]).each do |msg|
278
206
  contents = msg.contents
279
207
  contents['event_count'] = n
280
- redis.rpush(config_env['jabber_gateway']['queue'],
281
- Flapjack.dump_json(contents))
208
+ Flapjack::Data::Alert.add(config_env['jabber_gateway']['queue'],
209
+ contents)
282
210
  end
283
211
  end
284
212
 
@@ -291,51 +219,39 @@ namespace :profile do
291
219
  desc "profile email notifier with rubyprof"
292
220
  task :email do
293
221
 
294
- require 'eventmachine'
295
- # the redis/synchrony gems need to be required in this particular order, see
296
- # the redis-rb README for details
297
- require 'hiredis'
298
- require 'em-synchrony'
299
- require 'redis/connection/synchrony'
300
- require 'redis'
301
- require 'em-resque'
302
- require 'em-resque/worker'
303
-
304
- require 'flapjack/patches'
305
- require 'flapjack/redis_pool'
306
- require 'flapjack/notification/email'
307
-
222
+ require 'flapjack/email'
223
+ require 'flapjack/data/alert'
308
224
  require 'flapjack/data/contact'
309
225
  require 'flapjack/data/event'
310
226
  require 'flapjack/data/notification'
311
227
 
312
228
  FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'profile'
313
229
  config_env, redis_options = load_config
230
+ profile_pikelet(Flapjack::Gateways::Email, 'jabber', config_env['jabber_gateway'],
231
+ redis_options) {
314
232
 
315
- FlapjackProfileResque = Class.new(Flapjack::Notification::Email)
316
-
317
- profile_resque('email', config_env['email_notifier'], redis_options) {
318
-
319
- # this executes in a separate thread, so no Fibery stuff is allowed
320
- redis = Redis.new(redis_options.merge(:driver => 'ruby'))
233
+ # this executes in a separate thread, so no Fibery stuff is allowed
234
+ redis = Redis.new(redis_options.merge(:driver => 'ruby'))
321
235
 
322
- event = Flapjack::Data::Event.new('type' => 'service',
323
- 'state' => 'critical',
324
- 'summary' => '100% packet loss',
325
- 'entity' => 'clientx-app-01',
326
- 'check' => 'ping')
327
- notification = Flapjack::Data::Notification.for_event(event)
236
+ event = Flapjack::Data::Event.new('type' => 'service',
237
+ 'state' => 'critical',
238
+ 'summary' => '100% packet loss',
239
+ 'entity' => 'clientx-app-01',
240
+ 'check' => 'ping')
241
+ notification = Flapjack::Data::Notification.for_event(event)
328
242
 
329
- contact = Flapjack::Data::Contact.find_by_id('1000', :redis => redis)
243
+ contact = Flapjack::Data::Contact.find_by_id('1000', :redis => redis)
330
244
 
331
- RESQUE_REPETITIONS.times do
332
- notification.messages(:contacts => [contact]).each do |msg|
333
- Resque.enqueue_to(config_env['email_notifier']['queue'],
334
- FlapjackProfileResque, msg.contents)
245
+ REPETITIONS.times do |n|
246
+ notification.messages(:contacts => [contact]).each do |msg|
247
+ contents = msg.contents
248
+ contents['event_count'] = n
249
+ Flapjack::Data::Alert.add(config_env['email_gateway']['queue'],
250
+ contents)
251
+ end
335
252
  end
336
- end
337
253
 
338
- redis.quit
254
+ redis.quit
339
255
  }
340
256
  end
341
257
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flapjack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lindsay Holmwood
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-12-10 00:00:00.000000000 Z
14
+ date: 2015-02-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: dante
@@ -84,21 +84,7 @@ dependencies:
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  - !ruby/object:Gem::Dependency
87
- name: em-synchrony
88
- requirement: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - "~>"
91
- - !ruby/object:Gem::Version
92
- version: 1.0.2
93
- type: :runtime
94
- prerelease: false
95
- version_requirements: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - "~>"
98
- - !ruby/object:Gem::Version
99
- version: 1.0.2
100
- - !ruby/object:Gem::Dependency
101
- name: em-http-request
87
+ name: em-hiredis
102
88
  requirement: !ruby/object:Gem::Requirement
103
89
  requirements:
104
90
  - - ">="
@@ -112,33 +98,33 @@ dependencies:
112
98
  - !ruby/object:Gem::Version
113
99
  version: '0'
114
100
  - !ruby/object:Gem::Dependency
115
- name: em-resque
101
+ name: em-synchrony
116
102
  requirement: !ruby/object:Gem::Requirement
117
103
  requirements:
118
- - - ">="
104
+ - - "~>"
119
105
  - !ruby/object:Gem::Version
120
- version: '0'
106
+ version: 1.0.2
121
107
  type: :runtime
122
108
  prerelease: false
123
109
  version_requirements: !ruby/object:Gem::Requirement
124
110
  requirements:
125
- - - ">="
111
+ - - "~>"
126
112
  - !ruby/object:Gem::Version
127
- version: '0'
113
+ version: 1.0.2
128
114
  - !ruby/object:Gem::Dependency
129
- name: resque
115
+ name: em-http-request
130
116
  requirement: !ruby/object:Gem::Requirement
131
117
  requirements:
132
- - - "~>"
118
+ - - ">="
133
119
  - !ruby/object:Gem::Version
134
- version: 1.23.0
120
+ version: '0'
135
121
  type: :runtime
136
122
  prerelease: false
137
123
  version_requirements: !ruby/object:Gem::Requirement
138
124
  requirements:
139
- - - "~>"
125
+ - - ">="
140
126
  - !ruby/object:Gem::Version
141
- version: 1.23.0
127
+ version: '0'
142
128
  - !ruby/object:Gem::Dependency
143
129
  name: sinatra
144
130
  requirement: !ruby/object:Gem::Requirement
@@ -255,16 +241,16 @@ dependencies:
255
241
  name: activesupport
256
242
  requirement: !ruby/object:Gem::Requirement
257
243
  requirements:
258
- - - "~>"
244
+ - - ">="
259
245
  - !ruby/object:Gem::Version
260
- version: 3.2.14
246
+ version: '0'
261
247
  type: :runtime
262
248
  prerelease: false
263
249
  version_requirements: !ruby/object:Gem::Requirement
264
250
  requirements:
265
- - - "~>"
251
+ - - ">="
266
252
  - !ruby/object:Gem::Version
267
- version: 3.2.14
253
+ version: '0'
268
254
  - !ruby/object:Gem::Dependency
269
255
  name: ice_cube
270
256
  requirement: !ruby/object:Gem::Requirement
@@ -283,16 +269,16 @@ dependencies:
283
269
  name: tzinfo
284
270
  requirement: !ruby/object:Gem::Requirement
285
271
  requirements:
286
- - - "~>"
272
+ - - ">="
287
273
  - !ruby/object:Gem::Version
288
- version: 1.0.1
274
+ version: '0'
289
275
  type: :runtime
290
276
  prerelease: false
291
277
  version_requirements: !ruby/object:Gem::Requirement
292
278
  requirements:
293
- - - "~>"
279
+ - - ">="
294
280
  - !ruby/object:Gem::Version
295
- version: 1.0.1
281
+ version: '0'
296
282
  - !ruby/object:Gem::Dependency
297
283
  name: tzinfo-data
298
284
  requirement: !ruby/object:Gem::Requirement
@@ -363,6 +349,20 @@ dependencies:
363
349
  - - '='
364
350
  - !ruby/object:Gem::Version
365
351
  version: 1.6.2.1
352
+ - !ruby/object:Gem::Dependency
353
+ name: mysql2
354
+ requirement: !ruby/object:Gem::Requirement
355
+ requirements:
356
+ - - ">="
357
+ - !ruby/object:Gem::Version
358
+ version: '0'
359
+ type: :runtime
360
+ prerelease: false
361
+ version_requirements: !ruby/object:Gem::Requirement
362
+ requirements:
363
+ - - ">="
364
+ - !ruby/object:Gem::Version
365
+ version: '0'
366
366
  description: Flapjack is a distributed monitoring notification system that provides
367
367
  a scalable method for processing streams of events from Nagios and deciding who
368
368
  should be notified
@@ -381,8 +381,6 @@ files:
381
381
  - CONTRIBUTING.md
382
382
  - Dockerfile
383
383
  - Gemfile
384
- - Gemfile-ruby1.9
385
- - Gemfile-ruby1.9.lock
386
384
  - Guardfile
387
385
  - LICENCE
388
386
  - README.md
@@ -472,6 +470,7 @@ files:
472
470
  - lib/flapjack/gateways/oobetet.rb
473
471
  - lib/flapjack/gateways/pagerduty.rb
474
472
  - lib/flapjack/gateways/pagerduty/alert.text.erb
473
+ - lib/flapjack/gateways/sms_gammu.rb
475
474
  - lib/flapjack/gateways/sms_messagenet.rb
476
475
  - lib/flapjack/gateways/sms_messagenet/alert.text.erb
477
476
  - lib/flapjack/gateways/sms_messagenet/rollup.text.erb
@@ -600,7 +599,6 @@ files:
600
599
  - src/flapjack/event_test.go
601
600
  - src/flapjack/transport.go
602
601
  - src/flapjack/transport_test.go
603
- - tasks/benchmarks.rake
604
602
  - tasks/entities.rake
605
603
  - tasks/events.rake
606
604
  - tasks/profile.rake
@@ -642,7 +640,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
642
640
  version: '0'
643
641
  requirements: []
644
642
  rubyforge_project:
645
- rubygems_version: 2.2.2
643
+ rubygems_version: 2.4.5
646
644
  signing_key:
647
645
  specification_version: 4
648
646
  summary: Intelligent, scalable, distributed monitoring notification system.
data/Gemfile-ruby1.9 DELETED
@@ -1,30 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec :name => 'flapjack'
4
-
5
- group :development do
6
- gem 'ruby-prof'
7
- end
8
-
9
- group :test do
10
- gem 'rspec', '~> 3.0'
11
- gem 'cucumber', '>= 2.0.0.beta.3'
12
- gem 'delorean'
13
- gem 'rack-test'
14
- gem 'pact'
15
- gem 'async_rack_test', '>= 0.0.5'
16
- gem 'resque_spec'
17
- gem 'webmock'
18
- gem 'guard'
19
- gem 'rb-fsevent'
20
- gem 'guard-rspec'
21
- gem 'guard-cucumber'
22
- gem 'fuubar'
23
- 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
- end