flapjack 0.7.1 → 0.7.2

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. data/CHANGELOG.md +29 -0
  2. data/README.md +1 -4
  3. data/bin/flapjack +24 -2
  4. data/bin/flapjack-nagios-receiver +4 -2
  5. data/bin/receive-events +191 -0
  6. data/bin/simulate-failed-check +144 -0
  7. data/features/notification_rules.feature +63 -2
  8. data/features/steps/events_steps.rb +15 -3
  9. data/flapjack.gemspec +1 -1
  10. data/lib/flapjack/data/contact.rb +15 -9
  11. data/lib/flapjack/data/entity.rb +19 -1
  12. data/lib/flapjack/data/entity_check.rb +12 -0
  13. data/lib/flapjack/data/event.rb +10 -2
  14. data/lib/flapjack/data/notification.rb +12 -8
  15. data/lib/flapjack/data/notification_rule.rb +3 -1
  16. data/lib/flapjack/executive.rb +71 -17
  17. data/lib/flapjack/gateways/api.rb +5 -2
  18. data/lib/flapjack/gateways/jabber.rb +26 -17
  19. data/lib/flapjack/gateways/web.rb +54 -9
  20. data/lib/flapjack/gateways/web/public/css/bootstrap-responsive.min.css +9 -0
  21. data/lib/flapjack/gateways/web/public/css/bootstrap.min.css +9 -0
  22. data/lib/flapjack/gateways/web/public/css/flapjack.css +51 -0
  23. data/lib/flapjack/gateways/web/public/img/flapjack_white_bg_400_353.jpeg +0 -0
  24. data/lib/flapjack/gateways/web/public/img/glyphicons-halflings-white.png +0 -0
  25. data/lib/flapjack/gateways/web/public/img/glyphicons-halflings.png +0 -0
  26. data/lib/flapjack/gateways/web/public/js/bootstrap.min.js +6 -0
  27. data/lib/flapjack/gateways/web/views/_foot.haml +8 -0
  28. data/lib/flapjack/gateways/web/views/_head.haml +10 -0
  29. data/lib/flapjack/gateways/web/views/_nav.haml +9 -3
  30. data/lib/flapjack/gateways/web/views/check.haml +140 -138
  31. data/lib/flapjack/gateways/web/views/checks.haml +49 -0
  32. data/lib/flapjack/gateways/web/views/contact.haml +78 -37
  33. data/lib/flapjack/gateways/web/views/contacts.haml +23 -17
  34. data/lib/flapjack/gateways/web/views/entities.haml +28 -0
  35. data/lib/flapjack/gateways/web/views/entity.haml +44 -0
  36. data/lib/flapjack/gateways/web/views/index.haml +27 -44
  37. data/lib/flapjack/gateways/web/views/self_stats.haml +65 -22
  38. data/lib/flapjack/version.rb +1 -1
  39. data/spec/lib/flapjack/executive_spec.rb +6 -2
  40. data/spec/lib/flapjack/gateways/api_spec.rb +15 -0
  41. data/spec/lib/flapjack/gateways/web/views/contact.haml_spec.rb +2 -1
  42. data/spec/lib/flapjack/gateways/web/views/index.haml_spec.rb +3 -2
  43. data/spec/lib/flapjack/gateways/web_spec.rb +23 -9
  44. data/tmp/create_events_failure.rb +6 -4
  45. metadata +23 -12
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module Flapjack
4
- VERSION = "0.7.1"
4
+ VERSION = "0.7.2"
5
5
  end
@@ -19,19 +19,23 @@ describe Flapjack::Executive, :logger => true do
19
19
 
20
20
  redis = mock('redis')
21
21
 
22
- redis.should_receive(:set).with('boot_time', a_kind_of(Integer))
22
+ #redis.should_receive(:set).with('boot_time', a_kind_of(Integer))
23
+ redis.should_receive(:hset).with(/^executive_instance:/, "boot_time", anything)
23
24
  redis.should_receive(:hget).with('event_counters', 'all').and_return(nil)
24
25
  redis.should_receive(:hset).with('event_counters', 'all', 0)
25
26
  redis.should_receive(:hset).with('event_counters', 'ok', 0)
26
27
  redis.should_receive(:hset).with('event_counters', 'failure', 0)
27
28
  redis.should_receive(:hset).with('event_counters', 'action', 0)
28
29
 
29
- redis.should_receive(:zadd).with('executive_instances', a_kind_of(Integer), a_kind_of(String))
30
+ #redis.should_receive(:zadd).with('executive_instances', a_kind_of(Integer), a_kind_of(String))
30
31
  redis.should_receive(:hset).with(/^event_counters:/, 'all', 0)
