flapjack 1.0.0rc3 → 1.0.0rc5

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +20 -0
  5. data/CONTRIBUTING.md +2 -2
  6. data/Gemfile +1 -1
  7. data/README.md +6 -16
  8. data/build.sh +13 -1
  9. data/etc/flapjack_config.yaml.example +98 -12
  10. data/features/cli.feature +8 -8
  11. data/features/cli_flapjack-nagios-receiver.feature +29 -37
  12. data/features/cli_flapper.feature +24 -12
  13. data/features/cli_simulate-failed-check.feature +2 -2
  14. data/features/notifications.feature +18 -1
  15. data/features/steps/cli_steps.rb +2 -2
  16. data/features/steps/notifications_steps.rb +71 -0
  17. data/features/support/env.rb +7 -6
  18. data/flapjack.gemspec +3 -1
  19. data/lib/flapjack/cli/flapper.rb +74 -25
  20. data/lib/flapjack/cli/import.rb +3 -4
  21. data/lib/flapjack/cli/maintenance.rb +182 -0
  22. data/lib/flapjack/cli/receiver.rb +110 -121
  23. data/lib/flapjack/cli/server.rb +30 -26
  24. data/lib/flapjack/cli/simulate.rb +2 -3
  25. data/lib/flapjack/data/contact.rb +1 -1
  26. data/lib/flapjack/data/entity.rb +425 -32
  27. data/lib/flapjack/data/entity_check.rb +212 -14
  28. data/lib/flapjack/data/event.rb +1 -1
  29. data/lib/flapjack/gateways/aws_sns.rb +134 -0
  30. data/lib/flapjack/gateways/aws_sns/alert.text.erb +5 -0
  31. data/lib/flapjack/gateways/aws_sns/rollup.text.erb +2 -0
  32. data/lib/flapjack/gateways/jabber.rb +2 -2
  33. data/lib/flapjack/gateways/jsonapi/check_methods.rb +1 -1
  34. data/lib/flapjack/gateways/jsonapi/contact_methods.rb +1 -1
  35. data/lib/flapjack/gateways/jsonapi/entity_methods.rb +15 -1
  36. data/lib/flapjack/gateways/jsonapi/metrics_methods.rb +4 -3
  37. data/lib/flapjack/gateways/jsonapi/report_methods.rb +1 -1
  38. data/lib/flapjack/gateways/web.rb +35 -16
  39. data/lib/flapjack/gateways/web/public/css/tablesort.css +0 -16
  40. data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +1 -1
  41. data/lib/flapjack/gateways/web/public/js/jquery.tablesorter.widgets.js +0 -45
  42. data/lib/flapjack/gateways/web/public/js/modules/contact.js +2 -2
  43. data/lib/flapjack/gateways/web/public/js/modules/entity.js +2 -2
  44. data/lib/flapjack/gateways/web/public/js/modules/medium.js +4 -4
  45. data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -1
  46. data/lib/flapjack/gateways/web/views/check.html.erb +10 -10
  47. data/lib/flapjack/gateways/web/views/checks.html.erb +1 -1
  48. data/lib/flapjack/gateways/web/views/contact.html.erb +5 -1
  49. data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +3 -4
  50. data/lib/flapjack/gateways/web/views/entities.html.erb +1 -1
  51. data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
  52. data/lib/flapjack/gateways/web/views/layout.erb +3 -3
  53. data/lib/flapjack/gateways/web/views/self_stats.html.erb +5 -6
  54. data/lib/flapjack/notifier.rb +4 -1
  55. data/lib/flapjack/patches.rb +8 -2
  56. data/lib/flapjack/pikelet.rb +3 -1
  57. data/lib/flapjack/version.rb +1 -1
  58. data/libexec/httpbroker.go +1 -1
  59. data/spec/lib/flapjack/coordinator_spec.rb +3 -3
  60. data/spec/lib/flapjack/data/contact_spec.rb +2 -2
  61. data/spec/lib/flapjack/data/entity_check_spec.rb +805 -53
  62. data/spec/lib/flapjack/data/entity_spec.rb +661 -0
  63. data/spec/lib/flapjack/gateways/aws_sns_spec.rb +123 -0
  64. data/spec/lib/flapjack/gateways/jabber_spec.rb +1 -1
  65. data/spec/lib/flapjack/gateways/jsonapi/check_methods_spec.rb +1 -1
  66. data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +2 -2
  67. data/spec/lib/flapjack/gateways/pagerduty_spec.rb +1 -1
  68. data/spec/lib/flapjack/gateways/web_spec.rb +11 -11
  69. data/spec/support/profile_all_formatter.rb +10 -10
  70. data/spec/support/uncolored_doc_formatter.rb +66 -4
  71. data/src/flapjack/event.go +1 -1
  72. data/tasks/benchmarks.rake +24 -20
  73. data/tasks/entities.rake +148 -0
  74. data/tmp/dummy_contacts.json +43 -0
  75. data/tmp/dummy_entities.json +37 -1
  76. metadata +43 -7
  77. data/tmp/test_entities.json +0 -1
