flapjack 0.5.5 → 0.6.23

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 (167) hide show
  1. data/.gitignore +10 -0
  2. data/.rbenv-version +1 -0
  3. data/.rspec +10 -0
  4. data/Gemfile +18 -0
  5. data/Guardfile +14 -0
  6. data/README.md +152 -173
  7. data/Rakefile +53 -150
  8. data/bin/flapjack +72 -0
  9. data/bin/flapjack-nagios-receiver +111 -0
  10. data/bin/flapjack-nagios-receiver-control +15 -0
  11. data/bin/flapjack-netsaint-parser +0 -2
  12. data/bin/flapjack-populator +133 -16
  13. data/bin/install-flapjack-systemwide +2 -2
  14. data/config.ru +11 -0
  15. data/dist/etc/init.d/flapjack +46 -0
  16. data/dist/etc/init.d/flapjack-nagios-receiver +36 -0
  17. data/doc/GLOSSARY.md +19 -0
  18. data/etc/flapjack_config.yaml.example +90 -0
  19. data/features/events.feature +132 -0
  20. data/features/notifications.feature +57 -0
  21. data/features/packaging-lintian.feature +5 -3
  22. data/features/steps/events_steps.rb +164 -0
  23. data/features/steps/flapjack-importer_steps.rb +2 -5
  24. data/features/steps/flapjack-worker_steps.rb +13 -6
  25. data/features/steps/notifications_steps.rb +178 -0
  26. data/features/steps/packaging-lintian_steps.rb +14 -0
  27. data/features/steps/time_travel_steps.rb +34 -0
  28. data/features/support/env.rb +63 -36
  29. data/flapjack.gemspec +35 -186
  30. data/lib/flapjack.rb +2 -0
  31. data/lib/flapjack/api.rb +274 -0
  32. data/lib/flapjack/api/entity_check_presenter.rb +184 -0
  33. data/lib/flapjack/api/entity_presenter.rb +66 -0
  34. data/lib/flapjack/cli/worker_manager.rb +1 -2
  35. data/lib/flapjack/configuration.rb +11 -0
  36. data/lib/flapjack/coordinator.rb +288 -0
  37. data/lib/flapjack/daemonizing.rb +186 -0
  38. data/lib/flapjack/data/contact.rb +45 -0
  39. data/lib/flapjack/data/entity.rb +89 -0
  40. data/lib/flapjack/data/entity_check.rb +396 -0
  41. data/lib/flapjack/data/event.rb +144 -0
  42. data/lib/flapjack/data/notification.rb +13 -0
  43. data/lib/flapjack/executive.rb +289 -0
  44. data/lib/flapjack/filters/acknowledgement.rb +39 -0
  45. data/lib/flapjack/filters/{any_parents_failed.rb → base.rb} +6 -4
  46. data/lib/flapjack/filters/delays.rb +53 -0
  47. data/lib/flapjack/filters/detect_mass_client_failures.rb +44 -0
  48. data/lib/flapjack/filters/ok.rb +25 -5
  49. data/lib/flapjack/filters/scheduled_maintenance.rb +17 -0
  50. data/lib/flapjack/filters/unscheduled_maintenance.rb +17 -0
  51. data/lib/flapjack/jabber.rb +294 -0
  52. data/lib/flapjack/notification/common.rb +23 -0
  53. data/lib/flapjack/notification/email.rb +107 -0
  54. data/lib/flapjack/notification/email/alert.html.haml +48 -0
  55. data/lib/flapjack/notification/email/alert.text.erb +14 -0
  56. data/lib/flapjack/notification/sms.rb +42 -0
  57. data/lib/flapjack/notification/sms/messagenet.rb +49 -0
  58. data/lib/flapjack/notifier_engine.rb +4 -4
  59. data/lib/flapjack/notifiers/mailer/mailer.rb +6 -7
  60. data/lib/flapjack/notifiers/xmpp/xmpp.rb +12 -12
  61. data/lib/flapjack/pagerduty.rb +230 -0
  62. data/lib/flapjack/patches.rb +108 -19
  63. data/lib/flapjack/persistence/data_mapper/models/check.rb +5 -3
  64. data/lib/flapjack/persistence/data_mapper/models/check_template.rb +2 -0
  65. data/lib/flapjack/persistence/data_mapper/models/event.rb +2 -0
  66. data/lib/flapjack/persistence/data_mapper/models/node.rb +3 -1
  67. data/lib/flapjack/persistence/data_mapper/models/related_check.rb +3 -1
  68. data/lib/flapjack/pikelet.rb +56 -0
  69. data/lib/flapjack/transports/beanstalkd.rb +1 -1
  70. data/lib/flapjack/transports/result.rb +6 -6
  71. data/lib/flapjack/utility.rb +46 -0
  72. data/lib/flapjack/version.rb +5 -0
  73. data/lib/flapjack/web.rb +198 -0
  74. data/lib/flapjack/web/views/acknowledge.haml +55 -0
  75. data/lib/flapjack/web/views/check.haml +162 -0
  76. data/lib/flapjack/web/views/index.haml +92 -0
  77. data/lib/flapjack/web/views/self_stats.haml +56 -0
  78. data/lib/flapjack/{applications/worker.rb → worker/application.rb} +0 -0
  79. data/lib/flapjack/worker/cli.rb +49 -0
  80. data/{spec → spec.old}/check_sandbox/echo +0 -0
  81. data/{spec → spec.old}/check_sandbox/sandboxed_check +0 -0
  82. data/{spec → spec.old}/configs/flapjack-notifier-couchdb.ini +0 -0
  83. data/{spec → spec.old}/configs/flapjack-notifier.ini +0 -0
  84. data/{spec → spec.old}/configs/recipients.ini +0 -0
  85. data/{spec → spec.old}/helpers.rb +0 -0
  86. data/{spec → spec.old}/inifile_spec.rb +0 -0
  87. data/{spec → spec.old}/mock-notifiers/mock/init.rb +0 -0
  88. data/{spec → spec.old}/mock-notifiers/mock/mock.rb +0 -0
  89. data/{spec → spec.old}/notifier-directories/spoons/testmailer/init.rb +0 -0
  90. data/{spec → spec.old}/notifier_application_spec.rb +0 -0
  91. data/{spec → spec.old}/notifier_filters_spec.rb +0 -0
  92. data/{spec → spec.old}/notifier_options_multiplexer_spec.rb +0 -0
  93. data/{spec → spec.old}/notifier_options_spec.rb +0 -0
  94. data/{spec → spec.old}/notifier_spec.rb +0 -0
  95. data/{spec → spec.old}/notifiers/mailer_spec.rb +0 -0
  96. data/{spec → spec.old}/notifiers/xmpp_spec.rb +0 -0
  97. data/{spec → spec.old}/persistence/datamapper_spec.rb +0 -0
  98. data/{spec → spec.old}/persistence/mock_persistence_backend.rb +0 -0
  99. data/{spec → spec.old}/simple.ini +0 -0
  100. data/{spec → spec.old}/spec.opts +0 -0
  101. data/{spec → spec.old}/test-filters/blocker.rb +0 -0
  102. data/{spec → spec.old}/test-filters/mock.rb +0 -0
  103. data/{spec → spec.old}/transports/beanstalkd_spec.rb +0 -0
  104. data/{spec → spec.old}/transports/mock_transport.rb +0 -0
  105. data/{spec → spec.old}/worker_application_spec.rb +0 -0
  106. data/{spec → spec.old}/worker_options_spec.rb +0 -0
  107. data/spec/lib/flapjack/api/entity_check_presenter_spec.rb +117 -0
  108. data/spec/lib/flapjack/api/entity_presenter_spec.rb +92 -0
  109. data/spec/lib/flapjack/api_spec.rb +170 -0
  110. data/spec/lib/flapjack/coordinator_spec.rb +16 -0
  111. data/spec/lib/flapjack/data/entity_check_spec.rb +398 -0
  112. data/spec/lib/flapjack/data/entity_spec.rb +71 -0
  113. data/spec/lib/flapjack/data/event_spec.rb +6 -0
  114. data/spec/lib/flapjack/executive_spec.rb +59 -0
  115. data/spec/lib/flapjack/filters/acknowledgement_spec.rb +6 -0
  116. data/spec/lib/flapjack/filters/delays_spec.rb +6 -0
  117. data/spec/lib/flapjack/filters/detect_mass_client_failures_spec.rb +6 -0
  118. data/spec/lib/flapjack/filters/ok_spec.rb +6 -0
  119. data/spec/lib/flapjack/filters/scheduled_maintenance_spec.rb +6 -0
  120. data/spec/lib/flapjack/filters/unscheduled_maintenance_spec.rb +6 -0
  121. data/spec/lib/flapjack/jabber_spec.rb +150 -0
  122. data/spec/lib/flapjack/notification/email_spec.rb +6 -0
  123. data/spec/lib/flapjack/notification/sms_spec.rb +6 -0
  124. data/spec/lib/flapjack/pikelet_spec.rb +28 -0
  125. data/spec/lib/flapjack/web_spec.rb +188 -0
  126. data/spec/spec_helper.rb +44 -0
  127. data/spec/support/profile_all_formatter.rb +44 -0
  128. data/spec/support/uncolored_doc_formatter.rb +9 -0
  129. data/tasks/events.rake +85 -0
  130. data/tmp/acknowledge.rb +14 -0
  131. data/tmp/create_config_yaml.rb +16 -0
  132. data/tmp/create_events_failure.rb +33 -0
  133. data/tmp/create_events_ok.rb +33 -0
  134. data/tmp/create_events_ok_fail_ack_ok.rb +54 -0
  135. data/tmp/create_events_ok_failure.rb +40 -0
  136. data/tmp/create_events_ok_failure_ack.rb +54 -0
  137. data/tmp/dummy_entities.json +1 -0
  138. data/tmp/generate_nagios_test_hosts.rb +16 -0
  139. data/tmp/parse_config_yaml.rb +7 -0
  140. data/tmp/redis_delete_all_keys.rb +11 -0
  141. data/tmp/test_entities.json +1 -0
  142. metadata +482 -221
  143. data/TODO.md +0 -36
  144. data/VERSION +0 -1
  145. data/bin/flapjack-benchmark +0 -50
  146. data/bin/flapjack-notifier +0 -21
  147. data/bin/flapjack-notifier-manager +0 -43
  148. data/bin/flapjack-stats +0 -27
  149. data/bin/flapjack-worker +0 -13
  150. data/bin/flapjack-worker-manager +0 -35
  151. data/dist/etc/init.d/flapjack-notifier +0 -47
  152. data/dist/etc/init.d/flapjack-workers +0 -44
  153. data/features/flapjack-notifier-manager.feature +0 -19
  154. data/features/flapjack-worker-manager.feature +0 -27
  155. data/features/flapjack-worker.feature +0 -27
  156. data/features/netsaint-config-converter.feature +0 -126
  157. data/features/persistence/couch.feature +0 -105
  158. data/features/persistence/sqlite3.feature +0 -105
  159. data/features/persistence/steps/couch_steps.rb +0 -25
  160. data/features/persistence/steps/generic_steps.rb +0 -102
  161. data/features/persistence/steps/sqlite3_steps.rb +0 -13
  162. data/features/steps/flapjack-notifier-manager_steps.rb +0 -24
  163. data/features/steps/flapjack-worker-manager_steps.rb +0 -48
  164. data/lib/flapjack/applications/notifier.rb +0 -222
  165. data/lib/flapjack/cli/notifier.rb +0 -108
  166. data/lib/flapjack/cli/notifier_manager.rb +0 -86
  167. data/lib/flapjack/cli/worker.rb +0 -51