31
32
  redis.should_receive(:hset).with(/^event_counters:/, 'ok', 0)
32
33
  redis.should_receive(:hset).with(/^event_counters:/, 'failure', 0)
33
34
  redis.should_receive(:hset).with(/^event_counters:/, 'action', 0)
34
35
 
36
+ redis.should_receive(:expire).with(/^executive_instance:/, anything).twice
37
+ redis.should_receive(:expire).with(/^event_counters:/, anything).exactly(8).times
38
+
35
39
  redis.should_receive(:hincrby).with('event_counters', 'all', 1)
36
40
  redis.should_receive(:hincrby).with(/^event_counters:/, 'all', 1)
37
41
 
@@ -196,6 +196,21 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json =>
196
196
  last_response.status.should == 204
197
197
  end
198
198
 
199
+ it "creates a scheduled maintenance for an entity check" do
200
+ start = Time.now + (60 * 60) # an hour from now
201
+ duration = (2 * 60 * 60) # two hours
202
+ Flapjack::Data::Entity.should_receive(:find_by_name).
203
+ with(entity_name, :redis => redis).and_return(entity)
204
+ Flapjack::Data::EntityCheck.should_receive(:for_entity).
205
+ with(entity, check, :redis => redis).and_return(entity_check)
206
+ entity_check.should_receive(:create_scheduled_maintenance).
207
+ with(:summary => 'test', :duration => duration, :start_time => start.getutc.to_i)
208
+
209
+ post "/scheduled_maintenances/#{entity_name_esc}/#{check}?" +
210
+ "start_time=#{CGI.escape(start.iso8601)}&summary=test&duration=#{duration}"
211
+ last_response.status.should == 204
212
+ end
213
+
199
214
  it "returns a list of scheduled maintenance periods within a time window for an entity" do
200
215
  start = Time.parse('1 Jan 2012')
201
216
  finish = Time.parse('6 Jan 2012')
@@ -6,9 +6,10 @@ describe 'web/views/contact.haml', :haml_view => true do
6
6
  @contact = mock('contact')
7
7
  @contact.should_receive(:media)
8
8
  @contact.should_receive(:name).twice.and_return('Aeschylus')
9
+ @contact.should_receive(:notification_rules)
9
10
 
10
11
  entity = mock('entity')
11
- entity.should_receive(:name).twice.and_return('abc-xyz-01')
12
+ entity.should_receive(:name).exactly(3).times.and_return('abc-xyz-01')
12
13
 
13
14
  checks = ['Disk / Utilisation']
14
15
 
@@ -1,11 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'web/views/index.haml', :haml_view => true do
3
+ describe 'web/views/checks.haml', :haml_view => true do
4
4
 
5
5
  it "should escape unsafe check characters in URI parameters" do
6
6
  @states = [['abc-xyz-01', 'Disk / Utilisation', '-', '-', '-', false, false, nil, nil]]
7
+ @adjective = "all"
7
8
 
8
- page = render_haml('index.haml', self)
9
+ page = render_haml('checks.haml', self)
9
10
  page.should match(%r{\?entity=abc-xyz-01&check=Disk\+%2F\+Utilisation})
10
11
  end
11
12
 
@@ -19,6 +19,7 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
19
19
  before(:all) do
20
20
  Flapjack::Gateways::Web.class_eval {
21
21
  set :raise_errors, true
22
+ set :show_exceptions, false
22
23
  }
