flapjack 0.7.29 → 0.7.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG.md +8 -0
  2. data/bin/flapjack-nagios-receiver +20 -15
  3. data/bin/flapjack-populator +30 -13
  4. data/bin/flapper +1 -1
  5. data/bin/receive-events +13 -10
  6. data/bin/simulate-failed-check +13 -3
  7. data/dist/etc/init.d/flapjack +5 -42
  8. data/dist/etc/init.d/flapjack-nagios-receiver +3 -17
  9. data/dist/etc/init.d/flapper +3 -12
  10. data/etc/flapjack_config.yaml.example +81 -52
  11. data/features/cli.feature +30 -13
  12. data/features/cli_flapjack-nagios-receiver.feature +66 -0
  13. data/features/cli_flapjack-populator.feature +80 -0
  14. data/features/cli_flapper.feature +45 -0
  15. data/features/cli_receive-events.feature +27 -0
  16. data/features/cli_simulate-failed-check.feature +31 -0
  17. data/features/events.feature +3 -6
  18. data/features/packaging-lintian.feature +2 -2
  19. data/features/rollup.feature +2 -4
  20. data/features/steps/cli_steps.rb +25 -7
  21. data/features/steps/packaging-lintian_steps.rb +12 -6
  22. data/features/support/daemons.rb +11 -1
  23. data/features/support/env.rb +16 -4
  24. data/lib/flapjack/coordinator.rb +1 -1
  25. data/lib/flapjack/filters/delays.rb +1 -1
  26. data/lib/flapjack/gateways/email/alert.html.erb +1 -1
  27. data/lib/flapjack/gateways/email/alert.text.erb +1 -1
  28. data/lib/flapjack/gateways/email/rollup.html.erb +1 -1
  29. data/lib/flapjack/gateways/email/rollup.text.erb +1 -1
  30. data/lib/flapjack/gateways/web/views/check.html.erb +1 -1
  31. data/lib/flapjack/gateways/web/views/contact.html.erb +37 -32
  32. data/lib/flapjack/gateways/web.rb +7 -7
  33. data/lib/flapjack/logger.rb +25 -45
  34. data/lib/flapjack/version.rb +1 -1
  35. data/spec/lib/flapjack/coordinator_spec.rb +9 -7
  36. data/spec/lib/flapjack/logger_spec.rb +19 -13
  37. data/tasks/benchmarks.rake +1 -1
  38. data/tasks/support/flapjack_config_benchmark.yaml +1 -29
  39. metadata +97 -47
  40. checksums.yaml +0 -7
  41. data/bin/flapjack-netsaint-parser +0 -432
  42. data/dist/puppet/flapjack/files/.stub +0 -0
  43. data/dist/puppet/flapjack/manifests/common.pp +0 -61
  44. data/dist/puppet/flapjack/manifests/notifier.pp +0 -13
  45. data/dist/puppet/flapjack/manifests/worker.pp +0 -13
  46. data/dist/puppet/flapjack/templates/.stub +0 -0
  47. data/dist/puppet/ruby/manifests/dev.pp +0 -5
  48. data/dist/puppet/ruby/manifests/rubygems.pp +0 -14
  49. data/dist/puppet/sqlite3/manifests/dev.pp +0 -5
data/features/cli.feature CHANGED
@@ -5,7 +5,7 @@ Feature: command line utility
5
5
  From the command line
6
6
 
7
7
  Background:
8
- Given a file named "flapjack_cfg.yml" with:
8
+ Given a file named "flapjack_cfg.yaml" with:
9
9
  """
10
10
  test:
11
11
  redis:
@@ -15,7 +15,7 @@ test:
15
15
  logger:
16
16
  level: warn
17
17
  """
18
- And a file named "flapjack_cfg_d.yml" with:
18
+ And a file named "flapjack_cfg_d.yaml" with:
19
19
  """
20
20
  test:
21
21
  pid_file: tmp/cucumber_cli/flapjack_d.pid
@@ -28,34 +28,49 @@ test:
28
28
  level: warn
29
29
  """
30
30
 