@@ -1,105 +0,0 @@
1
- Feature: CouchDB persistence backend
2
- To use a CouchDB backend with Flapjack
3
- The backend must conform
4
- To the persistence API
5
-
6
- Background:
7
- Given I set up the Couch backend with the following options:
8
- | host | port | database |
9
- | localhost | 5984 | flapjack_test |
10
-
11
- Scenario: Create a check
12
- When I create the following checks:
13
- | name | id | command | status | enabled |
14
- | passing | 1 | exit 0 | 0 | true |
15
- | warning | 2 | exit 1 | 1 | true |
16
- | critical | 3 | exit 2 | 2 | true |
17
- Then looking up the following checks should return documents:
18
- | id |
19
- | 1 |
20
- | 2 |
21
- | 3 |
22
-
23
- Scenario: Update a check
24
- Given the following checks exist:
25
- | name | id | command | status | enabled |
26
- | passing | 4 | exit 0 | 0 | true |
27
- When I update the following checks:
28
- | name | id | command | status | enabled |
29
- | passing | 4 | exit 2 | 2 | true |
30
- Then the updates should succeed
31
-
32
- Scenario: Delete a check
33
- Given the following checks exist:
34
- | name | id | command | status | enabled |
35
- | passing | 5 | exit 0 | 0 | true |
36
- When I delete the check with id "4"
37
- Then the check with id "4" should not exist
38
-
39
- Scenario: List all checks
40
- Given the following checks exist:
41
- | name | id | command | status | enabled |
42
- | passing | 6 | exit 0 | 0 | true |
43
- | warning | 7 | exit 1 | 1 | true |
44
- | critical | 8 | exit 2 | 2 | true |
45
- When I get all checks
46
- Then I should have at least 3 checks
47
-
48
- Scenario: Query for failing parents
49
- Given the following checks exist:
50
- | name | id | command | status | enabled |
51
- | failing parent | 1 | exit 2 | 2 | true |
52
- | passing child | 2 | exit 0 | 0 | true |
53
- And the following related checks exist:
54
- | id | parent_id | child_id |
55
- | 1 | 1 | 2 |
56
- Then the following result should not have a failing parent:
57
- | check_id |
58
- | 1 |
59
- Then the following result should have a failing parent:
60
- | check_id |
61
- | 2 |
62
-
63
- Scenario: Saving events
64
- Given the following checks exist:
65
- | name | id | command | status | enabled |
66
- | failing parent | 4 | exit 2 | 4 | true |
67
- Then the following event should save:
68
- | check_id | status |
69
- | 4 | 2 |
70
- And the check with id "4" on the Sqlite3 backend should have an event created
71
-
72
- Scenario: List events for a check
73
- Given the following checks exist:
74
- | name | id | command | status | enabled |
75
- | passing child | 12 | exit 2 | 3 | true |
76
- Given the following events exist:
77
- | check_id |
78
- | 12 |
79
- | 12 |
80
- | 12 |
81
- When I get all events for check "12"
82
- Then I should have at least 3 events
83
-
84
- Scenario: List all events
85
- Given the following events exist:
86
- | check_id |
87
- | 9 |
88
- | 10 |
89
- | 11 |
90
- When I get all events
91
- Then I should have at least 3 events
92
-
93
- Scenario: List all check relationships
94
- Given the following checks exist:
95
- | name | id | command | status | enabled |
96
- | passing | 9 | exit 0 | 0 | true |
97
- | warning | 10 | exit 1 | 1 | true |
98
- | critical | 11 | exit 2 | 2 | true |
99
- And the following related checks exist:
100
- | parent_id | child_id |
101
- | 9 | 10 |
102
- | 10 | 11 |
103
- | 11 | 9 |
104
- When I get all check relationships
105
- Then I should have at least 3 check relationships
@@ -1,105 +0,0 @@
1
- Feature: SQLite3 persistence backend
2
- To use a SQLite3 backend with Flapjack
3
- The backend must conform
4
- To the persistence API
5
-
6
- Background:
7
- Given I set up the Sqlite3 backend with the following options:
8
- | database | auto_migrate |
9
- | :memory: | true |
10
-
11
- Scenario: Create a check
12
- When I create the following checks:
13
- | name | id | command | status | enabled |
14
- | passing | 1 | exit 0 | 0 | true |
15
- | warning | 2 | exit 1 | 1 | true |
16
- | critical | 3 | exit 2 | 2 | true |
17
- Then looking up the following checks should return documents:
18
- | id |
19
- | 1 |
20
- | 2 |
21
- | 3 |
22
-
23
- Scenario: Update a check
24
- Given the following checks exist:
25
- | name | id | command | status | enabled |
26
- | passing | 4 | exit 0 | 0 | true |
27
- When I update the following checks:
28
- | name | id | command | status | enabled |
29
- | passing | 4 | exit 2 | 2 | true |
30
- Then the updates should succeed
31
-
32
- Scenario: Delete a check
33
- Given the following checks exist:
34
- | name | id | command | status | enabled |
35
- | passing | 5 | exit 0 | 0 | true |
36
- When I delete the check with id "4"
37
- Then the check with id "4" should not exist
38
-
39
- Scenario: List all checks
40
- Given the following checks exist:
41
- | name | id | command | status | enabled |
42
- | passing | 6 | exit 0 | 0 | true |
43
- | warning | 7 | exit 1 | 1 | true |
44
- | critical | 8 | exit 2 | 2 | true |
45
- When I get all checks
46
- Then I should have at least 3 checks
47
-
48
- Scenario: Query for failing parents
49
- Given the following checks exist:
50
- | name | id | command | status | enabled |
51
- | failing parent | 1 | exit 2 | 2 | true |
52
- | passing child | 2 | exit 0 | 0 | true |
53
- And the following related checks exist:
54
- | id | parent_id | child_id |
55
- | 1 | 1 | 2 |
56
- Then the following result should not have a failing parent:
57
- | check_id |
58
- | 1 |
59
- Then the following result should have a failing parent:
60
- | check_id |
61
- | 2 |
62
-
63
- Scenario: Saving events
64
- Given the following checks exist:
65
- | name | id | command | status | enabled |
66
- | failing parent | 4 | exit 2 | 4 | true |
67
- Then the following event should save:
68
- | check_id | status |
69
- | 4 | 2 |
70
- And the check with id "4" on the Sqlite3 backend should have an event created
71
-
72
- Scenario: List events for a check
73
- Given the following checks exist:
74
- | name | id | command | status | enabled |
75
- | passing child | 12 | exit 2 | 3 | true |
76
- Given the following events exist:
77
- | check_id |
78
- | 12 |
79
- | 12 |
80
- | 12 |
81
- When I get all events for check "12"
82
- Then I should have at least 3 events
83
-
84
- Scenario: List all events
85
- Given the following events exist:
86
- | check_id |
87
- | 9 |
88
- | 10 |
89
- | 11 |
90
- When I get all events
91
- Then I should have at least 3 events
92
-
93
- Scenario: List all check relationships
94
- Given the following checks exist:
95
- | name | id | command | status | enabled |
96
- | passing | 9 | exit 0 | 0 | true |
97
- | warning | 10 | exit 1 | 1 | true |
98
- | critical | 11 | exit 2 | 2 | true |
99
- And the following related checks exist:
100
- | parent_id | child_id |
101
- | 9 | 10 |
102
- | 10 | 11 |
103
- | 11 | 9 |
104
- When I get all check relationships
105
- Then I should have at least 3 check relationships
@@ -1,25 +0,0 @@
1
- Given /^I set up the Couch backend with the following options:$/ do |table|
2
- @backend_options = table.hashes.first.symbolize_keys
3
- uri = "/#{@backend_options[:database]}/"
4
- request = ::Net::HTTP::Put.new(uri)
5
- response = ::Net::HTTP.start(@backend_options[:host], @backend_options[:port]) {|http| http.request(request)}
6
-
7
- @backend = Flapjack::Persistence::Couch.new(@backend_options)
8
-
9
- uri = "/#{@backend_options[:database]}/_all_docs"
10
- request = ::Net::HTTP::Get.new(uri)
11
- response = ::Net::HTTP.start(@backend_options[:host], @backend_options[:port]) {|http| http.request(request)}
12
-
13
- parser = Yajl::Parser.new
14
- doc = parser.parse(response.body)
15
- doc["rows"].each do |row|
16
- uri = "/#{@backend_options[:database]}/#{row["id"]}?rev=#{row["value"]["rev"]}"
17
- request = ::Net::HTTP::Delete.new(uri)
18
- response = ::Net::HTTP.start(@backend_options[:host], @backend_options[:port]) {|http| http.request(request)}
19
- end
20
- end
21
-
22
- Then /^the check with id "([^\"]*)" on the Couch backend should have a status of "([^\"]*)"$/ do |arg1, arg2|
23
- pending # express the regexp above with the code you wish you had
24
- end
25
-
@@ -1,102 +0,0 @@
1
- When /^I create the following checks:$/ do |table|
2
- table.hashes.each do |attrs|
3
- @backend.save_check(attrs.symbolize_keys).should be_true
4
- end
5
- end
6
-
7
- Then /^looking up the following checks should return documents:$/ do |table|
8
- table.hashes.each do |attrs|
9
- @backend.get_check(attrs['id']).should_not be_nil
10
- end
11
- end
12
-
13
- When /^I update the following checks:$/ do |table|
14
- table.hashes.each do |attrs|
15
- @backend.save_check(attrs.symbolize_keys).should be_true
16
- end
17
- end
18
-
19
- Then /^the updates should succeed$/ do
20
- # matches on "should be_true" above
21
- end
22
-
23
- When /^I delete the check with id "([^\"]*)"$/ do |id|
24
- @backend.delete_check(id).should be_true
25
- end
26
-
27
- Then /^the check with id "([^\"]*)" should not exist$/ do |id|
28
- @backend.get_check(id).should be_nil
29
- end
30
-
31
- When /^I get all checks$/ do
32
- @checks = @backend.all_checks
33
- end
34
-
35
- Then /^I should have at least (\d+) checks$/ do |n|
36
- @checks.size.should >= n.to_i
37
- end
38
-
39
- Given /^the following checks exist:$/ do |table|
40
- table.hashes.each do |attrs|
41
- @backend.save_check(attrs.symbolize_keys)
42
- end
43
- end
44
-
45
- Then /^the following results should save:$/ do |table|
46
- table.hashes.each do |attrs|
47
- @backend.save_check(attrs.symbolize_keys).should be_true
48
- end
49
- end
50
-
51
- Given /^the following related checks exist:$/ do |table|
52
- table.hashes.each do |attrs|
53
- @backend.save_check_relationship(attrs).should be_true
54
- end
55
- end
56
-
57
- Then /^the following result should not have a failing parent:$/ do |table|
58
- table.hashes.each do |attrs|
59
- @backend.any_parents_failed?(attrs['check_id']).should be_false
60
- end
61
- end
62
-
63
- Then /^the following result should have a failing parent:$/ do |table|
64
- table.hashes.each do |attrs|
65
- @backend.any_parents_failed?(attrs['check_id']).should be_true
66
- end
67
- end
68
-
69
- Then /^the following event should save:$/ do |table|
70
- table.hashes.each do |attrs|
71
- result = Flapjack::Transport::Result.new(:result => attrs.symbolize_keys)
72
- @backend.create_event(result).should be_true
73
- end
74
- end
75
-
76
-
77
- When /^I get all check relationships$/ do
78
- @relationships = @backend.all_check_relationships
79
- end
80
-
81
- Then /^I should have at least (\d+) check relationships$/ do |n|
82
- @relationships.size.should >= n.to_i
83
- end
84
-
85
- Given /^the following events exist:$/ do |table|
86
- table.hashes.each do |attrs|
87
- result = Flapjack::Transport::Result.new(:result => attrs.symbolize_keys)
88
- @backend.create_event(result).should be_true
89
- end
90
- end
91
-
92
- When /^I get all events$/ do
93
- @events = @backend.all_events
94
- end
95
-
96
- Then /^I should have at least (\d+) events$/ do |n|
97
- @events.size.should >= n.to_i
98
- end
99
-
100
- When /^I get all events for check "([^\"]*)"$/ do |id|
101
- @events = @backend.all_events_for(id)
102
- end
@@ -1,13 +0,0 @@
1
- Given /^I set up the Sqlite3 backend with the following options:$/ do |table|
2
- @backend_options = table.hashes.first
3
- @backend = Flapjack::Persistence::Sqlite3.new(@backend_options)
4
- end
5
-
6
- Then /^the check with id "([^\"]*)" on the Sqlite3 backend should have an event created$/ do |id|
7
- @backend.all_events_for(id).size.should > 0
8
- end
9
-
10
- Then /^the check with id "([^\"]*)" on the Sqlite3 backend should have a status of "([^\"]*)"$/ do |id, status|
11
- @backend.get_check(id)["status"].should == status
12
- end
13
-
@@ -1,24 +0,0 @@
1
- __DIR__ = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
2
- bin_path = File.join(__DIR__, 'bin')
3
-
4
- Given /^there are no instances of flapjack\-notifier running$/ do
5
- command = "#{bin_path}/flapjack-notifier-manager stop"
6
- silent_system(command)
7
-
8
- sleep 0.5 # wait for the notifier manager
9
-
10
- output = `ps -eo cmd |grep ^flapjack-notifier`
11
- output.split.size.should == 0
12
- end
13
-
14
- Given /^there is an instance of the flapjack\-notifier running$/ do
15
- command = "#{bin_path}/flapjack-notifier-manager start"
16
- command += " --recipients spec/fixtures/recipients.yaml --config spec/fixtures/flapjack-notifier.yaml"
17
- silent_system(command).should be_true
18
-
19
- sleep 0.5 # again, waiting for the notifier manager
20
-
21
- output = `ps -eo cmd |grep ^flapjack-notifier`
22
- output.split.size.should == 1
23
- end
24
-
@@ -1,48 +0,0 @@
1
- __DIR__ = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
2
-
3
- Given /^the (.+) is on my path$/ do |command|
4
- @bin_path = File.join(__DIR__, 'bin')
5
- # (and is executable)
6
- silent_system("test -x #{@bin_path}/#{command}").should be_true
7
- end
8
-
9
- Given /^the "([^\"]*)" directory exists and is writable$/ do |directory|
10
- File.exists?(directory).should be_true
11
- File.writable?(directory).should be_true
12
- end
13
-
14
- When /^I run "([^\"]*)"$/ do |cmd|
15
- @root = Pathname.new(File.dirname(__FILE__)).parent.parent.expand_path
16
- bin_path = @root.join('bin')
17
- command = "#{bin_path}/#{cmd}"
18
-
19
- @output = `#{command}`
20
- $?.exitstatus.should == 0
21
- end
22
-
23
- Then /^(\d+) instances of "([^\"]*)" should be running$/ do |number, command|
24
- sleep 0.5 # this truly is a dodgy hack.
25
- # sometimes the the worker manager can take a while to fork
26
- output = `ps -eo cmd |grep ^#{command} |grep -v grep`
27
- output.split.size.should >= number.to_i
28
- end
29
-
30
- Given /^there are (\d+) instances of the flapjack\-worker running$/ do |number|
31
- command = "#{@bin_path}/flapjack-worker-manager start --workers=5"
32
- silent_system(command).should be_true
33
- end
34
-
35
- Given /^there are no instances of flapjack\-worker running$/ do
36
- command = "#{@bin_path}/flapjack-worker-manager stop"
37
- silent_system(command)
38
-
39
- sleep 0.5 # again, waiting for the worker manager
40
-
41
- output = `ps -eo cmd |grep ^flapjack-worker |grep -v grep`
42
- output.split("\n").size.should == 0
43
- end
44
-
45
- Given /^beanstalkd is running on localhost$/ do
46
- output = `ps -eo cmd |grep beanstalkd |grep -v grep`
47
- output.split("\n").size.should == 1
48
- end
@@ -1,222 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $: << File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
4
- require 'log4r'
5
- require 'log4r/outputter/syslogoutputter'
6
- require 'flapjack/patches'
7
- require 'flapjack/notifier_engine'
8
-
9
- module Flapjack
10
- module Notifier
11
- class Application
12
-
13
- # boots the notifier
14
- def self.run(options={})
15
- app = self.new(options)
16
- app.setup_config
17
- app.setup_loggers
18
- app.setup_notifiers
19
- app.setup_notifier_engine
20
- app.setup_recipients
21
- app.setup_persistence
22
- app.setup_queues
23
- app.setup_filters
24
-
25
- app
26
- end
27
-
28
- attr_accessor :log, :recipients
29
-
30
- def initialize(options={})
31
- @log = options[:log]
32
- @notifier_directories = options[:notifier_directories]
33
- @filter_directories = options[:filter_directories]
34
- @options = options
35
- end
36
-
37
- def setup_loggers
38
- unless @log
39
- @log = Log4r::Logger.new("notifier")
40
- @log.add(Log4r::StdoutOutputter.new("notifier"))
41
- @log.add(Log4r::SyslogOutputter.new("notifier"))
42
- end
43
- end
44
-
45
- def setup_config
46
- @config = OpenStruct.new(@options)
47
- end
48
-
49
- def setup_notifiers
50
- @notifier_directories ||= []
51
-
52
- default_directory = File.expand_path(File.join(File.dirname(__FILE__), '..', 'notifiers'))
53
- # the default directory should be the last in the list
54
- if @notifier_directories.include?(default_directory)
55
- @notifier_directories << @notifier_directories.delete(default_directory)
56
- else
57
- @notifier_directories << default_directory
58
- end
59
-
60
- # filter to the directories that actually exist
61
- @notifier_directories = @notifier_directories.find_all do |dir|
62
- if File.exists?(dir)
63
- true
64
- else
65
- @log.warning("Notifiers directory #{dir} doesn't exist. Skipping.")
66
- false
67
- end
68
- end
69
-
70
- @notifiers = []
71
-
72
- # load up the notifiers and pass a config
73
- @config.notifiers.each_pair do |notifier, config|
74
- filenames = @notifier_directories.map {|dir| File.join(dir, notifier.to_s, 'init' + '.rb')}
75
- filename = filenames.find {|filename| File.exists?(filename)}
76
-
77
- if filename
78
- @log.info("Loading the #{notifier.to_s.capitalize} notifier (from #{filename})")
79
- require filename
80
- config.merge!(:log => @log)
81
- notifier = Flapjack::Notifiers.const_get("#{notifier.to_s.capitalize}").new(config)
82
- @notifiers << notifier
83
- else
84
- @log.warning("Flapjack::Notifiers::#{notifier.to_s.capitalize} doesn't exist!")
85
- end
86
- end
87
-
88
- end
89
-
90
- def setup_notifier_engine
91
- options = { :log => @log, :notifiers => @notifiers }
92
- @notifier_engine = Flapjack::NotifierEngine.new(options)
93
- end
94
-
95
- def setup_recipients
96
- @recipients ||= []
97
-
98
- @recipients += (@config.recipients || [])
99
- # so poking at a recipient within notifiers is easier
100
- @recipients.map! do |recipient|
101
- OpenStruct.new(recipient)
102
- end
103
- end
104
-
105
- def setup_persistence
106
- defaults = { :backend => :data_mapper,
107
- :log => @log }
108
- config = defaults.merge(@config.persistence || {})
109
- basedir = config.delete(:basedir) || File.join(File.dirname(__FILE__), '..', 'persistence')
110
-
111
- filename = File.join(basedir, "#{config[:backend]}.rb")
112
- class_name = config[:backend].to_s.camel_case
113
-
114
- @log.info("Loading the #{class_name} persistence backend")
115
-
116
- begin
117
- require filename
118
- @persistence = Flapjack::Persistence.const_get(class_name).new(config)
119
- rescue LoadError => e
120
- @log.warning("Attempted to load #{class_name} persistence backend, but it doesn't exist!")
121
- @log.warning("Exiting.")
122
- raise # preserves original exception
123
- end
124
-
125
- end
126
-
127
- def setup_queues
128
- defaults = { :backend => :beanstalkd,
129
- :host => 'localhost',
130
- :port => '11300',
131
- :queue_name => 'results',
132
- :log => @log }
133
- config = defaults.merge(@config.transport || {})
134
- basedir = config.delete(:basedir) || File.join(File.dirname(__FILE__), '..', 'transports')
135
-
136
- class_name = config[:backend].to_s.camel_case
137
- filename = File.join(basedir, "#{config[:backend]}.rb")
138
-
139
- @log.info("Loading the #{class_name} transport")
140
-
141
- begin
142
- require filename
143
- @results_queue = Flapjack::Transport.const_get(class_name).new(config)
144
- rescue LoadError => e
145
- @log.warning("Attempted to load #{class_name} transport, but it doesn't exist!")
146
- @log.warning("Exiting.")
147
- raise # preserves original exception
148
- end
149
- end
150
-
151
- def setup_filters
152
- @filter_directories ||= []
153
-
154
- default_directory = File.expand_path(File.join(File.dirname(__FILE__), '..', 'filters'))
155
- # the default directory should be the last in the list
156
- if @filter_directories.include?(default_directory)
157
- @filter_directories << @filter_directories.delete(default_directory)
158
- else
159
- @filter_directories << default_directory
160
- end
161
-
162
- # filter to the directories that actually exist
163
- @filter_directories = @filter_directories.find_all do |dir|
164
- if File.exists?(dir)
165
- true
166
- else
167
- @log.warning("Filters directory #{dir} doesn't exist. Skipping.")
168
- false
169
- end
170
- end
171
-
172
- @filters = []
173
-
174
- @config.filters.each do |filter|
175
- filenames = @filter_directories.map {|dir| File.join(dir, filter.to_s + '.rb')}
176
- filename = filenames.find {|filename| File.exists?(filename)}
177
-
178
- if filename
179
- @log.info("Loading the #{filter.camel_case} filter (from #{filename})")
180
- require filename
181
- filter = Flapjack::Filters.const_get(filter.camel_case).new(:log => @log, :persistence => @persistence)
182
- @filters << filter
183
- else
184
- @log.warning("Flapjack::Filters::#{filter.camel_case} doesn't exist!")
185
- end
186
- end
187
-
188
- end
189
-
190
- def process_result
191
- @log.debug("Waiting for new result...")
192
- result = @results_queue.next # this blocks until a result is popped
193
-
194
- @log.info("Processing result for check #{result.check_id}.")
195
- event = @persistence.create_event(result)
196
-
197
-
198
- block = @filters.find {|filter| filter.block?(result) }
199
- unless block
200
- # do munging
201
- @notifier_engine.notify!(:result => result,
202
- :event => event,
203
- :recipients => recipients)
204
- end
205
-
206
- @log.info("Storing status of check.")
207
- @persistence.save(result)
208
-
209
- @log.info("Deleting result for check #{result.check_id}.")
210
- @results_queue.delete(result)
211
- end
212
-
213
- def main
214
- @log.info("Booting main loop.")
215
- loop do
216
- process_result
217
- end
218
- end
219
-
220
- end
221
- end
222
- end