23
24
  Flapjack::Gateways::Web.instance_variable_get('@middleware').delete_if {|m|
24
25
  m[0] == Rack::FiberPool
@@ -33,10 +34,11 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
33
34
  end
34
35
 
35
36
  def expect_stats
36
- redis.should_receive(:keys).with('*').and_return([])
37
- redis.should_receive(:zcard).with('failed_checks')
37
+ redis.should_receive(:keys).with('*').and_return(['a', 'b', 'c'])
38
38
  redis.should_receive(:keys).with('check:*:*').and_return([])
39
- redis.should_receive(:zscore).with('executive_instances', anything).and_return(Time.now.to_i)
39
+ redis.should_receive(:zcard).with('failed_checks')
40
+ redis.should_receive(:keys).with('executive_instance:*').and_return(["executive_instance:foo-app-01"])
41
+ redis.should_receive(:hget).twice.and_return(Time.now.to_i - 60)
40
42
  redis.should_receive(:hgetall).twice.and_return({'all' => '8001', 'ok' => '8002'},
41
43
  {'all' => '9001', 'ok' => '9002'})
42
44
  redis.should_receive(:llen).with('events')
@@ -60,10 +62,11 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
60
62
 
61
63
  it "shows a page listing all checks" do
62
64
  redis.should_receive(:keys).with('*:*:states').and_return(["#{entity_name}:#{check}:states"])
65
+ redis.should_receive(:keys).with('check:*').and_return(["#{entity_name}:#{check}:states"])
63
66
 
64
67
  expect_stats
65
68
 
66
- redis.should_receive(:zrange).with("executive_instances", "0", "-1", :withscores => true)
69
+ redis.should_receive(:zrange).with("failed_checks", 0, -1).and_return([])
67
70
 
68
71
  expect_entity_check_status(entity_check)
69
72
 
@@ -73,13 +76,13 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
73
76
  Flapjack::Data::EntityCheck.should_receive(:for_entity).
74
77
  with(entity, 'ping', :redis => redis).and_return(entity_check)
75
78
 
76
- get '/'
79
+ get '/checks_all'
77
80
  last_response.should be_ok
78
81
  end
79
82
 
80
83
  it "shows a page listing failing checks" do
81
- redis.should_receive(:zrange).with("executive_instances", "0", "-1", :withscores => true)
82
- redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"])
84
+ redis.should_receive(:zrange).with('failed_checks', 0, -1).twice.and_return(["#{entity_name}:#{check}:states"])
85
+ redis.should_receive(:keys).with('check:*').and_return(["#{entity_name}:#{check}:states"])
83
86
 
84
87
  expect_stats
85
88
 
@@ -90,13 +93,14 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
90
93
 
91
94
  Flapjack::Data::EntityCheck.should_receive(:for_entity).
92
95
  with(entity, 'ping', :redis => redis).and_return(entity_check)
93
- get '/failing'
96
+ get '/checks_failing'
94
97
  last_response.should be_ok
95
98
  end
96
99
 
97
100
  it "shows a page listing flapjack statistics" do
101
+ redis.should_receive(:keys).with('check:*').and_return([])
102
+ redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"])
98
103
  expect_stats
99
- redis.should_receive(:zrange).with("executive_instances", "0", "-1", :withscores => true)
100
104
 
101
105
  get '/self_stats'
102
106
  last_response.should be_ok
@@ -109,6 +113,9 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
109
113
  :recovery => time - (3 * 60 * 60),
110
114
  :acknowledgement => nil }
111
115
 
116
+ expect_stats
117
+ redis.should_receive(:keys).with('check:*').and_return([])
118
+ redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return([])
112
119
  entity_check.should_receive(:state).and_return('ok')
113
120
  entity_check.should_receive(:last_update).and_return(time - (3 * 60 * 60))
114
121
  entity_check.should_receive(:last_change).and_return(time - (3 * 60 * 60))
@@ -228,6 +235,9 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
228
235
 
229
236
  it "shows a list of all known contacts" do
230
237
  Flapjack::Data::Contact.should_receive(:all)
238
+ redis.should_receive(:keys).with('check:*').and_return([])
239
+ redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"])
240
+ expect_stats
231
241
 
232
242
  get "/contacts"
233
243
  last_response.should be_ok
@@ -238,6 +248,10 @@ describe Flapjack::Gateways::Web, :sinatra => true, :logger => true do
238
248
  contact.should_receive(:name).twice.and_return("Smithson Smith")
239
249
  contact.should_receive(:media).exactly(3).times.and_return({})
240
250
  contact.should_receive(:entities).with(:checks => true).and_return([])
251
+ contact.should_receive(:notification_rules).and_return([])
252
+ redis.should_receive(:keys).with('check:*').and_return([])
253
+ redis.should_receive(:zrange).with('failed_checks', 0, -1).and_return(["#{entity_name}:#{check}:states"])
254
+ expect_stats
241
255
 
242
256
  Flapjack::Data::Contact.should_receive(:find_by_id).
243
257
  with('0362', :redis => redis).and_return(contact)
@@ -8,10 +8,12 @@ id = "%.2d" % (1..10).to_a[rand(9)]
8
8
  events = []
9
9
 
10
10
  events << {
11
- 'entity' => "app-#{id}",
12
- 'check' => 'http',
13
- 'type' => 'service',
14
- 'state' => 'critical',
11
+ 'entity' => "app-#{id}",
12
+ 'check' => 'http',
13
+ 'type' => 'service',
14
+ 'state' => 'critical',
15
+ 'summary' => "It's failing, yo!",
16
+ 'timestamp' => Time.now.to_i,
15
17
  }.to_json