31
+ Scenario: Running with --help shows usage information
32
+ When I run `bin/flapjack --help`
33
+ Then the exit status should be 0
34
+ And the output should contain "Usage: flapjack"
35
+ And the output should contain " reload "
36
+ And the output should contain "-c, --config"
37
+
38
+ Scenario: Getting status when stopped
39
+ When I run `bin/flapjack status --config tmp/cucumber_cli/flapjack_cfg_d.yaml`
40
+ Then the exit status should not be 0
41
+ And the output should contain "Flapjack is not running"
42
+
31
43
  Scenario: Starting flapjack
32
- When I start flapjack with `flapjack start --config tmp/cucumber_cli/flapjack_cfg.yml`
44
+ When I start flapjack with `flapjack start --config tmp/cucumber_cli/flapjack_cfg.yaml`
33
45
  Then flapjack should start within 15 seconds
34
46
 
35
47
  Scenario: Stopping flapjack via SIGINT
36
- When I start flapjack with `flapjack start --config tmp/cucumber_cli/flapjack_cfg.yml`
48
+ When I start flapjack with `flapjack start --config tmp/cucumber_cli/flapjack_cfg.yaml`
37
49
  Then flapjack should start within 15 seconds
38
50
  When I send a SIGINT to the flapjack process
39
51
  Then flapjack should stop within 15 seconds
40
52
 
41
- Scenario: Starting and stopping flapjack, daemonized
42
- When I start flapjack (daemonised) with `flapjack start -d --config tmp/cucumber_cli/flapjack_cfg_d.yml`
53
+ Scenario: Starting, status and stopping flapjack, daemonized
54
+ When I start flapjack (daemonised) with `flapjack start -d --config tmp/cucumber_cli/flapjack_cfg_d.yaml`
43
55
  Then flapjack should start within 15 seconds
44
- When I stop flapjack with `flapjack stop --config tmp/cucumber_cli/flapjack_cfg_d.yml`
56
+ When I run `bin/flapjack status --config tmp/cucumber_cli/flapjack_cfg_d.yaml`
57
+ Then the exit status should be 0
58
+ And the output should contain "Flapjack is running"
59
+ When I stop flapjack with `flapjack stop --config tmp/cucumber_cli/flapjack_cfg_d.yaml`
45
60
  Then flapjack should stop within 15 seconds
46
61
 
47
62
  Scenario: Starting, restarting and stopping flapjack, daemonized
48
- When I start flapjack (daemonised) with `flapjack start -d --config tmp/cucumber_cli/flapjack_cfg_d.yml`
63
+ When I start flapjack (daemonised) with `flapjack start -d --config tmp/cucumber_cli/flapjack_cfg_d.yaml`
49
64
  Then flapjack should start within 15 seconds
50
- When I restart flapjack with `flapjack restart -d --config tmp/cucumber_cli/flapjack_cfg_d.yml`
65
+ When I restart flapjack with `flapjack restart -d --config tmp/cucumber_cli/flapjack_cfg_d.yaml`
51
66
  Then flapjack should restart within 15 seconds
52
- When I stop flapjack with `flapjack stop --config tmp/cucumber_cli/flapjack_cfg_d.yml`
67
+ When I stop flapjack with `flapjack stop --config tmp/cucumber_cli/flapjack_cfg_d.yaml`
53
68
  Then flapjack should stop within 15 seconds
54
69
 
55
70
  Scenario: Reloading flapjack configuration