data/features/cli.feature CHANGED
@@ -8,8 +8,8 @@ Feature: command line utility
8
8
  Given a file named "flapjack_cfg.yaml" with:
9
9
  """
10
10
  test:
11
- pid_file: tmp/cucumber_cli/flapjack_d.pid
12
- log_file: tmp/cucumber_cli/flapjack_d.log
11
+ pid_dir: tmp/cucumber_cli/
12
+ log_dir: tmp/cucumber_cli/
13
13
  redis:
14
14
  db: 14
15
15
  processor:
@@ -20,8 +20,8 @@ test:
20
20
  And a file named "flapjack_cfg_d.yaml" with:
21
21
  """
22
22
  test:
23
- pid_file: tmp/cucumber_cli/flapjack_d.pid
24
- log_file: tmp/cucumber_cli/flapjack_d.log
23
+ pid_dir: tmp/cucumber_cli/
24
+ log_dir: tmp/cucumber_cli/
25
25
  redis:
26
26
  db: 14
27
27
  processor:
@@ -53,7 +53,7 @@ test:
53
53
  Then flapjack should stop within 15 seconds
54
54
 
55
55
  Scenario: Starting, status and stopping flapjack, daemonized
56
- When I start flapjack (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack_cfg_d.yaml server start -d`
56
+ When I start flapjack (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack_cfg_d.yaml server start`
57
57
  Then flapjack should start within 15 seconds
58
58
  When I run `bundle exec bin/flapjack -n test --config tmp/cucumber_cli/flapjack_cfg_d.yaml server status`
59
59
  Then the exit status should be 0
@@ -62,7 +62,7 @@ test:
62
62
  Then flapjack should stop within 15 seconds
63
63
 
64
64
  Scenario: Starting, restarting and stopping flapjack, daemonized
65
- When I start flapjack (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack_cfg_d.yaml server start -d`
65
+ When I start flapjack (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack_cfg_d.yaml server start`
66
66
  Then flapjack should start within 15 seconds
67
67
  When I restart flapjack (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack_cfg_d.yaml server restart`
68
68
  Then flapjack should restart within 15 seconds
@@ -76,6 +76,8 @@ test:
76
76
  Given a file named "flapjack_cfg.yaml" with:
77
77
  """
78
78
  test:
79
+ pid_dir: tmp/cucumber_cli/
80
+ log_dir: tmp/cucumber_cli/
79
81
  redis:
80
82
  db: 14
81
83
  processor:
@@ -85,5 +87,3 @@ test:
85
87
  # TODO how to test for config file change?
86
88
  When I stop flapjack (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack_cfg_d.yaml server stop`
87
89
  Then flapjack should stop within 15 seconds
88
-
89
-
@@ -1,28 +1,22 @@
1
1
  @process
2
- Feature: flapjack-nagios-receiver command line
2
+ Feature: nagios-receiver command line
3
3
  As a systems administrator
4
- I should be able to manage flapjack-nagios-receiver
4
+ I should be able to manage nagios-receiver
5
5
  From the command line
6
6
 
7
7
  Background:
8
8
  Given a fifo named "tmp/cucumber_cli/nagios_perfdata.fifo" exists
9
- And a file named "flapjack-nagios-receiver.yaml" with:
9
+ And a file named "nagios-receiver.yaml" with:
10
10
  """
11
11
  test:
12
+ pid_dir: "tmp/cucumber_cli/"
13
+ log_dir: "tmp/cucumber_cli/"
12
14
  redis:
13
15
  db: 14
14
16
  nagios-receiver:
15
17
  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"
18
+ pid_dir: "tmp/cucumber_cli/"
19
+ log_dir: "tmp/cucumber_cli/"
26
20
  """
27
21
 
28
22
  Scenario: Running with --help shows usage information
@@ -31,36 +25,34 @@ test:
31
25
  And the output should contain "[-f arg|--fifo arg]"
32
26
  And the output should contain "receiver nagios start [-d|--daemonize]"
33
27
 
34
- Scenario: Starting flapjack-nagios-receiver
35
- When I start flapjack-nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver.yaml receiver start --no-daemonize`
36
- Then flapjack-nagios-receiver should start within 15 seconds
28
+ Scenario: Starting nagios-receiver
29
+ When I start nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/nagios-receiver.yaml receiver start --no-daemonize`
30
+ Then nagios-receiver should start within 15 seconds
37
31
 
38
- Scenario: Stopping flapjack-nagios-receiver via SIGINT
39
- When I start flapjack-nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver.yaml receiver nagios start --no-daemonize`
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
32
+ Scenario: Stopping nagios-receiver via SIGINT
33
+ When I start nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/nagios-receiver.yaml receiver nagios start --no-daemonize`
34
+ Then nagios-receiver should start within 15 seconds
35
+ When I send a SIGINT to the nagios-receiver process
36
+ Then nagios-receiver should stop within 15 seconds
43
37
 
44
- Scenario: Starting, status, and stopping flapjack-nagios-receiver, daemonized
45
- When I start flapjack-nagios-receiver (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios start -d`
46
- Then flapjack-nagios-receiver should start within 15 seconds
47
- When I run `bundle exec bin/flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios status`
38
+ Scenario: Starting, status, and stopping nagios-receiver, daemonized
39
+ When I start nagios-receiver (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/nagios-receiver.yaml receiver nagios start -d`
40
+ Then nagios-receiver should start within 15 seconds
41
+ When I run `bundle exec bin/flapjack -n test --config tmp/cucumber_cli/nagios-receiver.yaml receiver nagios status`
48
42
  Then the exit status should be 0
49
43
  And the output should contain "nagios-receiver is running"
50
- When I stop flapjack-nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios stop`
51
- Then flapjack-nagios-receiver should stop within 15 seconds
44
+ When I stop nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/nagios-receiver.yaml receiver nagios stop`
45
+ Then nagios-receiver should stop within 15 seconds
52
46
 
53
- Scenario: Starting, restarting and stopping flapjack-nagios-receiver, daemonized
54
- When I start flapjack-nagios-receiver (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios start -d`
55
- Then flapjack-nagios-receiver should start within 15 seconds
56
- When I restart flapjack-nagios-receiver (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios restart`
57
- Then flapjack-nagios-receiver should restart within 15 seconds
58
- When I stop flapjack-nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios stop`
59
- Then flapjack-nagios-receiver should stop within 15 seconds
47
+ Scenario: Starting, restarting and stopping nagios-receiver, daemonized
48
+ When I start nagios-receiver (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/nagios-receiver.yaml receiver nagios start -d`
49
+ Then nagios-receiver should start within 15 seconds
50
+ When I restart nagios-receiver (daemonised) (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/nagios-receiver.yaml receiver nagios restart`
51
+ Then nagios-receiver should restart within 15 seconds
52
+ When I stop nagios-receiver (via bundle exec) with `flapjack -n test --config tmp/cucumber_cli/nagios-receiver.yaml receiver nagios stop`
53
+ Then nagios-receiver should stop within 15 seconds
60
54
 
61
55
  Scenario: Getting status when stopped
62
- When I run `bundle exec bin/flapjack -n test --config tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml receiver nagios status`
56
+ When I run `bundle exec bin/flapjack -n test --config tmp/cucumber_cli/nagios-receiver.yaml receiver nagios status`
63
57
  Then the exit status should not be 0
64
58
  And the output should contain "nagios-receiver is not running"
65
-
66
-
@@ -4,42 +4,54 @@ Feature: Flapper command line
4
4
  I should be able to manage flapper
5
5
  From the command line
6
6
 
7
+ Background:
8
+ Given a file named "flapjack_cfg.yaml" with:
9
+ """
10
+ test:
11
+ pid_dir: tmp/cucumber_cli/
12
+ log_dir: tmp/cucumber_cli/
13
+ redis:
14
+ db: 14
15
+ processor:
16
+ enabled: yes
17
+ logger:
18
+ level: warn
19
+ """
20
+
7
21
  Scenario: Running with --help shows usage information
8
- When I run `bundle exec bin/flapjack flapper --help`
22
+ When I run `bundle exec bin/flapjack --config tmp/cucumber_cli/flapjack_cfg.yaml flapper --help`
9
23
  Then the exit status should be 0
10
24
  And the output should contain "Artificial service that oscillates up and down"
11
25
  And the output should contain "[-b arg|--bind-ip arg]"
12
26
 
13
27
  Scenario: Starting flapper
14
- When I start flapper (via bundle exec) with `flapjack flapper start --no-daemonize`
28
+ When I start flapper (via bundle exec) with `flapjack --config tmp/cucumber_cli/flapjack_cfg.yaml flapper start --no-daemonize`
15
29
  Then flapper should start within 15 seconds
16
30
 
17
31
  Scenario: Stopping flapper via SIGINT
18
- When I start flapper (via bundle exec) with `flapjack flapper start --no-daemonize`
32
+ When I start flapper (via bundle exec) with `flapjack --config tmp/cucumber_cli/flapjack_cfg.yaml flapper start --no-daemonize`
19
33
  Then flapper should start within 15 seconds
20
34
  When I send a SIGINT to the flapper process
21
35
  Then flapper should stop within 15 seconds
22
36
 
23
37
  Scenario: Starting, status, and stopping flapper, daemonized
24
- When I start flapper (daemonised) (via bundle exec) with `flapjack flapper start -d -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
38
+ When I start flapper (daemonised) (via bundle exec) with `flapjack --config tmp/cucumber_cli/flapjack_cfg.yaml flapper start -d -p tmp/cucumber_cli/flapper.pid -l tmp/cucumber_cli/flapper.log`
25
39
  Then flapper should start within 15 seconds
26
- When I run `bundle exec bin/flapjack flapper status -p tmp/cucumber_cli/flapper_d.pid`
40
+ When I run `bundle exec bin/flapjack --config tmp/cucumber_cli/flapjack_cfg.yaml flapper status -p tmp/cucumber_cli/flapper.pid`
27
41
  Then the exit status should be 0
28
42
  And the output should contain "flapper is running"
29
- When I stop flapper (via bundle exec) with `flapjack flapper stop -p tmp/cucumber_cli/flapper_d.pid`
43
+ When I stop flapper (via bundle exec) with `flapjack --config tmp/cucumber_cli/flapjack_cfg.yaml flapper stop -p tmp/cucumber_cli/flapper.pid`
30
44
  Then flapper should stop within 15 seconds
31
45
 
32
46
  Scenario: Starting, restarting and stopping flapper, daemonized
33
- When I start flapper (daemonised) (via bundle exec) with `flapjack flapper start -d -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
47
+ When I start flapper (daemonised) (via bundle exec) with `flapjack --config tmp/cucumber_cli/flapjack_cfg.yaml flapper start -d -p tmp/cucumber_cli/flapper.pid -l tmp/cucumber_cli/flapper.log`
34
48
  Then flapper should start within 15 seconds
35
- When I restart flapper (daemonised) (via bundle exec) with `flapjack flapper restart -p tmp/cucumber_cli/flapper_d.pid -l tmp/cucumber_cli/flapper_d.log`
49
+ When I restart flapper (daemonised) (via bundle exec) with `flapjack --config tmp/cucumber_cli/flapjack_cfg.yaml flapper restart -p tmp/cucumber_cli/flapper.pid -l tmp/cucumber_cli/flapper.log`
36
50
  Then flapper should restart within 15 seconds
37
- When I stop flapper (via bundle exec) with `flapjack flapper stop -p tmp/cucumber_cli/flapper_d.pid`
51
+ When I stop flapper (via bundle exec) with `flapjack --config tmp/cucumber_cli/flapjack_cfg.yaml flapper stop -p tmp/cucumber_cli/flapper.pid`
38
52
  Then flapper should stop within 15 seconds
39
53
 
40
54
  Scenario: Getting status when stopped
41
- When I run `bundle exec bin/flapjack flapper status -p tmp/cucumber_cli/flapper_d.pid`
55
+ When I run `bundle exec bin/flapjack --config tmp/cucumber_cli/flapjack_cfg.yaml flapper status -p tmp/cucumber_cli/flapper.pid`
42
56
  Then the exit status should not be 0
43
57
  And the output should contain "flapper is not running"
44
-
45
-
@@ -16,13 +16,13 @@ test:
16
16
  Scenario: Running with --help shows usage information
17
17
  When I run `bundle exec bin/flapjack simulate --help`
18
18
  Then the exit status should be 0
19
- And the output should contain "Generate streams of events in various states"
19
+ And the output should contain "Simulates a check by creating a stream of events for Flapjack"
20
20
  And the output should contain "-k arg|--check arg"
21
21
 
22
22
  Scenario: Running simulate-failed-check with no arguments exits uncleanly and shows usage
23
23
  When I run `bundle exec bin/flapjack simulate`
24
24
  Then the exit status should not be 0
25
- And the output should contain "Generate streams of events in various states"
25
+ And the output should contain "Simulates a check by creating a stream of events for Flapjack"
26
26
 
27
27
  Scenario: Simulate a failed check
28
28
  When I run `bundle exec bin/flapjack -n test -c tmp/cucumber_cli/simulate-failed-check.yaml simulate fail -t 0 -i 0.1 -e 'test' -k 'PING'`
@@ -12,6 +12,13 @@ Feature: notifications
12
12
  Then an SMS notification for entity 'example.com' should be queued for the user
13
13
  And an email notification for entity 'example.com' should not be queued for the user
14
14
 
15
+ @resque
16
+ Scenario: Queue an SNS notification
17
+ Given the user wants to receive SNS notifications for entity 'example.com'
18
+ When an event notification is generated for entity 'example.com'
19
+ Then an SNS notification for entity 'example.com' should be queued for the user
20
+ And an email notification for entity 'example.com' should not be queued for the user
21
+
15
22
  @resque
16
23
  Scenario: Queue an email notification
17
24
  Given the user wants to receive email notifications for entity 'example.com'
@@ -39,11 +46,21 @@ Feature: notifications
39
46
  When the SMS notification handler runs successfully
40
47
  Then the user should receive an SMS notification
41
48
 
49
+ Scenario: Send a queued SNS notification
50
+ Given a user SNS notification has been queued for entity 'example.com'
51
+ When the SNS notification handler runs successfully
52
+ Then the user should receive an SNS notification
53
+
42
54
  Scenario: Handle a failure to send a queued SMS notification
43
55
  Given a user SMS notification has been queued for entity 'example.com'
44
56
  When the SMS notification handler fails to send an SMS
45
57
  Then the user should not receive an SMS notification
46
58
 
59
+ Scenario: Handle a failure to send a queued SNS notification
60
+ Given a user SNS notification has been queued for entity 'example.com'
61
+ When the SNS notification handler fails to send an SMS
62
+ Then the user should not receive an SNS notification
63
+
47
64
  Scenario: Send a queued email notification
48
65
  Given a user email notification has been queued for entity 'example.com'
49
66
  When the email notification handler runs successfully
@@ -52,4 +69,4 @@ Feature: notifications
52
69
  Scenario: Handle a failure to send a queued email notification
53
70
  Given a user email notification has been queued for entity 'example.com'
54
71
  When the email notification handler fails to send an email
55
- Then the user should not receive an email notification
72
+ Then the user should not receive an email notification
@@ -24,7 +24,7 @@ When /^I ((?:re)?start|stop) (\S+)( \(daemonised\))?( \(via bundle exec\))? with
24
24
  case start_stop_restart
25
25
  when 'start'
26
26
  @process_h = spawn_process(command,
27
- :daemon_pidfile => (daemonise.nil? || daemonise.empty?) ? nil : "tmp/cucumber_cli/#{exe}_d.pid")
27
+ :daemon_pidfile => (daemonise.nil? || daemonise.empty?) ? nil : "tmp/cucumber_cli/#{exe}.pid")
28
28
  when 'stop', 'restart'
29
29
  @daemons_output << `#{command}`
30
30
  @daemons_exit_status << $?
@@ -88,7 +88,7 @@ Then /^(\S+) should ((?:re)?start|stop) within (\d+) seconds$/ do |exe, start_st
88
88
  when 'restart'
89
89
  read_pid = nil
90
90
  while attempts < max_attempts
91
- time_and_pid = time_and_pid_from_file("tmp/cucumber_cli/#{exe}_d.pid")
91
+ time_and_pid = time_and_pid_from_file("tmp/cucumber_cli/#{exe}.pid")
92
92
  read_pid = time_and_pid.last
93
93
  break if read_pid != pid
94
94
  attempts += 1; sleep 0.1
@@ -26,6 +26,18 @@ Given /^the user wants to receive SMS notifications for entity '([\w\.\-]+)'$/ d
26
26
  :redis => @redis )
27
27
  end
28
28
 
29
+ Given /^the user wants to receive SNS notifications for entity '([\w\.\-]+)'$/ do |entity|
30
+ add_contact( 'id' => '0999',
31
+ 'first_name' => 'John',
32
+ 'last_name' => 'Smith',
33
+ 'email' => 'johns@example.dom',
34
+ 'media' => {'sns' => 'arn:aws:sns:us-east-1:698519295917:My-Topic'} )
35
+ Flapjack::Data::Entity.add({'id' => '5000',
36
+ 'name' => entity,
37
+ 'contacts' => ["0999"]},
38
+ :redis => @redis )
39
+ end
40
+
29
41
  Given /^the user wants to receive email notifications for entity '([\w\.\-]+)'$/ do |entity|
30
42
  add_contact( 'id' => '0999',
31
43
  'first_name' => 'John',
@@ -87,6 +99,11 @@ Then /^an SMS notification for entity '([\w\.\-]+)' should be queued for the use
87
99
  expect(queue.select {|n| n[:args].first['event_id'] =~ /#{entity}:ping/ }).not_to be_empty
88
100
  end
89
101
 
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
105
+ end
106
+
90
107
  Then /^an email notification for entity '([\w\.\-]+)' should be queued for the user$/ do |entity|
91
108
  queue = ResqueSpec.peek('email_notifications')
92
109
  expect(queue.select {|n| n[:args].first['event_id'] =~ /#{entity}:ping/ }).not_to be_empty
@@ -119,6 +136,23 @@ Given /^a user SMS notification has been queued for entity '([\w\.\-]+)'$/ do |e
119
136
  'duration' => 45}
120
137
  end
121
138
 
139
+ Given /^a user SNS notification has been queued for entity '([\w\.\-]+)'$/ do |entity|
140
+ Flapjack::Data::Entity.add({'id' => '5000',
141
+ 'name' => entity},
142
+ :redis => @redis )
143
+ @sms_notification = {'notification_type' => 'problem',
144
+ 'contact_first_name' => 'John',
145
+ 'contact_last_name' => 'Smith',
146
+ 'state' => 'critical',
147
+ 'summary' => 'Socket timeout after 10 seconds',
148
+ 'time' => Time.now.to_i,
149
+ 'event_id' => "#{entity}:ping",
150
+ 'address' => 'arn:aws:sns:us-east-1:698519295917:My-Topic',
151
+ 'id' => 1,
152
+ 'state_duration' => 30,
153
+ 'duration' => 45}
154
+ end
155
+
122
156
  Given /^a user email notification has been queued for entity '([\w\.\-]+)'$/ do |entity|
123
157
  Flapjack::Data::Entity.add({'id' => '5001',
124
158
  'name' => entity},
@@ -150,6 +184,20 @@ When /^the SMS notification handler runs successfully$/ do
150
184
  Flapjack::Gateways::SmsMessagenet.perform(@sms_notification)
151
185
  end
152
186
 
187
+ When /^the SNS notification handler runs successfully$/ do
188
+ @request = stub_request(:post, /amazonaws\.com/)
189
+
190
+ Flapjack::Gateways::AwsSns.instance_variable_set('@config', {
191
+ 'access_key' => "AKIAIOSFODNN7EXAMPLE",
192
+ '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
197
+
198
+ Flapjack::Gateways::AwsSns.perform(@sms_notification)
199
+ end
200
+
153
201
  When /^the SMS notification handler fails to send an SMS$/ do
154
202
  @request = stub_request(:get, /^#{Regexp.escape(Flapjack::Gateways::SmsMessagenet::MESSAGENET_DEFAULT_URL)}/).to_return(:status => [500, "Internal Server Error"])
155
203
  Flapjack::Gateways::SmsMessagenet.instance_variable_set('@config', {'username' => 'abcd', 'password' => 'efgh'})
@@ -160,6 +208,19 @@ When /^the SMS notification handler fails to send an SMS$/ do
160
208
  Flapjack::Gateways::SmsMessagenet.perform(@sms_notification)
161
209
  end
162
210
 
211
+ When /^the SNS notification handler fails to send an SMS$/ do
212
+ @request = stub_request(:post, /amazonaws\.com/).to_return(:status => [500, "Internal Server Error"])
213
+ Flapjack::Gateways::AwsSns.instance_variable_set('@config', {
214
+ 'access_key' => "AKIAIOSFODNN7EXAMPLE",
215
+ '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
220
+
221
+ Flapjack::Gateways::AwsSns.perform(@sms_notification)
222
+ end
223
+
163
224
  When /^the email notification handler runs successfully$/ do
164
225
  Resque.redis = @redis
165
226
  Flapjack::Gateways::Email.instance_variable_set('@config', {'smtp_config' => {'host' => '127.0.0.1', 'port' => 2525}})
@@ -203,6 +264,11 @@ Then /^the user should receive an SMS notification$/ do
203
264
  expect(Flapjack::Gateways::SmsMessagenet.instance_variable_get('@sent')).to eq(1)
204
265
  end
205
266
 
267
+ Then /^the user should receive an SNS notification$/ do
268
+ expect(@request).to have_been_requested
269
+ expect(Flapjack::Gateways::AwsSns.instance_variable_get('@sent')).to eq(1)
270
+ end
271
+
206
272
  Then /^the user should receive an email notification$/ do
207
273
  expect(Flapjack::Gateways::Email.instance_variable_get('@sent')).to eq(1)
208
274
  end
@@ -212,6 +278,11 @@ Then /^the user should not receive an SMS notification$/ do
212
278
  expect(Flapjack::Gateways::SmsMessagenet.instance_variable_get('@sent')).to eq(0)
213
279
  end
214
280
 
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)
284
+ end
285
+
215
286
  Then /^the user should not receive an email notification$/ do
216
287
  expect(Flapjack::Gateways::Email.instance_variable_get('@sent')).to eq(0)
217
288
  end
@@ -162,6 +162,7 @@ Before('@notifier') do
162
162
  :redis_config => redis_opts,
163
163
  :config => {'email_queue' => 'email_notifications',
164
164
  'sms_queue' => 'sms_notifications',
165
+ 'sns_queue' => 'sns_notifications',
165
166
  'default_contact_timezone' => 'America/New_York'})
166
167
  @notifier_redis = @notifier.instance_variable_get('@redis')
167
168
  end
@@ -188,15 +189,15 @@ After('@process') do
188
189
  ['tmp/cucumber_cli/flapjack_cfg.yaml',
189
190
  'tmp/cucumber_cli/flapjack_cfg.yaml.bak',
190
191
  'tmp/cucumber_cli/flapjack_cfg_d.yaml',
191
- 'tmp/cucumber_cli/flapjack_d.log',
192
- 'tmp/cucumber_cli/flapjack_d.pid',
192
+ 'tmp/cucumber_cli/flapjack.log',
193
+ 'tmp/cucumber_cli/flapjack.pid',
193
194
  'tmp/cucumber_cli/nagios_perfdata.fifo',
194
- 'tmp/cucumber_cli/flapjack-nagios-receiver_d.pid',
195
- 'tmp/cucumber_cli/flapjack-nagios-receiver_d.log',
195
+ 'tmp/cucumber_cli/flapjack-nagios-receiver.pid',
196
+ 'tmp/cucumber_cli/flapjack-nagios-receiver.log',
196
197
  'tmp/cucumber_cli/flapjack-nagios-receiver_d.yaml',
197
198
  'tmp/cucumber_cli/flapjack-nagios-receiver.yaml',
198
- 'tmp/cucumber_cli/flapper_d.pid',
199
- 'tmp/cucumber_cli/flapper_d.log',
199
+ 'tmp/cucumber_cli/flapper.pid',
200
+ 'tmp/cucumber_cli/flapper.log',
200
201
  'tmp/cucumber_cli/flapjack-populator.yaml',
201
202
  'tmp/cucumber_cli/flapjack-populator-contacts.json',
202
203
  'tmp/cucumber_cli/flapjack-populator-entities.json',
data/flapjack.gemspec CHANGED
@@ -34,11 +34,13 @@ Gem::Specification.new do |gem|
34
34
  gem.add_dependency 'blather', '~> 0.8.3'
35
35
  gem.add_dependency 'chronic'
36
36
  gem.add_dependency 'chronic_duration'
37
+ gem.add_dependency 'terminal-table'
37
38
  gem.add_dependency 'activesupport', '~> 3.2.14'
38
39
  gem.add_dependency 'ice_cube'
39
40
  gem.add_dependency 'tzinfo', '~> 1.0.1'
40
41
  gem.add_dependency 'tzinfo-data'
41
42
  gem.add_dependency 'rbtrace'
42
43
  gem.add_dependency 'rake'
43
- gem.add_dependency 'gli'
44
+ gem.add_dependency 'gli', '= 2.12.0'
45
+ gem.add_dependency 'nokogiri', '= 1.6.2.1'
44
46
  end