16
18
 
17
19
  redis = Redis.new
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: 0.7.1
4
+ version: 0.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-04-24 00:00:00.000000000 Z
14
+ date: 2013-05-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: dante
@@ -258,17 +258,17 @@ dependencies:
258
258
  requirement: !ruby/object:Gem::Requirement
259
259
  none: false
260
260
  requirements:
261
- - - '='
261
+ - - ~>
262
262
  - !ruby/object:Gem::Version
263
- version: 0.8.1
263
+ version: 0.8.3
264
264
  type: :runtime
265
265
  prerelease: false
266
266
  version_requirements: !ruby/object:Gem::Requirement
267
267
  none: false
268
268
  requirements:
269
- - - '='
269
+ - - ~>
270
270
  - !ruby/object:Gem::Version
271
- version: 0.8.1
271
+ version: 0.8.3
272
272
  - !ruby/object:Gem::Dependency
273
273
  name: chronic
274
274
  requirement: !ruby/object:Gem::Requirement
@@ -375,6 +375,8 @@ executables:
375
375
  - flapjack-netsaint-parser
376
376
  - flapjack-populator
377
377
  - flapper
378
+ - receive-events
379
+ - simulate-failed-check
378
380
  extensions: []
379
381
  extra_rdoc_files: []
380
382
  files:
@@ -383,6 +385,7 @@ files:
383
385
  - .rbenv-version
384
386
  - .rspec
385
387
  - .travis.yml
388
+ - CHANGELOG.md
386
389
  - Gemfile
387
390
  - Guardfile
388
391
  - LICENCE
@@ -393,6 +396,8 @@ files:
393
396
  - bin/flapjack-netsaint-parser
394
397
  - bin/flapjack-populator
395
398
  - bin/flapper
399
+ - bin/receive-events
400
+ - bin/simulate-failed-check
396
401
  - config.ru
397
402
  - dist/etc/init.d/flapjack
398
403
  - dist/etc/init.d/flapjack-nagios-receiver
@@ -452,11 +457,23 @@ files:
452
457
  - lib/flapjack/gateways/pagerduty.rb
453
458
  - lib/flapjack/gateways/sms_messagenet.rb
454
459
  - lib/flapjack/gateways/web.rb
460
+ - lib/flapjack/gateways/web/public/css/bootstrap-responsive.min.css
461
+ - lib/flapjack/gateways/web/public/css/bootstrap.min.css
462
+ - lib/flapjack/gateways/web/public/css/flapjack.css
463
+ - lib/flapjack/gateways/web/public/img/flapjack_white_bg_400_353.jpeg
464
+ - lib/flapjack/gateways/web/public/img/glyphicons-halflings-white.png
465
+ - lib/flapjack/gateways/web/public/img/glyphicons-halflings.png
466
+ - lib/flapjack/gateways/web/public/js/bootstrap.min.js
455
467
  - lib/flapjack/gateways/web/views/_css.haml
468
+ - lib/flapjack/gateways/web/views/_foot.haml
469
+ - lib/flapjack/gateways/web/views/_head.haml
456
470
  - lib/flapjack/gateways/web/views/_nav.haml
457
471
  - lib/flapjack/gateways/web/views/check.haml
472
+ - lib/flapjack/gateways/web/views/checks.haml
458
473
  - lib/flapjack/gateways/web/views/contact.haml
459
474
  - lib/flapjack/gateways/web/views/contacts.haml
475
+ - lib/flapjack/gateways/web/views/entities.haml
476
+ - lib/flapjack/gateways/web/views/entity.haml
460
477
  - lib/flapjack/gateways/web/views/index.haml
461
478
  - lib/flapjack/gateways/web/views/self_stats.haml
462
479
  - lib/flapjack/logger.rb
@@ -534,18 +551,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
534
551
  - - ! '>='
535
552
  - !ruby/object:Gem::Version
536
553
  version: '0'
537
- segments:
538
- - 0
539
- hash: 308146534625742434
540
554
  required_rubygems_version: !ruby/object:Gem::Requirement
541
555
  none: false
542
556
  requirements:
543
557
  - - ! '>='
544
558
  - !ruby/object:Gem::Version
545
559
  version: '0'
546
- segments:
547
- - 0
548
- hash: 308146534625742434
549
560
  requirements: []
550
561
  rubyforge_project:
551
562
  rubygems_version: 1.8.23