56
- When I start flapjack with `flapjack start --config tmp/cucumber_cli/flapjack_cfg.yml`
57
- When I run `mv tmp/cucumber_cli/flapjack_cfg.yml tmp/cucumber_cli/flapjack_cfg.yml.bak`
58
- Given a file named "flapjack_cfg.yml" with:
71
+ When I start flapjack with `flapjack start --config tmp/cucumber_cli/flapjack_cfg.yaml`
72
+ When I run `mv tmp/cucumber_cli/flapjack_cfg.yaml tmp/cucumber_cli/flapjack_cfg.yaml.bak`
73
+ Given a file named "flapjack_cfg.yaml" with:
59
74
  """
60
75
  test:
61
76
  redis:
@@ -67,3 +82,5 @@ test:
67
82
  # TODO how to test for config file change?
68
83
  When I send a SIGINT to the flapjack process
69
84
  Then flapjack should stop within 15 seconds
85
+
86
+
@@ -0,0 +1,66 @@
1
+ @process
2
+ Feature: flapjack-nagios-receiver command line
3
+ As a systems administrator
4
+ I should be able to manage flapjack-nagios-receiver
5
+ From the command line
6
+
7
+ Background:
8
+ Given a fifo named "tmp/cucumber_cli/nagios_perfdata.fifo" exists
9
+ And a file named "flapjack-nagios-receiver.yaml" with:
10
+ """
11
+ test:
12
+ redis:
13
+ db: 14
14
+ nagios-receiver:
15
+ fifo: "tmp/cucumber_cli/nagios_perfdata.fifo"
16
+ """
17
+ And a file named "flapjack-nagios-receiver_d.yaml" with:
18
+ """
19
+ test:
20
+ redis:
21
+ db: 14
22
+ nagios-receiver:
23
+ fifo: "tmp/cucumber_cli/nagios_perfdata.fifo"
24
+ pid_file: "tmp/cucumber_cli/flapjack-nagios-receiver_d.pid"
25
+ log_file: "tmp/cucumber_cli/flapjack-nagios-receiver_d.log"
26
+ """
27
+
28
+ Scenario: Running with --help shows usage information
29
+ When I run `bin/flapjack-nagios-receiver --help`
30
+ Then the exit status should be 0
31
+ And the output should contain "Usage: flapjack-nagios-receiver"
32
+ And the output should contain "-f, --fifo FIFO"
33
+
34
+ Scenario: Starting flapjack-nagios-receiver
35
+ When I start flapjack-nagios-receiver with `flapjack-nagios-receiver start --no-daemonize --config tmp/cucumber_cli/flapjack-nagios-receiver.yaml`
36
+ Then flapjack-nagios-receiver should start within 15 seconds
37
+
38
+ Scenario: Stopping flapjack-nagios-receiver via SIGINT
39
+ When I start flapjack-nagios-receiver with `flapjack-nagios-receiver start --no-daemonize --config tmp/cucumber_cli/flapjack-nagios-receiver.yaml`
40
+ Then flapjack-nagios-receiver should start within 15 seconds
41
+ When I send a SIGINT to the flapjack-nagios-receiver process
42
+ Then flapjack-nagios-receiver should stop within 15 seconds
43
+
44
+ Scenario: Starting, status, and stopping flapjack-nagios-receiver, daemonized
45
+ When I start flapjack-nagios-receiver (daemonised) with `flapjack-nagios-receiver start -d --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml`
46
+ Then flapjack-nagios-receiver should start within 15 seconds
47
+ When I run `bin/flapjack-nagios-receiver status --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml`
48
+ Then the exit status should be 0
49
+ And the output should contain "flapjack-nagios-receiver is running"
50
+ When I stop flapjack-nagios-receiver with `flapjack-nagios-receiver stop --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml`
51
+ Then flapjack-nagios-receiver should stop within 15 seconds
52
+
53
+ Scenario: Starting, restarting and stopping flapjack-nagios-receiver, daemonized
54
+ When I start flapjack-nagios-receiver (daemonised) with `flapjack-nagios-receiver start -d --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml`
55
+ Then flapjack-nagios-receiver should start within 15 seconds
56
+ When I restart flapjack-nagios-receiver (daemonised) with `flapjack-nagios-receiver restart -d --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml`
57
+ Then flapjack-nagios-receiver should restart within 15 seconds
58
+ When I stop flapjack-nagios-receiver with `flapjack-nagios-receiver stop --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml`
59
+ Then flapjack-nagios-receiver should stop within 15 seconds
60
+
61
+ Scenario: Getting status when stopped
62
+ When I run `bin/flapjack-nagios-receiver status --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml`
63
+ Then the exit status should not be 0
64
+ And the output should contain "flapjack-nagios-receiver is not running"
65
+
66
+
@@ -0,0 +1,80 @@
1
+ @process
2
+ Feature: flapjack-populator command line
3
+ As a systems administrator
4
+ I should be able to use flapjack-populator
5
+ From the command line
6
+
7
+ Background:
8
+ Given a file named "flapjack-populator.yaml" with:
9
+ """
10
+ test:
11
+ redis:
12
+ db: 14
13
+ """
14
+ And a file named "flapjack-populator-contacts.json" with:
15
+ """
16
+ [
17
+ {
18
+ "id": "21",
19
+ "first_name": "Ada",
20
+ "last_name": "Lovelace",
21
+ "email": "ada@example.com",
22
+ "media": {
23
+ "sms": {
24
+ "address": "+61412345678",
25
+ "interval": "3600",
26
+ "rollup_threshold": "5"
27
+ },
28
+ "email": {
29
+ "address": "ada@example.com",
30
+ "interval": "7200",
31
+ "rollup_threshold": null
32
+ }
33
+ },
34
+ "tags": [
35
+ "legend",
36
+ "first computer programmer"
37
+ ]
38
+ }
39
+ ]
40
+ """
41
+ And a file named "flapjack-populator-entities.json" with:
42
+ """
43
+ [
44
+ {
45
+ "id": "10001",
46
+ "name": "clientx-app-01",
47
+ "contacts": [
48
+ "362",
49
+ "363",
50
+ "364"
51
+ ],
52
+ "tags": [
53
+ "source:titanium",
54
+ "foo"
55
+ ]
56
+ }
57
+ ]
58
+ """
59
+
60
+ Scenario: Running with --help shows usage information
61
+ When I run `bin/flapjack-populator --help`
62
+ Then the exit status should be 0
63
+ And the output should contain "Usage: flapjack-populator"
64
+ And the output should contain "import-contacts"
65
+ And the output should contain "import-entities"
66
+ And the output should contain "--config"
67
+
68
+ Scenario: Running flapjack-populator with no arguments exits uncleanly and shows usage
69
+ When I run `bin/flapjack-populator`
70
+ Then the exit status should not be 0
71
+ And the output should contain "Usage: flapjack-populator"
72
+
73
+ Scenario: Importing contacts
74
+ When I run `bin/flapjack-populator import-contacts --from tmp/cucumber_cli/flapjack-populator-contacts.json --config tmp/cucumber_cli/flapjack-populator.yaml`
75
+ Then the exit status should be 0
76
+
77
+ Scenario: Importing entities
78
+ When I run `bin/flapjack-populator import-entities --from tmp/cucumber_cli/flapjack-populator-entities.json --config tmp/cucumber_cli/flapjack-populator.yaml`
79
+ Then the exit status should be 0
80
+
@@ -0,0 +1,45 @@
1
+ @process
2
+ Feature: Flapper command line
3
+ As a systems administrator
4
+ I should be able to manage flapper
5
+ From the command line
6
+
7
+ Scenario: Running with --help shows usage information
8
+ When I run `bin/flapper --help`
9
+ Then the exit status should be 0
10
+ And the output should contain "Usage: flapper"
11
+ And the output should contain "-b, --bind-ip"
12
+
13
+ Scenario: Starting flapper
14
+ When I start flapper with `flapper start --no-daemonize`
15
+ Then flapper should start within 15 seconds
16
+
17
+ Scenario: Stopping flapper via SIGINT
18
+ When I start flapper with `flapper start --no-daemonize`
19
+ Then flapper should start within 15 seconds
20
+ When I send a SIGINT to the flapper process
21
+ Then flapper should stop within 15 seconds
22
+
23
+ Scenario: Starting, status, and stopping flapper, daemonized
24
+ When I start flapper (daemonised) with `flapper start -d -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
25
+ Then flapper should start within 15 seconds
26
+ When I run `bin/flapper status -p tmp/cucumber_cli/flapper_d.pid`
27
+ Then the exit status should be 0
28
+ And the output should contain "flapper is running"
29
+ When I stop flapper with `flapper stop -p tmp/cucumber_cli/flapper_d.pid`
30
+ Then flapper should stop within 15 seconds
31
+
32
+ Scenario: Starting, restarting and stopping flapper, daemonized
33
+ When I start flapper (daemonised) with `flapper start -d -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
34
+ Then flapper should start within 15 seconds
35
+ When I restart flapper (daemonised) with `flapper restart -d -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
36
+ Then flapper should restart within 15 seconds
37
+ When I stop flapper with `flapper stop -p tmp/cucumber_cli/flapper_d.pid`
38
+ Then flapper should stop within 15 seconds
39
+
40
+ Scenario: Getting status when stopped
41
+ When I run `bin/flapper status -p tmp/cucumber_cli/flapper_d.pid`
42
+ Then the exit status should not be 0
43
+ And the output should contain "flapper is not running"
44
+
45
+
@@ -0,0 +1,27 @@
1
+ @process
2
+ Feature: receive-events command line
3
+ As a systems administrator
4
+ I should be able to use receive-events
5
+ From the command line
6
+
7
+ Background:
8
+ Given a file named "receive-events.yaml" with:
9
+ """
10
+ test:
11
+ redis:
12
+ db: 14
13
+ """
14
+
15
+ Scenario: Running with --help shows usage information
16
+ When I run `bin/receive-events --help`
17
+ Then the exit status should be 0
18
+ And the output should contain "Usage: receive-events"
19
+ And the output should contain "-s, --source URL"
20
+
21
+ Scenario: Running receive-events with no arguments exits uncleanly and shows usage
22
+ When I run `bin/receive-events`
23
+ Then the exit status should not be 0
24
+ And the output should contain "Usage: receive-events"
25
+
26
+ #TODO: put some archived events into a separate redis db and then run receive-events to suck them up
27
+
@@ -0,0 +1,31 @@
1
+ @process
2
+ Feature: simulate-failed-check command line
3
+ As a systems administrator
4
+ I should be able to use simulate-failed-check
5
+ From the command line
6
+
7
+ Background:
8
+ Given a file named "simulate-failed-check.yaml" with:
9
+ """
10
+ test:
11
+ redis:
12
+ db: 14
13
+ """
14
+
15
+ Scenario: Running with --help shows usage information
16
+ When I run `bin/simulate-failed-check --help`
17
+ Then the exit status should be 0
18
+ And the output should contain "Usage: simulate-failed-check"
19
+ And the output should contain "-k, --check CHECK"
20
+
21
+ Scenario: Running simulate-failed-check with no arguments exits uncleanly and shows usage
22
+ When I run `bin/simulate-failed-check`
23
+ Then the exit status should not be 0
24
+ And the output should contain "Usage: simulate-failed-check"
25
+
26
+ Scenario: Simulate a failed check
27
+ When I run `bin/simulate-failed-check fail -c tmp/cucumber_cli/simulate-failed-check.yaml -t 0 -i 0.1 -e 'test' -k 'PING'`
28
+ Then the exit status should be 0
29
+ And the output should contain "sending failure event"
30
+ And the output should contain "stopping"
31
+
@@ -60,13 +60,13 @@ Feature: events
60
60
  Then a notification should be generated
61
61
 
62
62
  @time
63
- Scenario: Check critical and alerted to critical for 1 minute
63
+ Scenario: Check critical and alerted to critical for 40 seconds
64
64
  Given the check is in an ok state
65
65
  When a critical event is received
66
66
  And 1 minute passes
67
67
  And a critical event is received
68
68
  Then a notification should be generated
69
- When 1 minute passes
69
+ When 40 seconds passes
70
70
  And a critical event is received
71
71
  Then a notification should not be generated
72
72
 
@@ -234,10 +234,7 @@ Feature: events
234
234
  When 10 seconds passes
235
235
  And an unknown event is received
236
236
  Then a notification should not be generated
237
- When 10 seconds passes
238
- And an unknown event is received
239
- Then a notification should not be generated
240
- When 5 minutes passes
237
+ When 1 minutes passes
241
238
  And an unknown event is received
242
239
  Then a notification should be generated
243
240
  When 10 seconds passes
@@ -4,12 +4,12 @@ Feature: Packagability
4
4
 
5
5
  Scenario: No rubygems references
6
6
  When I run `grep require lib/* bin/* -R |grep rubygems`
7
- Then the exit value should be 1
7
+ Then the exit status should not be 0
8
8
  And I should see 0 lines of output
9
9
 
10
10
  Scenario: A shebang that works everywhere
11
11
  When I run `find lib/ -type 'f' -name '*.rb'`
12
- Then the exit value should be 0
12
+ Then the exit status should be 0
13
13
  And every file in the output should start with "#!/usr/bin/env ruby"
14
14
 
15
15
 
@@ -172,10 +172,8 @@ Feature: Rollup on a per contact, per media basis
172
172
  And 1 sms alerts should be queued for +61400000001
173
173
  When 4 hours passes
174
174
  And a critical event is received for check 'ping' on entity 'foo'
175
- And 1 minute passes
176
- And a critical event is received for check 'ping' on entity 'foo'
177
- Then 1 sms alert of type problem and rollup problem should be queued for +61400000001
178
- And 2 sms alerts should be queued for +61400000001
175
+ Then 2 sms alerts should be queued for +61400000001
176
+ And 1 sms alert of type problem and rollup problem should be queued for +61400000001
179
177
 
180
178
  @time
181
179
  Scenario: Contact ceases to be a contact on an entity that they were being alerted for
@@ -7,31 +7,48 @@ Given /^a file named "([^"]*)" with:$/ do |file_name, file_content|
7
7
  write_file(file_name, file_content)
8
8
  end
9
9
 
10
- When /^I ((?:re)?start|stop) flapjack( \(daemonised\))? with `(.+)`$/ do |start_stop_restart, daemonise, cmd|
10
+ Given /^a fifo named "([^"]*)" exists$/ do |fifo_name|
11
+ create_fifo(fifo_name)
12
+ end
13
+
14
+ When /^I ((?:re)?start|stop) (\S+)( \(daemonised\))? with `(.+)`$/ do |start_stop_restart, exe, daemonise, cmd|
15
+ @daemons_output ||= []
16
+ @daemons_exit_status ||= []
17
+
11
18
  @root = Pathname.new(File.dirname(__FILE__)).parent.parent.expand_path
12
19
  command = "#{@root.join('bin')}/#{cmd}"
13
20
 
21
+ # enable debugging output from spawn_process etc
22
+ #@debug = true
23
+
14
24
  case start_stop_restart
15
25
  when 'start'
16
26
  @process_h = spawn_process(command,
17
- :daemon_pidfile => (daemonise.nil? || daemonise.empty?) ? nil : 'tmp/cucumber_cli/flapjack_d.pid')
27
+ :daemon_pidfile => (daemonise.nil? || daemonise.empty?) ? nil : "tmp/cucumber_cli/#{exe}_d.pid")
18
28
  when 'stop', 'restart'
19
- `#{command}`
29
+ @daemons_output << `#{command}`
30
+ @daemons_exit_status << $?
20
31
  end
32
+ puts "output: #{@daemons_output.join(', ')}, exit statuses: #{@daemons_exit_status}" if @debug
21
33
  end
22
34
 
23
- When /^I send a SIG(\w+) to the flapjack process$/ do |signal|
35
+ When /^I send a SIG(\w+) to the (?:\S+) process$/ do |signal|
24
36
  process = @process_h[:process]
25
37
  pid = process ? process.pid : @process_h[:pid]
26
38
  Process.kill(signal, pid)
27
39
  end
28
40
 
29
- Then /^flapjack should ((?:re)?start|stop) within (\d+) seconds$/ do |start_stop_restart, seconds|
41
+ Then /^(\S+) should ((?:re)?start|stop) within (\d+) seconds$/ do |exe, start_stop_restart, seconds|
30
42
  process = @process_h[:process]
31
43
  pid = process ? process.pid : @process_h[:pid]
32
44
  running = nil
33
45
  attempts = 0
34
- max_attempts = seconds.to_i * 200
46
+ max_attempts = seconds.to_i * 10
47
+
48
+ if @debug
49
+ puts "should #{start_stop_restart} within #{seconds} seconds..."
50
+ puts "pid: #{pid}, max_attempts: #{max_attempts}"
51
+ end
35
52
 
36
53
  case start_stop_restart
37
54
  when 'start'
@@ -39,6 +56,7 @@ Then /^flapjack should ((?:re)?start|stop) within (\d+) seconds$/ do |start_stop
39
56
  Process.kill(0, pid)
40
57
  running = true
41
58
  rescue Errno::EINVAL, Errno::ESRCH, RangeError, Errno::EPERM => e
59
+ puts "rescued error from kill: #{e.class} - #{e.message}" if @debug
42
60
  attempts += 1; sleep 0.1; retry if attempts < max_attempts
43
61
  running = false
44
62
  end
@@ -70,7 +88,7 @@ Then /^flapjack should ((?:re)?start|stop) within (\d+) seconds$/ do |start_stop
70
88
  when 'restart'
71
89
  read_pid = nil
72
90
  while attempts < max_attempts
73
- time_and_pid = time_and_pid_from_file('tmp/cucumber_cli/flapjack_d.pid')
91
+ time_and_pid = time_and_pid_from_file("tmp/cucumber_cli/#{exe}_d.pid")
74
92
  read_pid = time_and_pid.last
75
93
  break if read_pid != pid
76
94
  attempts += 1; sleep 0.1
@@ -13,15 +13,21 @@ Then /^every file in the output should start with "([^\"]*)"$/ do |string|
13
13
  end
14
14
 
15
15
  When /^I run `([^"]*)`$/ do |cmd|
16
- #bin_path = '/usr/bin'
17
- #command = "#{bin_path}/#{cmd}"
18
-
19
- #@output = `#{command}`
16
+ @cmd = cmd
20
17
  @output = `#{cmd} 2>&1`
21
18
  @exit_status = $?.exitstatus
19
+ puts "output: #{@output}" if @debug
20
+ puts "exit_status: #{@exit_status}" if @debug
22
21
  end
23
22
 
24
- Then /^the exit value should be (\d+)$/ do |number|
25
- @exit_status.should == number.to_i
23
+ Then /^the exit status should( not)? be (\d+)$/ do |negativity, number|
24
+ if negativity
25
+ @exit_status.should_not == number.to_i
26
+ else
27
+ @exit_status.should == number.to_i
28
+ end
26
29
  end
27
30
 
31
+ Then /^the output should contain "([^"]*)"$/ do |matcher|
32
+ @output.should include(matcher)
33
+ end
@@ -23,6 +23,12 @@ def write_file(file_name, file_content)
23
23
  _create_file(file_name, file_content, false)
24
24
  end
25
25
 
26
+ def create_fifo(fifo_name)
27
+ unless File.pipe?(fifo_name)
28
+ system("mkfifo #{fifo_name}")
29
+ end
30
+ end
31
+
26
32
  def _create_file(file_name, file_content, check_presence)
27
33
  in_current_dir do
28
34
  raise "expected #{file_name} to be present" if check_presence && !File.file?(file_name)
@@ -74,6 +80,9 @@ def time_and_pid_from_file(pid_file, cutoff_time = nil)
74
80
  end
75
81
 
76
82
  def spawn_process(command, opts={})
83
+ @daemons_output ||= []
84
+ @daemons_exit_status ||= []
85
+
77
86
  puts yellow("Running: #{command}") if @debug
78
87
 
79
88
  process_h = nil
@@ -84,7 +93,8 @@ def spawn_process(command, opts={})
84
93
  time = Time.now
85
94
  attempts = 0
86
95
 
87
- `#{command}`
96
+ @daemons_output << `#{command}`
97
+ @daemons_exit_status << $?
88
98
 
89
99
  while attempts < 50
90
100
  time_and_pid = time_and_pid_from_file(file, time)
@@ -19,6 +19,8 @@ if ENV['COVERAGE']
19
19
  end
20
20
  end
21
21
 
22
+ @debug = false
23
+
22
24
  ENV["FLAPJACK_ENV"] = 'test'
23
25
  FLAPJACK_ENV = 'test'
24
26
 
@@ -181,11 +183,21 @@ After('@time') do
181
183
  end
182
184
 
183
185
  After('@process') do
184
- ['tmp/cucumber_cli/flapjack_cfg.yml',
185
- 'tmp/cucumber_cli/flapjack_cfg.yml.bak',
186
- 'tmp/cucumber_cli/flapjack_cfg_d.yml',
186
+ ['tmp/cucumber_cli/flapjack_cfg.yaml',
187
+ 'tmp/cucumber_cli/flapjack_cfg.yaml.bak',
188
+ 'tmp/cucumber_cli/flapjack_cfg_d.yaml',
187
189
  'tmp/cucumber_cli/flapjack_d.log',
188
- 'tmp/cucumber_cli/flapjack_d.pid'].each do |file|
190
+ 'tmp/cucumber_cli/flapjack_d.pid',
191
+ 'tmp/cucumber_cli/nagios_perfdata.fifo',
192
+ 'tmp/cucumber_cli/flapjack-nagios-receiver_d.pid',
193
+ 'tmp/cucumber_cli/flapjack-nagios-receiver_d.log',
194
+ 'tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml',
195
+ 'tmp/cucumber_cli/flapjack-nagios-receiver.yaml',
196
+ 'tmp/cucumber_cli/flapper_d.pid',
197
+ 'tmp/cucumber_cli/flapper_d.log',
198
+ 'tmp/cucumber_cli/flapjack-populator.yaml',
199
+ 'tmp/cucumber_cli/flapjack-populator-contacts.json',
200
+ ].each do |file|
189
201
  next unless File.exists?(file)
190
202
  File.unlink(file)
191
203
  end
@@ -21,7 +21,7 @@ module Flapjack
21
21
  @redis_options = config.for_redis
22
22
  @pikelets = []
23
23
 
24
- @logger = Flapjack::Logger.new("flapjack-coordinator")
24
+ @logger = Flapjack::Logger.new("flapjack-coordinator", @config.all['logger'])
25
25
  end
26
26
 
27
27
  def start(options = {})
@@ -21,7 +21,7 @@ module Flapjack
21
21
 
22
22
  def block?(event, entity_check, previous_state)
23
23
  failure_delay = 30
24
- resend_delay = 300
24
+ resend_delay = 60
25
25
 
26
26
  label = 'Filter: Delays:'
27
27
 
@@ -54,7 +54,7 @@
54
54
  <% if @alert.state_duration && @alert.state_duration > 40 %>
55
55
  <tr>
56
56
  <td><strong>Duration</strong></td>
57
- <td><%= ChronicDuration.output(@alert.state_duration) %></td>
57
+ <td><%= ChronicDuration.output(@alert.state_duration, :keep_zero => true) || '0 secs' %></td>
58
58
  </tr>
59
59
  <% end %>
60
60
 
@@ -13,7 +13,7 @@ Details: <%= @alert.details %>
13
13
  Time: <%= Time.at(@alert.time.to_i).to_s %>
14
14
  <% end -%>
15
15
  <% if @alert.state_duration && @alert.state_duration > 40 -%>
16
- Duration: <%= ChronicDuration.output(@alert.state_duration) %>
16
+ Duration: <%= ChronicDuration.output(@alert.state_duration, :keep_zero => true) || '0 secs' %>
17
17
  <% end -%>
18
18
  <% if @alert.last_state -%>
19
19
  Previous State: <%= @alert.last_state_title_case %>
@@ -26,7 +26,7 @@
26
26
  <% @alert.rollup_alerts.sort_by {|entity_check, details| details['duration'] }.each do |rollup_alert| -%>
27
27
  <% r_entity, r_check = rollup_alert[0].split(':', 2) -%>
28
28
  <% state = rollup_alert[1]['state'] -%>
29
- <% duration = ChronicDuration.output(rollup_alert[1]['duration']) -%>
29
+ <% duration = (ChronicDuration.output(rollup_alert[1]['duration'], :keep_zero => true) || '0 secs') -%>
30
30
  <tr>
31
31
  <td><%= r_check %></td>
32
32
  <td><%= r_entity %></td>
@@ -5,7 +5,7 @@ You have <%= @alert.rollup_alerts.length %> alerting check<%= @alert.rollup_aler
5
5
  <% @alert.rollup_alerts.sort_by {|entity_check, details| details['duration'] }.each do |rollup_alert| -%>
6
6
  <% r_entity, r_check = rollup_alert[0].split(':', 2) -%>
7
7
  <% state = rollup_alert[1]['state'] -%>
8
- <% duration = ChronicDuration.output(rollup_alert[1]['duration'] ) -%>
8
+ <% duration = (ChronicDuration.output(rollup_alert[1]['duration'], :keep_zero => true) || '0 secs') -%>
9
9
  * <%= r_check %> on <%= r_entity %> is <%= ['ok'].include?(state) ? state.upcase : state.titleize %> (<%= duration %>)
10
10
  <% end -%>
11
11
 
@@ -109,7 +109,7 @@
109
109
  <tr>
110
110
  <td><%= h Time.at(start_time).to_s %></td>
111
111
  <td><%= h Time.at(end_time).to_s %></td>
112
- <td><%= h ChronicDuration.output(duration) %></td>
112
+ <td><%= h(ChronicDuration.output(duration, :keep_zero => true) || '0 secs') %></td>
113
113
  <td><%= h summary %></td>
114
114
  <td>
115
115
  <% if end_time > current_time.to_i %>