flapjack 1.6.0 → 2.0.0b1
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.
- checksums.yaml +4 -4
- data/.gitignore +4 -6
- data/.gitmodules +1 -1
- data/.rspec +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +12 -13
- data/CHANGELOG.md +2 -9
- data/CONTRIBUTING.md +7 -2
- data/Gemfile +4 -13
- data/LICENCE +1 -0
- data/README.md +8 -2
- data/Rakefile +2 -2
- data/bin/flapjack +3 -12
- data/build.sh +4 -2
- data/etc/flapjack_config.toml.example +273 -0
- data/features/ack_after_sched_maint.feature +18 -21
- data/features/cli.feature +11 -71
- data/features/cli_flapjack-feed-events.feature +14 -15
- data/features/cli_flapjack-nagios-receiver.feature +12 -41
- data/features/cli_flapper.feature +12 -41
- data/features/cli_purge.feature +5 -6
- data/features/cli_receive-events.feature +6 -7
- data/features/cli_simulate-failed-check.feature +5 -6
- data/features/events.feature +206 -181
- data/features/events_check_names.feature +4 -7
- data/features/notification_rules.feature +144 -223
- data/features/notifications.feature +65 -57
- data/features/rollup.feature +45 -47
- data/features/steps/cli_steps.rb +4 -5
- data/features/steps/events_steps.rb +163 -373
- data/features/steps/notifications_steps.rb +408 -264
- data/features/steps/packaging-lintian_steps.rb +0 -4
- data/features/steps/time_travel_steps.rb +0 -26
- data/features/support/daemons.rb +6 -31
- data/features/support/env.rb +65 -74
- data/flapjack.gemspec +22 -24
- data/lib/flapjack.rb +14 -7
- data/lib/flapjack/cli/flapper.rb +74 -173
- data/lib/flapjack/cli/maintenance.rb +278 -109
- data/lib/flapjack/cli/migrate.rb +950 -0
- data/lib/flapjack/cli/purge.rb +19 -22
- data/lib/flapjack/cli/receiver.rb +150 -326
- data/lib/flapjack/cli/server.rb +8 -235
- data/lib/flapjack/cli/simulate.rb +42 -57
- data/lib/flapjack/configuration.rb +51 -37
- data/lib/flapjack/coordinator.rb +138 -129
- data/lib/flapjack/data/acknowledgement.rb +177 -0
- data/lib/flapjack/data/alert.rb +97 -158
- data/lib/flapjack/data/check.rb +611 -0
- data/lib/flapjack/data/condition.rb +70 -0
- data/lib/flapjack/data/contact.rb +226 -456
- data/lib/flapjack/data/event.rb +96 -184
- data/lib/flapjack/data/extensions/associations.rb +59 -0
- data/lib/flapjack/data/extensions/short_name.rb +25 -0
- data/lib/flapjack/data/medium.rb +428 -0
- data/lib/flapjack/data/metrics.rb +194 -0
- data/lib/flapjack/data/notification.rb +22 -281
- data/lib/flapjack/data/rule.rb +473 -0
- data/lib/flapjack/data/scheduled_maintenance.rb +244 -0
- data/lib/flapjack/data/state.rb +221 -0
- data/lib/flapjack/data/statistic.rb +112 -0
- data/lib/flapjack/data/tag.rb +277 -0
- data/lib/flapjack/data/test_notification.rb +182 -0
- data/lib/flapjack/data/unscheduled_maintenance.rb +159 -0
- data/lib/flapjack/data/validators/id_validator.rb +20 -0
- data/lib/flapjack/exceptions.rb +6 -0
- data/lib/flapjack/filters/acknowledgement.rb +23 -16
- data/lib/flapjack/filters/base.rb +0 -5
- data/lib/flapjack/filters/delays.rb +53 -43
- data/lib/flapjack/filters/ok.rb +23 -14
- data/lib/flapjack/filters/scheduled_maintenance.rb +3 -3
- data/lib/flapjack/filters/unscheduled_maintenance.rb +12 -3
- data/lib/flapjack/gateways/aws_sns.rb +65 -49
- data/lib/flapjack/gateways/aws_sns/alert.text.erb +2 -2
- data/lib/flapjack/gateways/aws_sns/alert_subject.text.erb +2 -2
- data/lib/flapjack/gateways/aws_sns/rollup_subject.text.erb +1 -1
- data/lib/flapjack/gateways/email.rb +107 -90
- data/lib/flapjack/gateways/email/alert.html.erb +19 -18
- data/lib/flapjack/gateways/email/alert.text.erb +20 -14
- data/lib/flapjack/gateways/email/alert_subject.text.erb +2 -1
- data/lib/flapjack/gateways/email/rollup.html.erb +14 -13
- data/lib/flapjack/gateways/email/rollup.text.erb +13 -10
- data/lib/flapjack/gateways/jabber.rb +679 -671
- data/lib/flapjack/gateways/jabber/alert.text.erb +9 -6
- data/lib/flapjack/gateways/jsonapi.rb +164 -350
- data/lib/flapjack/gateways/jsonapi/data/join_descriptor.rb +44 -0
- data/lib/flapjack/gateways/jsonapi/data/method_descriptor.rb +21 -0
- data/lib/flapjack/gateways/jsonapi/helpers/headers.rb +63 -0
- data/lib/flapjack/gateways/jsonapi/helpers/miscellaneous.rb +136 -0
- data/lib/flapjack/gateways/jsonapi/helpers/resources.rb +227 -0
- data/lib/flapjack/gateways/jsonapi/helpers/serialiser.rb +313 -0
- data/lib/flapjack/gateways/jsonapi/helpers/swagger_docs.rb +322 -0
- data/lib/flapjack/gateways/jsonapi/methods/association_delete.rb +115 -0
- data/lib/flapjack/gateways/jsonapi/methods/association_get.rb +288 -0
- data/lib/flapjack/gateways/jsonapi/methods/association_patch.rb +178 -0
- data/lib/flapjack/gateways/jsonapi/methods/association_post.rb +116 -0
- data/lib/flapjack/gateways/jsonapi/methods/metrics.rb +71 -0
- data/lib/flapjack/gateways/jsonapi/methods/resource_delete.rb +119 -0
- data/lib/flapjack/gateways/jsonapi/methods/resource_get.rb +186 -0
- data/lib/flapjack/gateways/jsonapi/methods/resource_patch.rb +239 -0
- data/lib/flapjack/gateways/jsonapi/methods/resource_post.rb +197 -0
- data/lib/flapjack/gateways/jsonapi/middleware/array_param_fixer.rb +27 -0
- data/lib/flapjack/gateways/jsonapi/{rack → middleware}/json_params_parser.rb +7 -6
- data/lib/flapjack/gateways/jsonapi/middleware/request_timestamp.rb +18 -0
- data/lib/flapjack/gateways/oobetet.rb +222 -170
- data/lib/flapjack/gateways/pager_duty.rb +388 -0
- data/lib/flapjack/gateways/pager_duty/alert.text.erb +13 -0
- data/lib/flapjack/gateways/slack.rb +56 -48
- data/lib/flapjack/gateways/slack/alert.text.erb +1 -1
- data/lib/flapjack/gateways/slack/rollup.text.erb +1 -1
- data/lib/flapjack/gateways/sms_aspsms.rb +155 -0
- data/lib/flapjack/gateways/sms_aspsms/alert.text.erb +7 -0
- data/lib/flapjack/gateways/sms_aspsms/rollup.text.erb +2 -0
- data/lib/flapjack/gateways/sms_messagenet.rb +77 -57
- data/lib/flapjack/gateways/sms_messagenet/alert.text.erb +3 -2
- data/lib/flapjack/gateways/sms_nexmo.rb +53 -51
- data/lib/flapjack/gateways/sms_nexmo/alert.text.erb +2 -2
- data/lib/flapjack/gateways/sms_nexmo/rollup.text.erb +1 -1
- data/lib/flapjack/gateways/sms_twilio.rb +79 -62
- data/lib/flapjack/gateways/sms_twilio/alert.text.erb +3 -2
- data/lib/flapjack/gateways/web.rb +437 -345
- data/lib/flapjack/gateways/web/middleware/request_timestamp.rb +18 -0
- data/lib/flapjack/gateways/web/public/css/bootstrap.css +3793 -4340
- data/lib/flapjack/gateways/web/public/css/bootstrap.css.map +1 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.svg +273 -214
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/lib/flapjack/gateways/web/public/js/bootstrap.js +1637 -1607
- data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -2
- data/lib/flapjack/gateways/web/views/_pagination.html.erb +19 -0
- data/lib/flapjack/gateways/web/views/check.html.erb +159 -121
- data/lib/flapjack/gateways/web/views/checks.html.erb +82 -41
- data/lib/flapjack/gateways/web/views/contact.html.erb +59 -71
- data/lib/flapjack/gateways/web/views/contacts.html.erb +32 -8
- data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
- data/lib/flapjack/gateways/web/views/{layout.erb → layout.html.erb} +7 -23
- data/lib/flapjack/gateways/web/views/self_stats.html.erb +32 -33
- data/lib/flapjack/gateways/web/views/tag.html.erb +32 -0
- data/lib/flapjack/gateways/web/views/tags.html.erb +51 -0
- data/lib/flapjack/logger.rb +34 -3
- data/lib/flapjack/notifier.rb +180 -112
- data/lib/flapjack/patches.rb +8 -63
- data/lib/flapjack/pikelet.rb +185 -143
- data/lib/flapjack/processor.rb +323 -191
- data/lib/flapjack/record_queue.rb +33 -0
- data/lib/flapjack/redis_proxy.rb +66 -0
- data/lib/flapjack/utility.rb +21 -15
- data/lib/flapjack/version.rb +2 -1
- data/libexec/httpbroker.go +218 -14
- data/libexec/oneoff.go +13 -10
- data/spec/lib/flapjack/configuration_spec.rb +286 -0
- data/spec/lib/flapjack/coordinator_spec.rb +103 -157
- data/spec/lib/flapjack/data/check_spec.rb +175 -0
- data/spec/lib/flapjack/data/contact_spec.rb +26 -349
- data/spec/lib/flapjack/data/event_spec.rb +76 -291
- data/spec/lib/flapjack/data/medium_spec.rb +19 -0
- data/spec/lib/flapjack/data/rule_spec.rb +43 -0
- data/spec/lib/flapjack/data/scheduled_maintenance_spec.rb +976 -0
- data/spec/lib/flapjack/data/unscheduled_maintenance_spec.rb +34 -0
- data/spec/lib/flapjack/gateways/aws_sns_spec.rb +111 -60
- data/spec/lib/flapjack/gateways/email_spec.rb +194 -161
- data/spec/lib/flapjack/gateways/jabber_spec.rb +961 -162
- data/spec/lib/flapjack/gateways/jsonapi/methods/check_links_spec.rb +155 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/checks_spec.rb +426 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/contact_links_spec.rb +217 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/contacts_spec.rb +425 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/events_spec.rb +271 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/media_spec.rb +257 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/medium_links_spec.rb +163 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/metrics_spec.rb +8 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/rule_links_spec.rb +212 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/rules_spec.rb +289 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/scheduled_maintenance_links_spec.rb +49 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/scheduled_maintenances_spec.rb +242 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/tag_links_spec.rb +274 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/tags_spec.rb +302 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/unscheduled_maintenance_links_spec.rb +49 -0
- data/spec/lib/flapjack/gateways/jsonapi/methods/unscheduled_maintenances_spec.rb +339 -0
- data/spec/lib/flapjack/gateways/jsonapi_spec.rb +1 -1
- data/spec/lib/flapjack/gateways/oobetet_spec.rb +151 -79
- data/spec/lib/flapjack/gateways/pager_duty_spec.rb +353 -0
- data/spec/lib/flapjack/gateways/slack_spec.rb +53 -53
- data/spec/lib/flapjack/gateways/sms_aspsms_spec.rb +106 -0
- data/spec/lib/flapjack/gateways/sms_messagenet_spec.rb +111 -54
- data/spec/lib/flapjack/gateways/sms_nexmo_spec.rb +50 -51
- data/spec/lib/flapjack/gateways/sms_twilio_spec.rb +108 -48
- data/spec/lib/flapjack/gateways/web_spec.rb +144 -216
- data/spec/lib/flapjack/notifier_spec.rb +132 -1
- data/spec/lib/flapjack/pikelet_spec.rb +111 -50
- data/spec/lib/flapjack/processor_spec.rb +210 -40
- data/spec/lib/flapjack/redis_proxy_spec.rb +45 -0
- data/spec/lib/flapjack/utility_spec.rb +11 -15
- data/spec/service_consumers/fixture_data.rb +547 -0
- data/spec/service_consumers/pact_helper.rb +21 -32
- data/spec/service_consumers/pacts/flapjack-diner_v2.0.json +4652 -0
- data/spec/service_consumers/provider_states_for_flapjack-diner.rb +279 -322
- data/spec/service_consumers/provider_support.rb +8 -0
- data/spec/spec_helper.rb +34 -44
- data/spec/support/erb_view_helper.rb +1 -1
- data/spec/support/factories.rb +58 -0
- data/spec/support/jsonapi_helper.rb +15 -26
- data/spec/support/mock_logger.rb +43 -0
- data/spec/support/xmpp_comparable.rb +24 -0
- data/src/flapjack/transport_test.go +30 -1
- data/tasks/dump_keys.rake +82 -0
- data/tasks/events.rake +7 -7
- data/tasks/support/flapjack_config_benchmark.toml +28 -0
- data/tasks/support/flapjack_config_benchmark.yaml +0 -2
- metadata +175 -222
- data/Guardfile +0 -14
- data/etc/flapjack_config.yaml.example +0 -477
- data/features/cli_flapjack-populator.feature +0 -90
- data/features/support/silent_system.rb +0 -4
- data/lib/flapjack/cli/import.rb +0 -108
- data/lib/flapjack/data/entity.rb +0 -652
- data/lib/flapjack/data/entity_check.rb +0 -1044
- data/lib/flapjack/data/message.rb +0 -56
- data/lib/flapjack/data/migration.rb +0 -234
- data/lib/flapjack/data/notification_rule.rb +0 -425
- data/lib/flapjack/data/semaphore.rb +0 -44
- data/lib/flapjack/data/tagged.rb +0 -48
- data/lib/flapjack/gateways/jsonapi/check_methods.rb +0 -206
- data/lib/flapjack/gateways/jsonapi/check_presenter.rb +0 -221
- data/lib/flapjack/gateways/jsonapi/contact_methods.rb +0 -186
- data/lib/flapjack/gateways/jsonapi/entity_methods.rb +0 -223
- data/lib/flapjack/gateways/jsonapi/medium_methods.rb +0 -185
- data/lib/flapjack/gateways/jsonapi/metrics_methods.rb +0 -132
- data/lib/flapjack/gateways/jsonapi/notification_rule_methods.rb +0 -141
- data/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods.rb +0 -139
- data/lib/flapjack/gateways/jsonapi/report_methods.rb +0 -146
- data/lib/flapjack/gateways/pagerduty.rb +0 -318
- data/lib/flapjack/gateways/pagerduty/alert.text.erb +0 -10
- data/lib/flapjack/gateways/web/public/css/select2-bootstrap.css +0 -87
- data/lib/flapjack/gateways/web/public/css/select2.css +0 -615
- data/lib/flapjack/gateways/web/public/css/tablesort.css +0 -67
- data/lib/flapjack/gateways/web/public/img/select2-spinner.gif +0 -0
- data/lib/flapjack/gateways/web/public/img/select2.png +0 -0
- data/lib/flapjack/gateways/web/public/img/select2x2.png +0 -0
- data/lib/flapjack/gateways/web/public/js/backbone.js +0 -1581
- data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +0 -322
- data/lib/flapjack/gateways/web/public/js/flapjack.js +0 -82
- data/lib/flapjack/gateways/web/public/js/jquery.tablesorter.js +0 -1640
- data/lib/flapjack/gateways/web/public/js/jquery.tablesorter.widgets.js +0 -1390
- data/lib/flapjack/gateways/web/public/js/modules/contact.js +0 -520
- data/lib/flapjack/gateways/web/public/js/modules/entity.js +0 -28
- data/lib/flapjack/gateways/web/public/js/modules/medium.js +0 -40
- data/lib/flapjack/gateways/web/public/js/select2.js +0 -3397
- data/lib/flapjack/gateways/web/public/js/tablesort.js +0 -44
- data/lib/flapjack/gateways/web/public/js/underscore.js +0 -1276
- data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +0 -173
- data/lib/flapjack/gateways/web/views/entities.html.erb +0 -30
- data/lib/flapjack/gateways/web/views/entity.html.erb +0 -51
- data/lib/flapjack/rack_logger.rb +0 -47
- data/lib/flapjack/redis_pool.rb +0 -42
- data/spec/lib/flapjack/data/entity_check_spec.rb +0 -1418
- data/spec/lib/flapjack/data/entity_spec.rb +0 -872
- data/spec/lib/flapjack/data/message_spec.rb +0 -30
- data/spec/lib/flapjack/data/migration_spec.rb +0 -104
- data/spec/lib/flapjack/data/notification_rule_spec.rb +0 -232
- data/spec/lib/flapjack/data/notification_spec.rb +0 -53
- data/spec/lib/flapjack/data/semaphore_spec.rb +0 -24
- data/spec/lib/flapjack/filters/acknowledgement_spec.rb +0 -6
- data/spec/lib/flapjack/filters/delays_spec.rb +0 -6
- data/spec/lib/flapjack/filters/ok_spec.rb +0 -6
- data/spec/lib/flapjack/filters/scheduled_maintenance_spec.rb +0 -6
- data/spec/lib/flapjack/filters/unscheduled_maintenance_spec.rb +0 -6
- data/spec/lib/flapjack/gateways/jsonapi/check_methods_spec.rb +0 -315
- data/spec/lib/flapjack/gateways/jsonapi/check_presenter_spec.rb +0 -223
- data/spec/lib/flapjack/gateways/jsonapi/contact_methods_spec.rb +0 -131
- data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +0 -389
- data/spec/lib/flapjack/gateways/jsonapi/medium_methods_spec.rb +0 -231
- data/spec/lib/flapjack/gateways/jsonapi/notification_rule_methods_spec.rb +0 -169
- data/spec/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods_spec.rb +0 -114
- data/spec/lib/flapjack/gateways/jsonapi/report_methods_spec.rb +0 -590
- data/spec/lib/flapjack/gateways/pagerduty_spec.rb +0 -249
- data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +0 -21
- data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +0 -24
- data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +0 -16
- data/spec/lib/flapjack/redis_pool_spec.rb +0 -29
- data/spec/service_consumers/pacts/flapjack-diner_v1.0.json +0 -4702
- data/tasks/entities.rake +0 -151
- data/tasks/profile.rake +0 -282
- data/tmp/acknowledge.rb +0 -13
- data/tmp/create_config_yaml.rb +0 -16
- data/tmp/create_event_ok.rb +0 -30
- data/tmp/create_event_unknown.rb +0 -30
- data/tmp/create_events_failure.rb +0 -34
- data/tmp/create_events_ok.rb +0 -32
- data/tmp/create_events_ok_fail_ack_ok.rb +0 -53
- data/tmp/create_events_ok_failure.rb +0 -41
- data/tmp/create_events_ok_failure_ack.rb +0 -53
- data/tmp/dummy_contacts.json +0 -43
- data/tmp/dummy_entities.json +0 -37
- data/tmp/generate_nagios_test_hosts.rb +0 -16
- data/tmp/notification_rules.rb +0 -73
- data/tmp/parse_config_yaml.rb +0 -7
- data/tmp/redis_find_spurious_unknown_states.rb +0 -52
- data/tmp/test_json_post.rb +0 -19
- data/tmp/test_notification_rules_api.rb +0 -171
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
<%
|
|
2
|
-
require_css 'select2'
|
|
3
|
-
require_css 'select2-bootstrap'
|
|
4
|
-
|
|
5
|
-
require_js 'underscore'
|
|
6
|
-
require_js 'jquery-1.10.2'
|
|
7
|
-
require_js 'backbone'
|
|
8
|
-
require_js 'backbone.jsonapi'
|
|
9
|
-
require_js 'bootstrap'
|
|
10
|
-
require_js 'select2'
|
|
11
|
-
%>
|
|
12
|
-
|
|
13
|
-
<script type="text/template" id="contact-actions-template">
|
|
14
|
-
<button class="btn btn-success" id="addContact">
|
|
15
|
-
Add contact
|
|
16
|
-
</button>
|
|
17
|
-
</script>
|
|
18
|
-
|
|
19
|
-
<script type="text/template" id="contact-list-item-template">
|
|
20
|
-
<td><@- first_name @></td>
|
|
21
|
-
<td><@- last_name @></td>
|
|
22
|
-
<td class="actions">
|
|
23
|
-
<button type="button" class="btn btn-default contact-media" aria-hidden="true">Media</button>
|
|
24
|
-
</td>
|
|
25
|
-
<td class="actions">
|
|
26
|
-
<button type="button" class="btn btn-default contact-entities" aria-hidden="true">Entities</button>
|
|
27
|
-
</td>
|
|
28
|
-
<td class="actions">
|
|
29
|
-
<button type="button" class="btn btn-danger delete-contact">Delete</button>
|
|
30
|
-
</td>
|
|
31
|
-
</script>
|
|
32
|
-
|
|
33
|
-
<script type="text/template" id="contact-details-form-template">
|
|
34
|
-
<div class="modal-content">
|
|
35
|
-
<div class="modal-header">
|
|
36
|
-
<h4 class="modal-title" id="contactModalLabel"><@- is_new ? 'New' : 'Edit' @> Contact</h4>
|
|
37
|
-
</div>
|
|
38
|
-
<div class="modal-body">
|
|
39
|
-
<form action="<%= @base_url %>contacts" method="post" role="form" class="form-horizontal">
|
|
40
|
-
|
|
41
|
-
<div id="contactDetails">
|
|
42
|
-
<div class="form-group">
|
|
43
|
-
<label class="col-sm-3 control-label" for="contact_first_name">First name</label>
|
|
44
|
-
<div class="col-sm-9">
|
|
45
|
-
<input type="text" autofocus="autofocus" name="contact_first_name" class="form-control" value="<@- first_name @>">
|
|
46
|
-
</div>
|
|
47
|
-
</div>
|
|
48
|
-
<div class="form-group">
|
|
49
|
-
<label class="col-sm-3 control-label" for="contact_last_name">Last name</label>
|
|
50
|
-
<div class="col-sm-9">
|
|
51
|
-
<input type="text" name="contact_last_name" class="form-control" value="<@- last_name @>">
|
|
52
|
-
</div>
|
|
53
|
-
</div>
|
|
54
|
-
</div>
|
|
55
|
-
|
|
56
|
-
<div class="modal-footer">
|
|
57
|
-
<button type="button" class="btn btn-success" id="contactAccept"<@- is_valid ? '' : ' disabled="disabled"' @>><@- is_new ? 'Create' : 'Update' @></button>
|
|
58
|
-
<button type="button" class="btn btn-cancel" id="contactCancel">Cancel</button>
|
|
59
|
-
</div>
|
|
60
|
-
</form>
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
</script>
|
|
64
|
-
|
|
65
|
-
<script type="text/template" id="contact-media-template">
|
|
66
|
-
<div class="modal-content">
|
|
67
|
-
<div class="modal-header">
|
|
68
|
-
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
|
69
|
-
<h4 class="modal-title" id="contactModalLabel">Media for <@- first_name @> <@- last_name @></h4>
|
|
70
|
-
</div>
|
|
71
|
-
<div class="modal-body">
|
|
72
|
-
<table class="table">
|
|
73
|
-
<thead>
|
|
74
|
-
<tr>
|
|
75
|
-
<th style="width: 15%">Media</th>
|
|
76
|
-
<th style="width: 65%">Address</th>
|
|
77
|
-
<th style="width: 10%">Interval</th>
|
|
78
|
-
<th style="width: 10%">Rollup</th>
|
|
79
|
-
</tr>
|
|
80
|
-
</thead>
|
|
81
|
-
<tbody id="contactMediaList">
|
|
82
|
-
</tbody>
|
|
83
|
-
</table>
|
|
84
|
-
</div>
|
|
85
|
-
</div>
|
|
86
|
-
</script>
|
|
87
|
-
|
|
88
|
-
<script type="text/template" id="contact-media-list-item-template">
|
|
89
|
-
<td>
|
|
90
|
-
<@- labels[type] @>
|
|
91
|
-
</td>
|
|
92
|
-
<td>
|
|
93
|
-
<input type="text" id="<@- labels[type] @>-address" data-attr="address" class="form-control" value="<@- address @>">
|
|
94
|
-
</td>
|
|
95
|
-
<td>
|
|
96
|
-
<input type="text" id="<@- labels[type] @>-interval" data-attr="interval" class="form-control" value="<@- interval @>">
|
|
97
|
-
</td>
|
|
98
|
-
<td>
|
|
99
|
-
<input type="text" id="<@- labels[type] @>-rollup_threshold" data-attr="rollup_threshold" class="form-control <@- labels[type] @>-rollup_threshold" value="<@- rollup_threshold @>">
|
|
100
|
-
</td>
|
|
101
|
-
</script>
|
|
102
|
-
|
|
103
|
-
<script type="text/template" id="contact-entities-template">
|
|
104
|
-
<div class="modal-content">
|
|
105
|
-
<div class="modal-header">
|
|
106
|
-
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
|
107
|
-
<h4 class="modal-title" id="contactModalLabel">Entities for <@- first_name @> <@- last_name @></h4>
|
|
108
|
-
</div>
|
|
109
|
-
<div class="modal-body">
|
|
110
|
-
<div id="contactEntityChooser">
|
|
111
|
-
</div>
|
|
112
|
-
|
|
113
|
-
<table class="table" style="margin-top: 1em; width: 100%">
|
|
114
|
-
<thead>
|
|
115
|
-
<tr>
|
|
116
|
-
<th style="width: 90%">Entities</th>
|
|
117
|
-
<th> </th>
|
|
118
|
-
</tr>
|
|
119
|
-
</thead>
|
|
120
|
-
<tbody id="contactEntityList">
|
|
121
|
-
</tbody>
|
|
122
|
-
</table>
|
|
123
|
-
</div>
|
|
124
|
-
</div><!-- /.modal-content -->
|
|
125
|
-
</script>
|
|
126
|
-
|
|
127
|
-
<script type="text/template" id="contact-entities-chooser-template">
|
|
128
|
-
<input type="hidden" id="entityChooser" style="width: 440px">
|
|
129
|
-
<button id="add-contact-entity" type="button" class="btn btn-default btn-xs">
|
|
130
|
-
<i class="fa fa-plus-square"></i>
|
|
131
|
-
|
|
132
|
-
Add Entities
|
|
133
|
-
</button>
|
|
134
|
-
</script>
|
|
135
|
-
|
|
136
|
-
<script type="text/template" id="contact-entities-list-item-template">
|
|
137
|
-
<td><@- name @></td>
|
|
138
|
-
<td><button type="button" class="close btn delete delete-entity" aria-hidden="true">−</button></td>
|
|
139
|
-
</script>
|
|
140
|
-
|
|
141
|
-
<%
|
|
142
|
-
require_js 'flapjack'
|
|
143
|
-
|
|
144
|
-
require_js 'modules/contact'
|
|
145
|
-
require_js 'modules/entity'
|
|
146
|
-
require_js 'modules/medium'
|
|
147
|
-
%>
|
|
148
|
-
|
|
149
|
-
<div id="data-api-url" data-api-url="<%= @api_url %>">
|
|
150
|
-
<div class="page-header">
|
|
151
|
-
<h2>Edit Contacts</h2>
|
|
152
|
-
</div>
|
|
153
|
-
<div id="container">
|
|
154
|
-
<table class="table">
|
|
155
|
-
<thead>
|
|
156
|
-
<tr>
|
|
157
|
-
<th>First Name</th>
|
|
158
|
-
<th>Last Name</th>
|
|
159
|
-
<th colspan="3">Actions</th>
|
|
160
|
-
</tr>
|
|
161
|
-
</thead>
|
|
162
|
-
<tbody id="contactList">
|
|
163
|
-
</tbody>
|
|
164
|
-
</table>
|
|
165
|
-
|
|
166
|
-
<!-- Modal -->
|
|
167
|
-
<div class="modal fade" id="contactModal" tabindex="-1" role="dialog" aria-labelledby="contactModalLabel" aria-hidden="true">
|
|
168
|
-
<div class="modal-dialog">
|
|
169
|
-
</div><!-- /.modal-dialog -->
|
|
170
|
-
</div><!-- /.modal -->
|
|
171
|
-
|
|
172
|
-
</div>
|
|
173
|
-
</div>
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<% if @auto_refresh %>
|
|
2
|
-
<meta http-equiv="refresh" content="<%= @auto_refresh %>" >
|
|
3
|
-
<% end %>
|
|
4
|
-
<% page_title "#{@adjective.capitalize} Entities" %>
|
|
5
|
-
|
|
6
|
-
<div class="page-header">
|
|
7
|
-
<h2><%= h @adjective.capitalize %> Entities</h2>
|
|
8
|
-
</div>
|
|
9
|
-
|
|
10
|
-
<p><%= h @count_failing_entities %> failing out of <%= h @count_current_entities %></p>
|
|
11
|
-
|
|
12
|
-
<% if @entities.length > 0 %>
|
|
13
|
-
<table class="table table-bordered table-hover table-condensed tablesorter">
|
|
14
|
-
<thead>
|
|
15
|
-
<tr>
|
|
16
|
-
<th data-placeholder="e.g. app[1-3]*">Entity</th>
|
|
17
|
-
</tr>
|
|
18
|
-
</thead>
|
|
19
|
-
<tbody>
|
|
20
|
-
<% @entities.sort.each do |entity| %>
|
|
21
|
-
<tr>
|
|
22
|
-
<td><a href="<%= @base_url %>entity/<%= CGI.escape(entity) %>"><%= h entity %></a>
|
|
23
|
-
</td>
|
|
24
|
-
</tr>
|
|
25
|
-
<% end %>
|
|
26
|
-
</tbody>
|
|
27
|
-
</table>
|
|
28
|
-
<% else %>
|
|
29
|
-
<p>No check output has been processed yet, so there are no entities we can show you here.</p>
|
|
30
|
-
<% end %>
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
<% if @auto_refresh %>
|
|
2
|
-
<meta http-equiv="refresh" content="<%= @auto_refresh %>" >
|
|
3
|
-
<% end %>
|
|
4
|
-
<% page_title "#{h(@entity)} (entity)" %>
|
|
5
|
-
|
|
6
|
-
<div class="page-header">
|
|
7
|
-
<h2><%= h @entity %></h2>
|
|
8
|
-
</div>
|
|
9
|
-
<% if @states.empty? %>
|
|
10
|
-
<div>
|
|
11
|
-
<p>This entity has no check output associated with it</p>
|
|
12
|
-
</div>
|
|
13
|
-
<% else %>
|
|
14
|
-
<table class="table table-bordered table-hover table-condensed">
|
|
15
|
-
<tr>
|
|
16
|
-
<th>Check</th>
|
|
17
|
-
<th>State</th>
|
|
18
|
-
<th>Summary</th>
|
|
19
|
-
<th>Last State Change</th>
|
|
20
|
-
<th>Last Update</th>
|
|
21
|
-
<th>Last Notification</th>
|
|
22
|
-
</tr>
|
|
23
|
-
<% @states.each do |check, status, summary, changed, updated, in_unscheduled_outage, in_scheduled_outage, notified| %>
|
|
24
|
-
<%
|
|
25
|
-
row_colour = case status
|
|
26
|
-
when 'critical', 'unknown'
|
|
27
|
-
'danger'
|
|
28
|
-
when 'ok', 'up'
|
|
29
|
-
'success'
|
|
30
|
-
else
|
|
31
|
-
status
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
check_link = @base_url + "check?entity=" << u(@entity) << "&check=" << u(check)
|
|
35
|
-
|
|
36
|
-
%>
|
|
37
|
-
<tr class="<%= row_colour %>">
|
|
38
|
-
<td><a href="<%= check_link %>" title="check detail"><%= h check %></a></td>
|
|
39
|
-
<td class="<%= status %>">
|
|
40
|
-
<%= h status.upcase %>
|
|
41
|
-
<% if in_unscheduled_outage%> (Ack'd)<% end %>
|
|
42
|
-
<% if in_scheduled_outage %> (Sched)<% end %>
|
|
43
|
-
</td>
|
|
44
|
-
<td><%= h summary %></td>
|
|
45
|
-
<td><%= h changed %></td>
|
|
46
|
-
<td><%= h updated %></td>
|
|
47
|
-
<td><%= h notified %></td>
|
|
48
|
-
</tr>
|
|
49
|
-
<% end %>
|
|
50
|
-
</table>
|
|
51
|
-
<% end %>
|
data/lib/flapjack/rack_logger.rb
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
module Flapjack
|
|
4
|
-
|
|
5
|
-
class CommonLogger < Rack::CommonLogger
|
|
6
|
-
|
|
7
|
-
alias_method :orig_log, :log
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
def log(env, status, header, began_at)
|
|
12
|
-
ret = orig_log(env, status, header, began_at)
|
|
13
|
-
@logger.flush if @logger.is_a?(Flapjack::AsyncLogger)
|
|
14
|
-
ret
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# from http://stackoverflow.com/questions/6427033/how-do-i-log-asynchronous-thinsinatrarack-requests
|
|
20
|
-
class AsyncLogger < ::Logger
|
|
21
|
-
|
|
22
|
-
attr_accessor :messages
|
|
23
|
-
|
|
24
|
-
def initialize(logdev, shift_age = 0, shift_size = 1048576)
|
|
25
|
-
@messages = {}
|
|
26
|
-
super(logdev, shift_age, shift_size)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def write(message)
|
|
30
|
-
stack << message
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def stack
|
|
34
|
-
# This is the important async awareness
|
|
35
|
-
# It stores messages for each fiber separately
|
|
36
|
-
@messages[Fiber.current.object_id] ||= []
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def flush
|
|
40
|
-
stack.each do |msg|
|
|
41
|
-
self.send(:"<<", msg)
|
|
42
|
-
end
|
|
43
|
-
@messages.delete(Fiber.current.object_id)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
end
|
data/lib/flapjack/redis_pool.rb
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require 'eventmachine'
|
|
4
|
-
# the redis/synchrony gems need to be required in this particular order, see
|
|
5
|
-
# the redis-rb README for details
|
|
6
|
-
require 'hiredis'
|
|
7
|
-
require 'em-synchrony'
|
|
8
|
-
require 'redis/connection/synchrony'
|
|
9
|
-
require 'redis'
|
|
10
|
-
|
|
11
|
-
require 'em-synchrony/connection_pool'
|
|
12
|
-
|
|
13
|
-
require 'flapjack/data/migration'
|
|
14
|
-
|
|
15
|
-
module Flapjack
|
|
16
|
-
class RedisPool < EventMachine::Synchrony::ConnectionPool
|
|
17
|
-
|
|
18
|
-
def initialize(opts = {})
|
|
19
|
-
config = opts.delete(:config)
|
|
20
|
-
@size = opts[:size] || 5
|
|
21
|
-
logger = opts[:logger]
|
|
22
|
-
super(:size => @size) {
|
|
23
|
-
redis = ::Redis.new(config)
|
|
24
|
-
Flapjack::Data::Migration.correct_notification_rule_contact_linkages(:redis => redis,
|
|
25
|
-
:logger => logger)
|
|
26
|
-
Flapjack::Data::Migration.migrate_entity_check_data_if_required(:redis => redis,
|
|
27
|
-
:logger => logger)
|
|
28
|
-
Flapjack::Data::Migration.create_entity_ids_if_required(:redis => redis,
|
|
29
|
-
:logger => logger)
|
|
30
|
-
Flapjack::Data::Migration.clear_orphaned_entity_ids(:redis => redis,
|
|
31
|
-
:logger => logger)
|
|
32
|
-
Flapjack::Data::Migration.refresh_archive_index(:redis => redis)
|
|
33
|
-
Flapjack::Data::Migration.validate_scheduled_maintenance_periods(:redis => redis,
|
|
34
|
-
:logger => logger)
|
|
35
|
-
Flapjack::Data::Migration.correct_rollup_including_disabled_checks(:redis => redis,
|
|
36
|
-
:logger => logger)
|
|
37
|
-
redis
|
|
38
|
-
}
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
end
|
|
@@ -1,1418 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
require 'flapjack/data/entity_check'
|
|
4
|
-
|
|
5
|
-
describe Flapjack::Data::EntityCheck, :redis => true do
|
|
6
|
-
|
|
7
|
-
let(:name) { 'abc-123' }
|
|
8
|
-
let(:check) { 'ping' }
|
|
9
|
-
|
|
10
|
-
let(:half_an_hour) { 30 * 60 }
|
|
11
|
-
let(:t) { Time.now.to_i }
|
|
12
|
-
let(:five_minutes) { 60 * 5 }
|
|
13
|
-
let(:five_hours_ago) { t - (60 * 60 * 5) }
|
|
14
|
-
let(:four_hours_ago) { t - (60 * 60 * 4) }
|
|
15
|
-
let(:three_hours_ago) { t - (60 * 60 * 3) }
|
|
16
|
-
let(:two_hours_ago) { t - (60 * 60 * 2) }
|
|
17
|
-
let(:one_hour) { 60 * 60 }
|
|
18
|
-
let(:two_hours) { 60 * 60 * 2 }
|
|
19
|
-
let(:three_hours) { 60 * 60 * 3 }
|
|
20
|
-
let(:five_hours) { 60 * 60 * 5 }
|
|
21
|
-
let(:seven_hours) { 60 * 60 * 7 }
|
|
22
|
-
|
|
23
|
-
before(:each) do
|
|
24
|
-
Flapjack::Data::Contact.add({ 'id' => '362',
|
|
25
|
-
'first_name' => 'John',
|
|
26
|
-
'last_name' => 'Johnson',
|
|
27
|
-
'email' => 'johnj@example.com' },
|
|
28
|
-
:redis => @redis)
|
|
29
|
-
|
|
30
|
-
Flapjack::Data::Entity.add({ 'id' => '5000',
|
|
31
|
-
'name' => name,
|
|
32
|
-
'contacts' => ['362'] },
|
|
33
|
-
:redis => @redis)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "is created for an event id" do
|
|
37
|
-
ec = Flapjack::Data::EntityCheck.for_event_id("#{name}:ping", :redis => @redis)
|
|
38
|
-
expect(ec).not_to be_nil
|
|
39
|
-
expect(ec.entity).not_to be_nil
|
|
40
|
-
expect(ec.entity.name).not_to be_nil
|
|
41
|
-
expect(ec.entity.name).to eq(name)
|
|
42
|
-
expect(ec.check).not_to be_nil
|
|
43
|
-
expect(ec.check).to eq('ping')
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "is created for an entity name" do
|
|
47
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, 'ping', :redis => @redis)
|
|
48
|
-
expect(ec).not_to be_nil
|
|
49
|
-
expect(ec.entity).not_to be_nil
|
|
50
|
-
expect(ec.entity.name).not_to be_nil
|
|
51
|
-
expect(ec.entity.name).to eq(name)
|
|
52
|
-
expect(ec.check).not_to be_nil
|
|
53
|
-
expect(ec.check).to eq('ping')
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "is created for an entity id" do
|
|
57
|
-
ec = Flapjack::Data::EntityCheck.for_entity_id(5000, 'ping', :redis => @redis)
|
|
58
|
-
expect(ec).not_to be_nil
|
|
59
|
-
expect(ec.entity).not_to be_nil
|
|
60
|
-
expect(ec.entity.name).not_to be_nil
|
|
61
|
-
expect(ec.entity.name).to eq(name)
|
|
62
|
-
expect(ec.check).not_to be_nil
|
|
63
|
-
expect(ec.check).to eq('ping')
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "is created for an entity object" do
|
|
67
|
-
e = Flapjack::Data::Entity.find_by_name(name, :redis => @redis)
|
|
68
|
-
ec = Flapjack::Data::EntityCheck.for_entity(e, 'ping', :redis => @redis)
|
|
69
|
-
expect(ec).not_to be_nil
|
|
70
|
-
expect(ec.entity).not_to be_nil
|
|
71
|
-
expect(ec.entity.name).not_to be_nil
|
|
72
|
-
expect(ec.entity.name).to eq(name)
|
|
73
|
-
expect(ec.check).not_to be_nil
|
|
74
|
-
expect(ec.check).to eq('ping')
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "is not created for a missing entity" do
|
|
78
|
-
expect {
|
|
79
|
-
Flapjack::Data::EntityCheck.for_entity(nil, 'ping', :redis => @redis)
|
|
80
|
-
}.to raise_error
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "raises an error if not created with a redis connection handle" do
|
|
84
|
-
expect {
|
|
85
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, 'ping')
|
|
86
|
-
}.to raise_error
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'registers with current_checks and current_entities if explicitly added' do
|
|
90
|
-
expect(@redis.zrange("current_checks:#{name}", 0, -1)).to eq([])
|
|
91
|
-
expect(@redis.zrange("current_entities", 0, -1)).to eq([])
|
|
92
|
-
|
|
93
|
-
check_data = {'entity_id' => '5000',
|
|
94
|
-
'name' => 'ssh'}
|
|
95
|
-
|
|
96
|
-
Flapjack::Data::EntityCheck.add(check_data, :redis => @redis)
|
|
97
|
-
|
|
98
|
-
expect(@redis.zrange("current_checks:#{name}", 0, -1)).to eq(["ssh"])
|
|
99
|
-
expect(@redis.zrange("current_entities", 0, -1)).to eq([name])
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it 'creates tags if passed when explicitly added' do
|
|
103
|
-
check_data = {'entity_id' => '5000',
|
|
104
|
-
'name' => 'ssh',
|
|
105
|
-
'tags' => ['virtual', 'staging']}
|
|
106
|
-
|
|
107
|
-
Flapjack::Data::EntityCheck.add(check_data, :redis => @redis)
|
|
108
|
-
|
|
109
|
-
entity_check = Flapjack::Data::EntityCheck.for_event_id("#{name}:ssh", :redis => @redis)
|
|
110
|
-
expect(entity_check).not_to be_nil
|
|
111
|
-
expect(entity_check.tags).to eq(Set.new(['abc-123', 'ssh', 'virtual', 'staging']))
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it "adds tags to checks" do
|
|
115
|
-
entity_check = Flapjack::Data::EntityCheck.for_entity_name(name, 'ping', :redis => @redis)
|
|
116
|
-
|
|
117
|
-
entity_check.add_tags('source:foobar', 'foo')
|
|
118
|
-
|
|
119
|
-
expect(entity_check.tags).to include("source:foobar")
|
|
120
|
-
expect(entity_check.tags).to include("foo")
|
|
121
|
-
|
|
122
|
-
# and test the tags as read back from redis
|
|
123
|
-
entity_check = Flapjack::Data::EntityCheck.for_event_id("#{name}:ping", :redis => @redis)
|
|
124
|
-
expect(entity_check.tags).to include("source:foobar")
|
|
125
|
-
expect(entity_check.tags).to include("foo")
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it "deletes tags from checks" do
|
|
129
|
-
entity_check = Flapjack::Data::EntityCheck.for_entity_name(name, 'ping', :redis => @redis)
|
|
130
|
-
|
|
131
|
-
entity_check.add_tags('source:foobar', 'foo')
|
|
132
|
-
|
|
133
|
-
expect(entity_check.tags).to include("source:foobar")
|
|
134
|
-
expect(entity_check.tags).to include("foo")
|
|
135
|
-
|
|
136
|
-
entity_check.delete_tags('source:foobar')
|
|
137
|
-
|
|
138
|
-
# and test the tags as read back from redis
|
|
139
|
-
entity_check = Flapjack::Data::EntityCheck.for_event_id("#{name}:ping", :redis => @redis)
|
|
140
|
-
expect(entity_check.tags).not_to include("source:foobar")
|
|
141
|
-
expect(entity_check.tags).to include("foo")
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context "maintenance" do
|
|
145
|
-
|
|
146
|
-
it "returns that it is in unscheduled maintenance" do
|
|
147
|
-
@redis.set("#{name}:#{check}:unscheduled_maintenance", Time.now.to_i.to_s)
|
|
148
|
-
|
|
149
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
150
|
-
expect(ec).to be_in_unscheduled_maintenance
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
it "returns that it is not in unscheduled maintenance" do
|
|
154
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
155
|
-
expect(ec).not_to be_in_unscheduled_maintenance
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
it "returns that it is in scheduled maintenance" do
|
|
159
|
-
@redis.set("#{name}:#{check}:scheduled_maintenance", Time.now.to_i.to_s)
|
|
160
|
-
|
|
161
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
162
|
-
expect(ec).to be_in_scheduled_maintenance
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
it "returns that it is not in scheduled maintenance" do
|
|
166
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
167
|
-
expect(ec).not_to be_in_scheduled_maintenance
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
it "returns its current maintenance period" do
|
|
171
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
172
|
-
expect(ec.current_maintenance(:scheduled => true)).to be_nil
|
|
173
|
-
|
|
174
|
-
t = Time.now.to_i
|
|
175
|
-
|
|
176
|
-
ec.create_unscheduled_maintenance(t, half_an_hour, :summary => 'oops')
|
|
177
|
-
expect(ec.current_maintenance).to eq(:start_time => t,
|
|
178
|
-
:duration => half_an_hour,
|
|
179
|
-
:summary => 'oops')
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "creates an unscheduled maintenance period" do
|
|
183
|
-
t = Time.now.to_i
|
|
184
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
185
|
-
ec.create_unscheduled_maintenance(t, half_an_hour, :summary => 'oops')
|
|
186
|
-
|
|
187
|
-
expect(ec).to be_in_unscheduled_maintenance
|
|
188
|
-
|
|
189
|
-
umps = ec.maintenances(nil, nil, :scheduled => false)
|
|
190
|
-
expect(umps).not_to be_nil
|
|
191
|
-
expect(umps).to be_an(Array)
|
|
192
|
-
expect(umps.size).to eq(1)
|
|
193
|
-
expect(umps[0]).to be_a(Hash)
|
|
194
|
-
|
|
195
|
-
start_time = umps[0][:start_time]
|
|
196
|
-
expect(start_time).not_to be_nil
|
|
197
|
-
expect(start_time).to be_an(Integer)
|
|
198
|
-
expect(start_time).to eq(t)
|
|
199
|
-
|
|
200
|
-
duration = umps[0][:duration]
|
|
201
|
-
expect(duration).not_to be_nil
|
|
202
|
-
expect(duration).to be_a(Float)
|
|
203
|
-
expect(duration).to eq(half_an_hour)
|
|
204
|
-
|
|
205
|
-
summary = @redis.get("#{name}:#{check}:#{t}:unscheduled_maintenance:summary")
|
|
206
|
-
expect(summary).not_to be_nil
|
|
207
|
-
expect(summary).to eq('oops')
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
it "creates an unscheduled maintenance period and ends the current one early", :time => true do
|
|
211
|
-
t = Time.now.to_i
|
|
212
|
-
later_t = t + (15 * 60)
|
|
213
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
214
|
-
ec.create_unscheduled_maintenance(t, half_an_hour, :summary => 'oops')
|
|
215
|
-
Delorean.time_travel_to(Time.at(later_t))
|
|
216
|
-
ec.create_unscheduled_maintenance(later_t, half_an_hour, :summary => 'spoo')
|
|
217
|
-
|
|
218
|
-
expect(ec).to be_in_unscheduled_maintenance
|
|
219
|
-
|
|
220
|
-
umps = ec.maintenances(nil, nil, :scheduled => false)
|
|
221
|
-
expect(umps).not_to be_nil
|
|
222
|
-
expect(umps).to be_an(Array)
|
|
223
|
-
expect(umps.size).to eq(2)
|
|
224
|
-
expect(umps[0]).to be_a(Hash)
|
|
225
|
-
|
|
226
|
-
start_time = umps[0][:start_time]
|
|
227
|
-
expect(start_time).not_to be_nil
|
|
228
|
-
expect(start_time).to be_an(Integer)
|
|
229
|
-
expect(start_time).to eq(t)
|
|
230
|
-
|
|
231
|
-
duration = umps[0][:duration]
|
|
232
|
-
expect(duration).not_to be_nil
|
|
233
|
-
expect(duration).to be_a(Float)
|
|
234
|
-
expect(duration).to eq(15 * 60)
|
|
235
|
-
|
|
236
|
-
start_time_curr = umps[1][:start_time]
|
|
237
|
-
expect(start_time_curr).not_to be_nil
|
|
238
|
-
expect(start_time_curr).to be_an(Integer)
|
|
239
|
-
expect(start_time_curr).to eq(later_t)
|
|
240
|
-
|
|
241
|
-
duration_curr = umps[1][:duration]
|
|
242
|
-
expect(duration_curr).not_to be_nil
|
|
243
|
-
expect(duration_curr).to be_a(Float)
|
|
244
|
-
expect(duration_curr).to eq(half_an_hour)
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
it "creates an unscheduled maintenance period from a human readable time" do
|
|
248
|
-
Flapjack::Data::EntityCheck.create_maintenance(:redis => @redis, :entity => name, :check => check, :type => 'unscheduled', :started => '14/3/2027 3pm', :duration => '30 minutes', :reason => 'oops')
|
|
249
|
-
t = Time.local(2027, 3, 14, 15, 0).to_i
|
|
250
|
-
|
|
251
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
252
|
-
expect(ec).to be_in_unscheduled_maintenance
|
|
253
|
-
|
|
254
|
-
umps = ec.maintenances(nil, nil, :scheduled => false)
|
|
255
|
-
expect(umps).not_to be_nil
|
|
256
|
-
expect(umps).to be_an(Array)
|
|
257
|
-
expect(umps.size).to eq(1)
|
|
258
|
-
expect(umps[0]).to be_a(Hash)
|
|
259
|
-
|
|
260
|
-
start_time = umps[0][:start_time]
|
|
261
|
-
expect(start_time).not_to be_nil
|
|
262
|
-
expect(start_time).to be_an(Integer)
|
|
263
|
-
expect(start_time).to eq(t)
|
|
264
|
-
|
|
265
|
-
duration = umps[0][:duration]
|
|
266
|
-
expect(duration).not_to be_nil
|
|
267
|
-
expect(duration).to be_a(Float)
|
|
268
|
-
expect(duration).to eq(1800.0)
|
|
269
|
-
|
|
270
|
-
summary = @redis.get("#{name}:#{check}:#{t}:unscheduled_maintenance:summary")
|
|
271
|
-
expect(summary).not_to be_nil
|
|
272
|
-
expect(summary).to eq('oops')
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
it "ends an unscheduled maintenance period", :time => true do
|
|
276
|
-
t = Time.now.to_i
|
|
277
|
-
later_t = t + (15 * 60)
|
|
278
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
279
|
-
|
|
280
|
-
ec.create_unscheduled_maintenance(t, half_an_hour, :summary => 'oops')
|
|
281
|
-
expect(ec).to be_in_unscheduled_maintenance
|
|
282
|
-
|
|
283
|
-
Delorean.time_travel_to(Time.at(later_t))
|
|
284
|
-
expect(ec).to be_in_unscheduled_maintenance
|
|
285
|
-
ec.end_unscheduled_maintenance(later_t)
|
|
286
|
-
expect(ec).not_to be_in_unscheduled_maintenance
|
|
287
|
-
|
|
288
|
-
umps = ec.maintenances(nil, nil, :scheduled => false)
|
|
289
|
-
expect(umps).not_to be_nil
|
|
290
|
-
expect(umps).to be_an(Array)
|
|
291
|
-
expect(umps.size).to eq(1)
|
|
292
|
-
expect(umps[0]).to be_a(Hash)
|
|
293
|
-
|
|
294
|
-
start_time = umps[0][:start_time]
|
|
295
|
-
expect(start_time).not_to be_nil
|
|
296
|
-
expect(start_time).to be_an(Integer)
|
|
297
|
-
expect(start_time).to eq(t)
|
|
298
|
-
|
|
299
|
-
duration = umps[0][:duration]
|
|
300
|
-
expect(duration).not_to be_nil
|
|
301
|
-
expect(duration).to be_a(Float)
|
|
302
|
-
expect(duration).to eq(15 * 60)
|
|
303
|
-
end
|
|
304
|
-
|
|
305
|
-
it "creates a scheduled maintenance period for a future time" do
|
|
306
|
-
t = Time.now.to_i
|
|
307
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
308
|
-
ec.create_scheduled_maintenance(t + (60 * 60),
|
|
309
|
-
half_an_hour, :summary => "30 minutes")
|
|
310
|
-
|
|
311
|
-
smps = ec.maintenances(nil, nil, :scheduled => true)
|
|
312
|
-
expect(smps).not_to be_nil
|
|
313
|
-
expect(smps).to be_an(Array)
|
|
314
|
-
expect(smps.size).to eq(1)
|
|
315
|
-
expect(smps[0]).to be_a(Hash)
|
|
316
|
-
|
|
317
|
-
start_time = smps[0][:start_time]
|
|
318
|
-
expect(start_time).not_to be_nil
|
|
319
|
-
expect(start_time).to be_an(Integer)
|
|
320
|
-
expect(start_time).to eq(t + (60 * 60))
|
|
321
|
-
|
|
322
|
-
duration = smps[0][:duration]
|
|
323
|
-
expect(duration).not_to be_nil
|
|
324
|
-
expect(duration).to be_a(Float)
|
|
325
|
-
expect(duration).to eq(half_an_hour)
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
it "creates a scheduled maintenance period covering the current time" do
|
|
329
|
-
t = Time.now.to_i
|
|
330
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
331
|
-
ec.create_scheduled_maintenance(t - (60 * 60),
|
|
332
|
-
2 * (60 * 60), :summary => "2 hours")
|
|
333
|
-
|
|
334
|
-
smps = ec.maintenances(nil, nil, :scheduled => true)
|
|
335
|
-
expect(smps).not_to be_nil
|
|
336
|
-
expect(smps).to be_an(Array)
|
|
337
|
-
expect(smps.size).to eq(1)
|
|
338
|
-
expect(smps[0]).to be_a(Hash)
|
|
339
|
-
|
|
340
|
-
start_time = smps[0][:start_time]
|
|
341
|
-
expect(start_time).not_to be_nil
|
|
342
|
-
expect(start_time).to be_an(Integer)
|
|
343
|
-
expect(start_time).to eq(t - (60 * 60))
|
|
344
|
-
|
|
345
|
-
duration = smps[0][:duration]
|
|
346
|
-
expect(duration).not_to be_nil
|
|
347
|
-
expect(duration).to be_a(Float)
|
|
348
|
-
expect(duration).to eq(2 * (60 * 60))
|
|
349
|
-
|
|
350
|
-
ttl = @redis.ttl("#{name}:#{check}:scheduled_maintenance")
|
|
351
|
-
expect(ttl).to be_within(20).of(60 * 60) # 20-second margin of error,
|
|
352
|
-
# should be large enough for a slow machine running the test -- duration
|
|
353
|
-
# is considered to start at the begininng of the period
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
it "creates an scheduled maintenance period from a human readable time" do
|
|
357
|
-
Flapjack::Data::EntityCheck.create_maintenance(:redis => @redis, :entity => name, :check => check, :type => 'scheduled', :started => '14/3/2027 3pm', :duration => '30 minutes', :reason => 'oops')
|
|
358
|
-
t = Time.local(2027, 3, 14, 15, 0).to_i
|
|
359
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
360
|
-
|
|
361
|
-
smps = ec.maintenances(nil, nil, :scheduled => true)
|
|
362
|
-
expect(smps).not_to be_nil
|
|
363
|
-
expect(smps).to be_an(Array)
|
|
364
|
-
expect(smps.size).to eq(1)
|
|
365
|
-
expect(smps[0]).to be_a(Hash)
|
|
366
|
-
|
|
367
|
-
start_time = smps[0][:start_time]
|
|
368
|
-
expect(start_time).not_to be_nil
|
|
369
|
-
expect(start_time).to be_an(Integer)
|
|
370
|
-
expect(start_time).to eq(t)
|
|
371
|
-
|
|
372
|
-
duration = smps[0][:duration]
|
|
373
|
-
expect(duration).not_to be_nil
|
|
374
|
-
expect(duration).to be_a(Float)
|
|
375
|
-
expect(duration).to eq(1800.0)
|
|
376
|
-
|
|
377
|
-
summary = @redis.get("#{name}:#{check}:#{t}:scheduled_maintenance:summary")
|
|
378
|
-
expect(summary).not_to be_nil
|
|
379
|
-
expect(summary).to eq('oops')
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
it "removes a scheduled maintenance period for a future time" do
|
|
383
|
-
t = Time.now.to_i
|
|
384
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
385
|
-
ec.create_scheduled_maintenance(t + (60 * 60),
|
|
386
|
-
2 * (60 * 60), :summary => "2 hours")
|
|
387
|
-
|
|
388
|
-
ec.end_scheduled_maintenance(t + (60 * 60))
|
|
389
|
-
|
|
390
|
-
smps = ec.maintenances(nil, nil, :scheduled => true)
|
|
391
|
-
expect(smps).not_to be_nil
|
|
392
|
-
expect(smps).to be_an(Array)
|
|
393
|
-
expect(smps).to be_empty
|
|
394
|
-
end
|
|
395
|
-
|
|
396
|
-
# maint period starts an hour from now, goes for two hours -- at 30 minutes into
|
|
397
|
-
# it we stop it, and its duration should be 30 minutes
|
|
398
|
-
it "shortens a scheduled maintenance period covering a current time", :time => true do
|
|
399
|
-
t = Time.now.to_i
|
|
400
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
401
|
-
ec.create_scheduled_maintenance(t + (60 * 60),
|
|
402
|
-
2 * (60 * 60), :summary => "2 hours")
|
|
403
|
-
|
|
404
|
-
Delorean.time_travel_to(Time.at(t + (90 * 60)))
|
|
405
|
-
|
|
406
|
-
ec.end_scheduled_maintenance(t + (60 * 60))
|
|
407
|
-
|
|
408
|
-
smps = ec.maintenances(nil, nil, :scheduled => true)
|
|
409
|
-
expect(smps).not_to be_nil
|
|
410
|
-
expect(smps).to be_an(Array)
|
|
411
|
-
expect(smps).not_to be_empty
|
|
412
|
-
expect(smps.size).to eq(1)
|
|
413
|
-
expect(smps.first[:duration]).to eq(30 * 60)
|
|
414
|
-
end
|
|
415
|
-
|
|
416
|
-
it "does not alter or remove a scheduled maintenance period covering a past time", :time => true do
|
|
417
|
-
t = Time.now.to_i
|
|
418
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
419
|
-
ec.create_scheduled_maintenance(t + (60 * 60),
|
|
420
|
-
2 * (60 * 60), :summary => "2 hours")
|
|
421
|
-
|
|
422
|
-
Delorean.time_travel_to(Time.at(t + (6 * (60 * 60))))
|
|
423
|
-
|
|
424
|
-
ec.end_scheduled_maintenance(t + (60 * 60))
|
|
425
|
-
|
|
426
|
-
smps = ec.maintenances(nil, nil, :scheduled => true)
|
|
427
|
-
expect(smps).not_to be_nil
|
|
428
|
-
expect(smps).to be_an(Array)
|
|
429
|
-
expect(smps).not_to be_empty
|
|
430
|
-
expect(smps.size).to eq(1)
|
|
431
|
-
expect(smps.first[:duration]).to eq(2 * (60 * 60))
|
|
432
|
-
end
|
|
433
|
-
|
|
434
|
-
it "returns a list of scheduled maintenance periods" do
|
|
435
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
436
|
-
ec.create_scheduled_maintenance(five_hours_ago, half_an_hour,
|
|
437
|
-
:summary => "first")
|
|
438
|
-
ec.create_scheduled_maintenance(three_hours_ago, half_an_hour,
|
|
439
|
-
:summary => "second")
|
|
440
|
-
|
|
441
|
-
smp = ec.maintenances(nil, nil, :scheduled => true)
|
|
442
|
-
expect(smp).not_to be_nil
|
|
443
|
-
expect(smp).to be_an(Array)
|
|
444
|
-
expect(smp.size).to eq(2)
|
|
445
|
-
expect(smp[0]).to eq(:start_time => five_hours_ago,
|
|
446
|
-
:end_time => five_hours_ago + half_an_hour,
|
|
447
|
-
:duration => half_an_hour,
|
|
448
|
-
:summary => "first")
|
|
449
|
-
expect(smp[1]).to eq(:start_time => three_hours_ago,
|
|
450
|
-
:end_time => three_hours_ago + half_an_hour,
|
|
451
|
-
:duration => half_an_hour,
|
|
452
|
-
:summary => "second")
|
|
453
|
-
end
|
|
454
|
-
|
|
455
|
-
it "returns a list of unscheduled maintenance periods" do
|
|
456
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
457
|
-
ec.create_unscheduled_maintenance(five_hours_ago,
|
|
458
|
-
half_an_hour, :summary => "first")
|
|
459
|
-
ec.create_unscheduled_maintenance(three_hours_ago,
|
|
460
|
-
half_an_hour, :summary => "second")
|
|
461
|
-
|
|
462
|
-
ump = ec.maintenances(nil, nil, :scheduled => false)
|
|
463
|
-
expect(ump).not_to be_nil
|
|
464
|
-
expect(ump).to be_an(Array)
|
|
465
|
-
expect(ump.size).to eq(2)
|
|
466
|
-
expect(ump[0]).to eq(:start_time => five_hours_ago,
|
|
467
|
-
:end_time => five_hours_ago + half_an_hour,
|
|
468
|
-
:duration => half_an_hour,
|
|
469
|
-
:summary => "first")
|
|
470
|
-
expect(ump[1]).to eq(:start_time => three_hours_ago,
|
|
471
|
-
:end_time => three_hours_ago + half_an_hour,
|
|
472
|
-
:duration => half_an_hour,
|
|
473
|
-
:summary => "second")
|
|
474
|
-
end
|
|
475
|
-
|
|
476
|
-
it "finds current scheduled maintenance periods for multiple entities" do
|
|
477
|
-
ec = nil
|
|
478
|
-
|
|
479
|
-
%w(alpha lima bravo).each do |entity|
|
|
480
|
-
Flapjack::Data::Entity.add({ 'name' => entity }, :redis => @redis)
|
|
481
|
-
|
|
482
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(entity, check, :redis => @redis)
|
|
483
|
-
ec.create_scheduled_maintenance(five_hours_ago, seven_hours,
|
|
484
|
-
:summary => "Test scheduled maintenance for #{entity}")
|
|
485
|
-
end
|
|
486
|
-
|
|
487
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis,
|
|
488
|
-
:type => 'scheduled', :finishing => 'more than 0 minutes from now').sort_by { |k| k[:entity] }
|
|
489
|
-
|
|
490
|
-
expect(smp).to be_an(Array)
|
|
491
|
-
expect(smp.size).to eq(3)
|
|
492
|
-
%w(alpha bravo lima).each_with_index do |entity, index|
|
|
493
|
-
expect(smp[index]).to eq(:entity => entity,
|
|
494
|
-
:check => "ping",
|
|
495
|
-
# The state here is nil due to no check having gone
|
|
496
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
497
|
-
:state => nil,
|
|
498
|
-
:start_time => five_hours_ago,
|
|
499
|
-
:end_time => five_hours_ago + seven_hours,
|
|
500
|
-
:duration => seven_hours,
|
|
501
|
-
:summary => "Test scheduled maintenance for #{entity}")
|
|
502
|
-
end
|
|
503
|
-
end
|
|
504
|
-
|
|
505
|
-
it "finds current unscheduled maintenance periods for multiple entities" do
|
|
506
|
-
ec = nil
|
|
507
|
-
|
|
508
|
-
%w(alpha bravo lima).each do |entity|
|
|
509
|
-
Flapjack::Data::Entity.add({ 'name' => entity }, :redis => @redis)
|
|
510
|
-
|
|
511
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(entity, check, :redis => @redis)
|
|
512
|
-
ec.create_unscheduled_maintenance(five_hours_ago, seven_hours, :summary => "Test unscheduled maintenance for #{entity}")
|
|
513
|
-
end
|
|
514
|
-
|
|
515
|
-
ump = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'unscheduled', :finishing => 'more than 0 minutes from now').sort_by { |k| k[:entity] }
|
|
516
|
-
|
|
517
|
-
expect(ump).not_to be_nil
|
|
518
|
-
expect(ump).to be_an(Array)
|
|
519
|
-
expect(ump.size).to eq(3)
|
|
520
|
-
%w(alpha bravo lima).each_with_index do |entity, index|
|
|
521
|
-
expect(ump[index]).to eq(:entity => entity,
|
|
522
|
-
:check => "ping",
|
|
523
|
-
# The state here is nil due to no check having gone
|
|
524
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
525
|
-
:state => nil,
|
|
526
|
-
:start_time => five_hours_ago,
|
|
527
|
-
:end_time => five_hours_ago + seven_hours,
|
|
528
|
-
:duration => seven_hours,
|
|
529
|
-
:summary => "Test unscheduled maintenance for #{entity}")
|
|
530
|
-
end
|
|
531
|
-
end
|
|
532
|
-
|
|
533
|
-
it "finds all scheduled maintenance starting more than 3 hours ago" do
|
|
534
|
-
['more than three hours ago', 'before 3 hours ago'].each do |input|
|
|
535
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
536
|
-
|
|
537
|
-
# Maintenance in the past, now ended
|
|
538
|
-
ec.create_scheduled_maintenance(five_hours_ago, half_an_hour, :summary => "30 minute maintenance")
|
|
539
|
-
# Maintenance started in the past, still running
|
|
540
|
-
ec.create_scheduled_maintenance(three_hours_ago + five_minutes, seven_hours, :summary => "Scheduled maintenance started 3 hours ago")
|
|
541
|
-
ec.create_scheduled_maintenance(four_hours_ago, seven_hours, :summary => "Scheduled maintenance started 4 hours ago")
|
|
542
|
-
|
|
543
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis,
|
|
544
|
-
:type => 'scheduled', :started => input).sort_by { |k| k[:entity] }
|
|
545
|
-
|
|
546
|
-
expect(smp).to be_an(Array)
|
|
547
|
-
expect(smp.size).to eq(2)
|
|
548
|
-
|
|
549
|
-
expect(smp[0]).to eq(:entity => name,
|
|
550
|
-
:check => check,
|
|
551
|
-
# The state here is nil due to no check having gone
|
|
552
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
553
|
-
:state => nil,
|
|
554
|
-
:start_time => five_hours_ago,
|
|
555
|
-
:end_time => five_hours_ago + half_an_hour,
|
|
556
|
-
:duration => half_an_hour,
|
|
557
|
-
:summary => "30 minute maintenance")
|
|
558
|
-
expect(smp[1]).to eq(:entity => name,
|
|
559
|
-
:check => check,
|
|
560
|
-
# The state here is nil due to no check having gone
|
|
561
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
562
|
-
:state => nil,
|
|
563
|
-
:start_time => four_hours_ago,
|
|
564
|
-
:end_time => four_hours_ago + seven_hours,
|
|
565
|
-
:duration => seven_hours,
|
|
566
|
-
:summary => "Scheduled maintenance started 4 hours ago")
|
|
567
|
-
end
|
|
568
|
-
end
|
|
569
|
-
|
|
570
|
-
it "finds all scheduled maintenance starting within the next four hours" do
|
|
571
|
-
['less than four hours ago', 'after 4 hours ago'].each do |input|
|
|
572
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
573
|
-
|
|
574
|
-
# Maintenance in the past, now ended
|
|
575
|
-
ec.create_scheduled_maintenance(five_hours_ago, half_an_hour, :summary => "30 minute maintenance")
|
|
576
|
-
# Maintenance started in the past, still running
|
|
577
|
-
ec.create_scheduled_maintenance(three_hours_ago, seven_hours, :summary => "Scheduled maintenance started 3 hours ago")
|
|
578
|
-
ec.create_scheduled_maintenance(four_hours_ago, seven_hours, :summary => "Scheduled maintenance started 4 hours ago")
|
|
579
|
-
|
|
580
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :started => input).sort_by { |k| k[:entity] }
|
|
581
|
-
|
|
582
|
-
expect(smp).to be_an(Array)
|
|
583
|
-
expect(smp.size).to eq(1)
|
|
584
|
-
|
|
585
|
-
expect(smp[0]).to eq(:entity => name,
|
|
586
|
-
:check => check,
|
|
587
|
-
# The state here is nil due to no check having gone
|
|
588
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
589
|
-
:state => nil,
|
|
590
|
-
:start_time => three_hours_ago,
|
|
591
|
-
:end_time => three_hours_ago + seven_hours,
|
|
592
|
-
:duration => seven_hours,
|
|
593
|
-
:summary => "Scheduled maintenance started 3 hours ago")
|
|
594
|
-
end
|
|
595
|
-
end
|
|
596
|
-
|
|
597
|
-
it "finds all scheduled maintenance ending within the next two hours" do
|
|
598
|
-
['less than two hours', 'before 2 hours'].each do |input|
|
|
599
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
600
|
-
# Maintenance in the past, now ended
|
|
601
|
-
ec.create_scheduled_maintenance(two_hours_ago + five_minutes, half_an_hour, :summary => "Scheduled maintenance started 3 hours ago")
|
|
602
|
-
# Maintenance started in the past, still running
|
|
603
|
-
ec.create_scheduled_maintenance(three_hours_ago, seven_hours, :summary => "Scheduled maintenance started 3 hours ago for 7 hours")
|
|
604
|
-
ec.create_scheduled_maintenance(five_hours_ago, seven_hours + five_minutes, :summary => "Scheduled maintenance started 5 hours ago")
|
|
605
|
-
# Current maintenance
|
|
606
|
-
ec.create_scheduled_maintenance(t, half_an_hour, :summary => "Scheduled maintenance started now")
|
|
607
|
-
# Future maintenance
|
|
608
|
-
ec.create_scheduled_maintenance(t + five_minutes, half_an_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
609
|
-
|
|
610
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :finishing => input).sort_by { |k| k[:entity] }
|
|
611
|
-
|
|
612
|
-
expect(smp).to be_an(Array)
|
|
613
|
-
expect(smp.size).to eq(3)
|
|
614
|
-
|
|
615
|
-
expect(smp[0]).to eq(:entity => name,
|
|
616
|
-
:check => check,
|
|
617
|
-
# The state here is nil due to no check having gone
|
|
618
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
619
|
-
:state => nil,
|
|
620
|
-
:start_time => two_hours_ago + five_minutes,
|
|
621
|
-
:end_time => two_hours_ago + five_minutes + half_an_hour,
|
|
622
|
-
:duration => half_an_hour,
|
|
623
|
-
:summary => "Scheduled maintenance started 3 hours ago")
|
|
624
|
-
expect(smp[1]).to eq(:entity => name,
|
|
625
|
-
:check => check,
|
|
626
|
-
# The state here is nil due to no check having gone
|
|
627
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
628
|
-
:state => nil,
|
|
629
|
-
:start_time => t,
|
|
630
|
-
:end_time => t + half_an_hour,
|
|
631
|
-
:duration => half_an_hour,
|
|
632
|
-
:summary => "Scheduled maintenance started now")
|
|
633
|
-
expect(smp[2]).to eq(:entity => name,
|
|
634
|
-
:check => check,
|
|
635
|
-
# The state here is nil due to no check having gone
|
|
636
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
637
|
-
:state => nil,
|
|
638
|
-
:start_time => t + five_minutes,
|
|
639
|
-
:end_time => t + five_minutes + half_an_hour,
|
|
640
|
-
:duration => half_an_hour,
|
|
641
|
-
:summary => "Scheduled maintenance starting in 5 minutes")
|
|
642
|
-
end
|
|
643
|
-
end
|
|
644
|
-
|
|
645
|
-
it "finds all scheduled maintenance ending between two times (1 hour ago - 2 hours ago)" do
|
|
646
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
647
|
-
# Maintenance in the past, now ended
|
|
648
|
-
ec.create_scheduled_maintenance(two_hours_ago + five_minutes, half_an_hour, :summary => "Scheduled maintenance started 1 hour, 55 minutes ago")
|
|
649
|
-
# Maintenance started in the past, still running
|
|
650
|
-
ec.create_scheduled_maintenance(three_hours_ago, seven_hours, :summary => "Scheduled maintenance started 3 hours ago for 7 hours")
|
|
651
|
-
ec.create_scheduled_maintenance(five_hours_ago, three_hours + five_minutes, :summary => "Scheduled maintenance started 5 hours ago")
|
|
652
|
-
# Future maintenance
|
|
653
|
-
ec.create_scheduled_maintenance(t + five_minutes, half_an_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
654
|
-
|
|
655
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :finishing => 'between one and two hours ago').sort_by { |k| k[:entity] }
|
|
656
|
-
|
|
657
|
-
expect(smp).to be_an(Array)
|
|
658
|
-
expect(smp.size).to eq(2)
|
|
659
|
-
|
|
660
|
-
expect(smp[0]).to eq(:entity => name,
|
|
661
|
-
:check => check,
|
|
662
|
-
# The state here is nil due to no check having gone
|
|
663
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
664
|
-
:state => nil,
|
|
665
|
-
:start_time => five_hours_ago,
|
|
666
|
-
:end_time => five_hours_ago + three_hours + five_minutes,
|
|
667
|
-
:duration => three_hours + five_minutes,
|
|
668
|
-
:summary => "Scheduled maintenance started 5 hours ago")
|
|
669
|
-
expect(smp[1]).to eq(:entity => name,
|
|
670
|
-
:check => check,
|
|
671
|
-
# The state here is nil due to no check having gone
|
|
672
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
673
|
-
:state => nil,
|
|
674
|
-
:start_time => two_hours_ago + five_minutes,
|
|
675
|
-
:end_time => two_hours_ago + five_minutes + half_an_hour,
|
|
676
|
-
:duration => half_an_hour,
|
|
677
|
-
:summary => "Scheduled maintenance started 1 hour, 55 minutes ago")
|
|
678
|
-
end
|
|
679
|
-
|
|
680
|
-
it "finds all scheduled maintenance ending between two times (1 hour from now - 2 hours from now)" do
|
|
681
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
682
|
-
# Maintenance in the past, now ended
|
|
683
|
-
ec.create_scheduled_maintenance(two_hours_ago + five_minutes, half_an_hour, :summary => "Scheduled maintenance started 1 hour, 55 minutes ago")
|
|
684
|
-
# Maintenance started in the past, still running
|
|
685
|
-
ec.create_scheduled_maintenance(three_hours_ago, five_hours - five_minutes, :summary => "Scheduled maintenance started 3 hours ago for 4 hours, 25 minutes")
|
|
686
|
-
ec.create_scheduled_maintenance(five_hours_ago, three_hours + five_minutes, :summary => "Scheduled maintenance started 5 hours ago")
|
|
687
|
-
# Future maintenance
|
|
688
|
-
ec.create_scheduled_maintenance(t + five_minutes, one_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
689
|
-
|
|
690
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :finishing => 'between one and two hours').sort_by { |k| k[:entity] }
|
|
691
|
-
|
|
692
|
-
expect(smp).to be_an(Array)
|
|
693
|
-
expect(smp.size).to eq(2)
|
|
694
|
-
|
|
695
|
-
expect(smp[0]).to eq(:entity => name,
|
|
696
|
-
:check => check,
|
|
697
|
-
# The state here is nil due to no check having gone
|
|
698
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
699
|
-
:state => nil,
|
|
700
|
-
:start_time => three_hours_ago,
|
|
701
|
-
:end_time => three_hours_ago + five_hours - five_minutes,
|
|
702
|
-
:duration => five_hours - five_minutes,
|
|
703
|
-
:summary => "Scheduled maintenance started 3 hours ago for 4 hours, 25 minutes")
|
|
704
|
-
expect(smp[1]).to eq(:entity => name,
|
|
705
|
-
:check => check,
|
|
706
|
-
# The state here is nil due to no check having gone
|
|
707
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
708
|
-
:state => nil,
|
|
709
|
-
:start_time => t + five_minutes,
|
|
710
|
-
:end_time => t + five_minutes + one_hour,
|
|
711
|
-
:duration => one_hour,
|
|
712
|
-
:summary => "Scheduled maintenance starting in 5 minutes")
|
|
713
|
-
end
|
|
714
|
-
|
|
715
|
-
it "finds all scheduled maintenance ending in more than two hours" do
|
|
716
|
-
['more than two hours', 'after 2 hours'].each do |input|
|
|
717
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
718
|
-
# Maintenance in the past, now ended
|
|
719
|
-
ec.create_scheduled_maintenance(two_hours_ago, half_an_hour, :summary => "Scheduled maintenance started 2 hours ago")
|
|
720
|
-
# Maintenance started in the past, still running
|
|
721
|
-
ec.create_scheduled_maintenance(three_hours_ago, seven_hours, :summary => "Scheduled maintenance started 3 hours ago for 7 hours")
|
|
722
|
-
ec.create_scheduled_maintenance(five_hours_ago, seven_hours, :summary => "Scheduled maintenance started 5 hours ago")
|
|
723
|
-
# Current maintenance
|
|
724
|
-
ec.create_scheduled_maintenance(t, half_an_hour, :summary => "Scheduled maintenance started now")
|
|
725
|
-
# Future maintenance
|
|
726
|
-
ec.create_scheduled_maintenance(t + five_minutes, half_an_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
727
|
-
|
|
728
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :finishing => input).sort_by { |k| k[:entity] }
|
|
729
|
-
|
|
730
|
-
expect(smp).to be_an(Array)
|
|
731
|
-
expect(smp.size).to eq(1)
|
|
732
|
-
|
|
733
|
-
expect(smp[0]).to eq(:entity => name,
|
|
734
|
-
:check => check,
|
|
735
|
-
# The state here is nil due to no check having gone
|
|
736
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
737
|
-
:state => nil,
|
|
738
|
-
:start_time => three_hours_ago,
|
|
739
|
-
:end_time => three_hours_ago + seven_hours,
|
|
740
|
-
:duration => seven_hours,
|
|
741
|
-
:summary => "Scheduled maintenance started 3 hours ago for 7 hours")
|
|
742
|
-
end
|
|
743
|
-
end
|
|
744
|
-
|
|
745
|
-
it "finds all scheduled maintenance with a duration of less than one hour" do
|
|
746
|
-
['less than', 'before'].each do |input|
|
|
747
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
748
|
-
# Maintenance in the past, now ended
|
|
749
|
-
ec.create_scheduled_maintenance(two_hours_ago, half_an_hour, :summary => "Scheduled maintenance started 3 hours ago")
|
|
750
|
-
# Maintenance started in the past, still running
|
|
751
|
-
ec.create_scheduled_maintenance(three_hours_ago, seven_hours, :summary => "Scheduled maintenance started 3 hours ago for 7 hours")
|
|
752
|
-
ec.create_scheduled_maintenance(five_hours_ago, seven_hours, :summary => "Scheduled maintenance started 5 hours ago")
|
|
753
|
-
# Current maintenance
|
|
754
|
-
ec.create_scheduled_maintenance(t, half_an_hour, :summary => "Scheduled maintenance started now")
|
|
755
|
-
# Future maintenance
|
|
756
|
-
ec.create_scheduled_maintenance(t + five_minutes, half_an_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
757
|
-
|
|
758
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :duration => "#{input} one hour").sort_by { |k| k[:entity] }
|
|
759
|
-
|
|
760
|
-
expect(smp).to be_an(Array)
|
|
761
|
-
expect(smp.size).to eq(3)
|
|
762
|
-
|
|
763
|
-
expect(smp[0]).to eq(:entity => name,
|
|
764
|
-
:check => check,
|
|
765
|
-
# The state here is nil due to no check having gone
|
|
766
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
767
|
-
:state => nil,
|
|
768
|
-
:start_time => two_hours_ago,
|
|
769
|
-
:end_time => two_hours_ago + half_an_hour,
|
|
770
|
-
:duration => half_an_hour,
|
|
771
|
-
:summary => "Scheduled maintenance started 3 hours ago")
|
|
772
|
-
expect(smp[1]).to eq(:entity => name,
|
|
773
|
-
:check => check,
|
|
774
|
-
# The state here is nil due to no check having gone
|
|
775
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
776
|
-
:state => nil,
|
|
777
|
-
:start_time => t,
|
|
778
|
-
:end_time => t + half_an_hour,
|
|
779
|
-
:duration => half_an_hour,
|
|
780
|
-
:summary => "Scheduled maintenance started now")
|
|
781
|
-
expect(smp[2]).to eq(:entity => name,
|
|
782
|
-
:check => check,
|
|
783
|
-
# The state here is nil due to no check having gone
|
|
784
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
785
|
-
:state => nil,
|
|
786
|
-
:start_time => t + five_minutes,
|
|
787
|
-
:end_time => t + five_minutes + half_an_hour,
|
|
788
|
-
:duration => half_an_hour,
|
|
789
|
-
:summary => "Scheduled maintenance starting in 5 minutes")
|
|
790
|
-
end
|
|
791
|
-
end
|
|
792
|
-
|
|
793
|
-
it "finds all scheduled maintenance with a duration of 30 minutes" do
|
|
794
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
795
|
-
# Maintenance in the past, now ended
|
|
796
|
-
ec.create_scheduled_maintenance(two_hours_ago, half_an_hour, :summary => "Scheduled maintenance started 3 hours ago")
|
|
797
|
-
# Maintenance started in the past, still running
|
|
798
|
-
ec.create_scheduled_maintenance(three_hours_ago, seven_hours, :summary => "Scheduled maintenance started 3 hours ago for 7 hours")
|
|
799
|
-
ec.create_scheduled_maintenance(five_hours_ago, seven_hours, :summary => "Scheduled maintenance started 5 hours ago")
|
|
800
|
-
# Current maintenance
|
|
801
|
-
ec.create_scheduled_maintenance(t, half_an_hour, :summary => "Scheduled maintenance started now")
|
|
802
|
-
# Future maintenance
|
|
803
|
-
ec.create_scheduled_maintenance(t + five_minutes, half_an_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
804
|
-
|
|
805
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :duration => '30 minutes').sort_by { |k| k[:entity] }
|
|
806
|
-
|
|
807
|
-
expect(smp).to be_an(Array)
|
|
808
|
-
expect(smp.size).to eq(3)
|
|
809
|
-
|
|
810
|
-
expect(smp[0]).to eq(:entity => name,
|
|
811
|
-
:check => check,
|
|
812
|
-
# The state here is nil due to no check having gone
|
|
813
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
814
|
-
:state => nil,
|
|
815
|
-
:start_time => two_hours_ago,
|
|
816
|
-
:end_time => two_hours_ago + half_an_hour,
|
|
817
|
-
:duration => half_an_hour,
|
|
818
|
-
:summary => "Scheduled maintenance started 3 hours ago")
|
|
819
|
-
expect(smp[1]).to eq(:entity => name,
|
|
820
|
-
:check => check,
|
|
821
|
-
# The state here is nil due to no check having gone
|
|
822
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
823
|
-
:state => nil,
|
|
824
|
-
:start_time => t,
|
|
825
|
-
:end_time => t + half_an_hour,
|
|
826
|
-
:duration => half_an_hour,
|
|
827
|
-
:summary => "Scheduled maintenance started now")
|
|
828
|
-
expect(smp[2]).to eq(:entity => name,
|
|
829
|
-
:check => check,
|
|
830
|
-
# The state here is nil due to no check having gone
|
|
831
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
832
|
-
:state => nil,
|
|
833
|
-
:start_time => t + five_minutes,
|
|
834
|
-
:end_time => t + five_minutes + half_an_hour,
|
|
835
|
-
:duration => half_an_hour,
|
|
836
|
-
:summary => "Scheduled maintenance starting in 5 minutes")
|
|
837
|
-
end
|
|
838
|
-
|
|
839
|
-
it "finds all scheduled maintenance with a duration of between 15 and 65 minutes" do
|
|
840
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
841
|
-
# Maintenance in the past, now ended
|
|
842
|
-
ec.create_scheduled_maintenance(two_hours_ago, half_an_hour, :summary => "Scheduled maintenance started 3 hours ago")
|
|
843
|
-
# Maintenance started in the past, still running
|
|
844
|
-
ec.create_scheduled_maintenance(three_hours_ago, seven_hours, :summary => "Scheduled maintenance started 3 hours ago for 7 hours")
|
|
845
|
-
ec.create_scheduled_maintenance(five_hours_ago, one_hour, :summary => "Scheduled maintenance started 5 hours ago")
|
|
846
|
-
# Current maintenance
|
|
847
|
-
ec.create_scheduled_maintenance(t, half_an_hour, :summary => "Scheduled maintenance started now")
|
|
848
|
-
# Future maintenance
|
|
849
|
-
ec.create_scheduled_maintenance(t + five_minutes, half_an_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
850
|
-
|
|
851
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :duration => 'between 15 and 65 minutes').sort_by { |k| k[:entity] }
|
|
852
|
-
|
|
853
|
-
expect(smp).to be_an(Array)
|
|
854
|
-
expect(smp.size).to eq(4)
|
|
855
|
-
|
|
856
|
-
expect(smp[1]).to eq(:entity => name,
|
|
857
|
-
:check => check,
|
|
858
|
-
# The state here is nil due to no check having gone
|
|
859
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
860
|
-
:state => nil,
|
|
861
|
-
:start_time => two_hours_ago,
|
|
862
|
-
:end_time => two_hours_ago + half_an_hour,
|
|
863
|
-
:duration => half_an_hour,
|
|
864
|
-
:summary => "Scheduled maintenance started 3 hours ago")
|
|
865
|
-
expect(smp[0]).to eq(:entity => name,
|
|
866
|
-
:check => check,
|
|
867
|
-
# The state here is nil due to no check having gone
|
|
868
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
869
|
-
:state => nil,
|
|
870
|
-
:start_time => five_hours_ago,
|
|
871
|
-
:end_time => five_hours_ago + one_hour,
|
|
872
|
-
:duration => one_hour,
|
|
873
|
-
:summary => "Scheduled maintenance started 5 hours ago")
|
|
874
|
-
expect(smp[2]).to eq(:entity => name,
|
|
875
|
-
:check => check,
|
|
876
|
-
# The state here is nil due to no check having gone
|
|
877
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
878
|
-
:state => nil,
|
|
879
|
-
:start_time => t,
|
|
880
|
-
:end_time => t + half_an_hour,
|
|
881
|
-
:duration => half_an_hour,
|
|
882
|
-
:summary => "Scheduled maintenance started now")
|
|
883
|
-
expect(smp[3]).to eq(:entity => name,
|
|
884
|
-
:check => check,
|
|
885
|
-
# The state here is nil due to no check having gone
|
|
886
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
887
|
-
:state => nil,
|
|
888
|
-
:start_time => t + five_minutes,
|
|
889
|
-
:end_time => t + five_minutes + half_an_hour,
|
|
890
|
-
:duration => half_an_hour,
|
|
891
|
-
:summary => "Scheduled maintenance starting in 5 minutes")
|
|
892
|
-
end
|
|
893
|
-
|
|
894
|
-
it "finds all scheduled maintenance with a duration of more than one hour" do
|
|
895
|
-
['more than, after'].each do |input|
|
|
896
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
897
|
-
# Maintenance in the past, now ended
|
|
898
|
-
ec.create_scheduled_maintenance(two_hours_ago, half_an_hour, :summary => "Scheduled maintenance started 3 hours ago")
|
|
899
|
-
# Maintenance started in the past, still running
|
|
900
|
-
ec.create_scheduled_maintenance(three_hours_ago, seven_hours, :summary => "Scheduled maintenance started 3 hours ago for 7 hours")
|
|
901
|
-
ec.create_scheduled_maintenance(five_hours_ago, seven_hours, :summary => "Scheduled maintenance started 5 hours ago")
|
|
902
|
-
# Current maintenance
|
|
903
|
-
ec.create_scheduled_maintenance(t, half_an_hour, :summary => "Scheduled maintenance started now")
|
|
904
|
-
# Future maintenance
|
|
905
|
-
ec.create_scheduled_maintenance(t + five_minutes, half_an_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
906
|
-
|
|
907
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :duration => "#{input} one hour").sort_by { |k| k[:entity] }
|
|
908
|
-
|
|
909
|
-
expect(smp).to be_an(Array)
|
|
910
|
-
expect(smp.size).to eq(2)
|
|
911
|
-
|
|
912
|
-
expect(smp[0]).to eq(:entity => name,
|
|
913
|
-
:check => check,
|
|
914
|
-
# The state here is nil due to no check having gone
|
|
915
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
916
|
-
:state => nil,
|
|
917
|
-
:start_time => five_hours_ago,
|
|
918
|
-
:end_time => five_hours_ago + seven_hours,
|
|
919
|
-
:duration => seven_hours,
|
|
920
|
-
:summary => "Scheduled maintenance started 5 hours ago")
|
|
921
|
-
expect(smp[1]).to eq(:entity => name,
|
|
922
|
-
:check => check,
|
|
923
|
-
# The state here is nil due to no check having gone
|
|
924
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
925
|
-
:state => nil,
|
|
926
|
-
:start_time => three_hours_ago,
|
|
927
|
-
:end_time => three_hours_ago + seven_hours,
|
|
928
|
-
:duration => seven_hours,
|
|
929
|
-
:summary => "Scheduled maintenance started 3 hours ago for 7 hours")
|
|
930
|
-
end
|
|
931
|
-
end
|
|
932
|
-
|
|
933
|
-
it "finds all scheduled maintenance with a particular entity name" do
|
|
934
|
-
['bravo', 'br.*'].each do |input|
|
|
935
|
-
%w(alpha bravo lima).each do |entity|
|
|
936
|
-
Flapjack::Data::Entity.add({ 'name' => entity }, :redis => @redis)
|
|
937
|
-
|
|
938
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(entity, check, :redis => @redis)
|
|
939
|
-
ec.create_scheduled_maintenance(five_hours_ago, seven_hours, :summary => "Test scheduled maintenance for #{entity}")
|
|
940
|
-
end
|
|
941
|
-
|
|
942
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :entity => input ).sort_by { |k| k[:entity] }
|
|
943
|
-
|
|
944
|
-
expect(smp).to be_an(Array)
|
|
945
|
-
expect(smp.size).to eq(1)
|
|
946
|
-
expect(smp[0]).to eq(:entity => "bravo",
|
|
947
|
-
:check => check,
|
|
948
|
-
# The state here is nil due to no check having gone
|
|
949
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
950
|
-
:state => nil,
|
|
951
|
-
:start_time => five_hours_ago,
|
|
952
|
-
:end_time => five_hours_ago + seven_hours,
|
|
953
|
-
:duration => seven_hours,
|
|
954
|
-
:summary => "Test scheduled maintenance for bravo")
|
|
955
|
-
end
|
|
956
|
-
end
|
|
957
|
-
|
|
958
|
-
it "finds all scheduled maintenance with a particular check name" do
|
|
959
|
-
['http', 'ht.*'].each do |input|
|
|
960
|
-
%w(ping http ssh).each do |check|
|
|
961
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
962
|
-
ec.create_scheduled_maintenance(five_hours_ago, seven_hours, :summary => "Test scheduled maintenance for #{check}")
|
|
963
|
-
end
|
|
964
|
-
|
|
965
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :check => input ).sort_by { |k| k[:entity] }
|
|
966
|
-
|
|
967
|
-
expect(smp).to be_an(Array)
|
|
968
|
-
expect(smp.size).to eq(1)
|
|
969
|
-
expect(smp[0]).to eq(:entity => name,
|
|
970
|
-
:check => "http",
|
|
971
|
-
# The state here is nil due to no check having gone
|
|
972
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
973
|
-
:state => nil,
|
|
974
|
-
:start_time => five_hours_ago,
|
|
975
|
-
:end_time => five_hours_ago + seven_hours,
|
|
976
|
-
:duration => seven_hours,
|
|
977
|
-
:summary => "Test scheduled maintenance for http")
|
|
978
|
-
end
|
|
979
|
-
end
|
|
980
|
-
|
|
981
|
-
it "finds all scheduled maintenance with a particular summary" do
|
|
982
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
983
|
-
|
|
984
|
-
# Maintenance started in the past, still running
|
|
985
|
-
ec.create_scheduled_maintenance(three_hours_ago, seven_hours, :summary => "Bring me a shrubbery!")
|
|
986
|
-
# Current maintenance
|
|
987
|
-
ec.create_scheduled_maintenance(t, half_an_hour, :summary => "Bring me a shrubbery!")
|
|
988
|
-
# Future maintenance
|
|
989
|
-
ec.create_scheduled_maintenance(t + five_minutes, half_an_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
990
|
-
|
|
991
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :reason => "Bring me a shrubbery!").sort_by { |k| k[:entity] }
|
|
992
|
-
|
|
993
|
-
expect(smp).to be_an(Array)
|
|
994
|
-
expect(smp.size).to eq(2)
|
|
995
|
-
|
|
996
|
-
expect(smp[0]).to eq(:entity => name,
|
|
997
|
-
:check => check,
|
|
998
|
-
# The state here is nil due to no check having gone
|
|
999
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1000
|
-
:state => nil,
|
|
1001
|
-
:start_time => three_hours_ago,
|
|
1002
|
-
:end_time => three_hours_ago + seven_hours,
|
|
1003
|
-
:duration => seven_hours,
|
|
1004
|
-
:summary => "Bring me a shrubbery!")
|
|
1005
|
-
expect(smp[1]).to eq(:entity => name,
|
|
1006
|
-
:check => check,
|
|
1007
|
-
# The state here is nil due to no check having gone
|
|
1008
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1009
|
-
:state => nil,
|
|
1010
|
-
:start_time => t,
|
|
1011
|
-
:end_time => t + half_an_hour,
|
|
1012
|
-
:duration => half_an_hour,
|
|
1013
|
-
:summary => "Bring me a shrubbery!")
|
|
1014
|
-
end
|
|
1015
|
-
|
|
1016
|
-
it "finds all scheduled maintenance with a summary regex" do
|
|
1017
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1018
|
-
|
|
1019
|
-
# Maintenance started in the past, still running
|
|
1020
|
-
ec.create_scheduled_maintenance(three_hours_ago, seven_hours, :summary => "Bring me a shrubbery!")
|
|
1021
|
-
# Current maintenance
|
|
1022
|
-
ec.create_scheduled_maintenance(t, half_an_hour, :summary => "Bring me a shrubbery!")
|
|
1023
|
-
# Future maintenance
|
|
1024
|
-
ec.create_scheduled_maintenance(t + five_minutes, half_an_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
1025
|
-
|
|
1026
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled', :reason => '.* shrubbery!').sort_by { |k| k[:entity] }
|
|
1027
|
-
|
|
1028
|
-
expect(smp).to be_an(Array)
|
|
1029
|
-
expect(smp.size).to eq(2)
|
|
1030
|
-
|
|
1031
|
-
expect(smp[0]).to eq(:entity => name,
|
|
1032
|
-
:check => check,
|
|
1033
|
-
# The state here is nil due to no check having gone
|
|
1034
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1035
|
-
:state => nil,
|
|
1036
|
-
:start_time => three_hours_ago,
|
|
1037
|
-
:end_time => three_hours_ago + seven_hours,
|
|
1038
|
-
:duration => seven_hours,
|
|
1039
|
-
:summary => "Bring me a shrubbery!")
|
|
1040
|
-
expect(smp[1]).to eq(:entity => name,
|
|
1041
|
-
:check => check,
|
|
1042
|
-
# The state here is nil due to no check having gone
|
|
1043
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1044
|
-
:state => nil,
|
|
1045
|
-
:start_time => t,
|
|
1046
|
-
:end_time => t + half_an_hour,
|
|
1047
|
-
:duration => half_an_hour,
|
|
1048
|
-
:summary => "Bring me a shrubbery!")
|
|
1049
|
-
end
|
|
1050
|
-
|
|
1051
|
-
it "deletes scheduled maintenance from list" do
|
|
1052
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1053
|
-
# Current maintenance
|
|
1054
|
-
ec.create_scheduled_maintenance(two_hours_ago, seven_hours, :summary => "Scheduled maintenance started 2 hours ago")
|
|
1055
|
-
ec.create_scheduled_maintenance(t + half_an_hour, half_an_hour, :summary => "Scheduled maintenance starting in half an hour")
|
|
1056
|
-
# Future maintenance
|
|
1057
|
-
ec.create_scheduled_maintenance(t + five_minutes, half_an_hour, :summary => "Scheduled maintenance starting in 5 minutes")
|
|
1058
|
-
|
|
1059
|
-
smp = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled').sort_by { |k| k[:entity] }
|
|
1060
|
-
|
|
1061
|
-
expect(smp).to be_an(Array)
|
|
1062
|
-
expect(smp.size).to eq(3)
|
|
1063
|
-
|
|
1064
|
-
expect(smp[0]).to eq(:entity => name,
|
|
1065
|
-
:check => check,
|
|
1066
|
-
# The state here is nil due to no check having gone
|
|
1067
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1068
|
-
:state => nil,
|
|
1069
|
-
:start_time => two_hours_ago,
|
|
1070
|
-
:end_time => two_hours_ago + seven_hours,
|
|
1071
|
-
:duration => seven_hours,
|
|
1072
|
-
:summary => "Scheduled maintenance started 2 hours ago")
|
|
1073
|
-
expect(smp[1]).to eq(:entity => name,
|
|
1074
|
-
:check => check,
|
|
1075
|
-
# The state here is nil due to no check having gone
|
|
1076
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1077
|
-
:state => nil,
|
|
1078
|
-
:start_time => t + five_minutes,
|
|
1079
|
-
:end_time => t + five_minutes + half_an_hour,
|
|
1080
|
-
:duration => half_an_hour,
|
|
1081
|
-
:summary => "Scheduled maintenance starting in 5 minutes")
|
|
1082
|
-
expect(smp[2]).to eq(:entity => name,
|
|
1083
|
-
:check => check,
|
|
1084
|
-
# The state here is nil due to no check having gone
|
|
1085
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1086
|
-
:state => nil,
|
|
1087
|
-
:start_time => t + half_an_hour,
|
|
1088
|
-
:end_time => t + half_an_hour + half_an_hour,
|
|
1089
|
-
:duration => half_an_hour,
|
|
1090
|
-
:summary => "Scheduled maintenance starting in half an hour")
|
|
1091
|
-
|
|
1092
|
-
delete = Flapjack::Data::EntityCheck.delete_maintenance(:redis => @redis, :type => 'scheduled', :duration => '30 minutes' )
|
|
1093
|
-
expect(delete).to eq({})
|
|
1094
|
-
|
|
1095
|
-
remain = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'scheduled').sort_by { |k| k[:entity] }
|
|
1096
|
-
|
|
1097
|
-
expect(remain).to be_an(Array)
|
|
1098
|
-
expect(remain.size).to eq(1)
|
|
1099
|
-
|
|
1100
|
-
expect(remain[0]).to eq(:entity => name,
|
|
1101
|
-
:check => check,
|
|
1102
|
-
# The state here is nil due to no check having gone
|
|
1103
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1104
|
-
:state => nil,
|
|
1105
|
-
:start_time => two_hours_ago,
|
|
1106
|
-
:end_time => two_hours_ago + seven_hours,
|
|
1107
|
-
:duration => seven_hours,
|
|
1108
|
-
:summary => "Scheduled maintenance started 2 hours ago")
|
|
1109
|
-
end
|
|
1110
|
-
|
|
1111
|
-
it "deletes unscheduled maintenance from list" do
|
|
1112
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1113
|
-
ec.create_unscheduled_maintenance(t, half_an_hour, :summary => "Unscheduled maintenance starting now")
|
|
1114
|
-
|
|
1115
|
-
ump = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'unscheduled').sort_by { |k| k[:entity] }
|
|
1116
|
-
expect(ump).to be_an(Array)
|
|
1117
|
-
expect(ump.size).to eq(1)
|
|
1118
|
-
|
|
1119
|
-
expect(ump[0]).to eq(:entity => name,
|
|
1120
|
-
:check => check,
|
|
1121
|
-
# The state here is nil due to no check having gone
|
|
1122
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1123
|
-
:state => nil,
|
|
1124
|
-
:start_time => t,
|
|
1125
|
-
:duration => half_an_hour,
|
|
1126
|
-
:end_time => t + half_an_hour,
|
|
1127
|
-
:summary => "Unscheduled maintenance starting now")
|
|
1128
|
-
|
|
1129
|
-
later_t = t + (15 * 60)
|
|
1130
|
-
Delorean.time_travel_to(Time.at(later_t))
|
|
1131
|
-
|
|
1132
|
-
delete = Flapjack::Data::EntityCheck.delete_maintenance(:redis => @redis, :type => 'unscheduled', :duration => '30 minutes')
|
|
1133
|
-
expect(delete).to eq({})
|
|
1134
|
-
|
|
1135
|
-
remain = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'unscheduled').sort_by { |k| k[:entity] }
|
|
1136
|
-
expect(remain).to be_an(Array)
|
|
1137
|
-
expect(remain.size).to eq(1)
|
|
1138
|
-
|
|
1139
|
-
expect(remain[0]).to eq(:entity => name,
|
|
1140
|
-
:check => check,
|
|
1141
|
-
# The state here is nil due to no check having gone
|
|
1142
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1143
|
-
:state => nil,
|
|
1144
|
-
:start_time => t,
|
|
1145
|
-
:duration => half_an_hour,
|
|
1146
|
-
:end_time => t + half_an_hour,
|
|
1147
|
-
:summary => "Unscheduled maintenance starting now")
|
|
1148
|
-
end
|
|
1149
|
-
|
|
1150
|
-
it "shows errors when deleting maintenance in the past" do
|
|
1151
|
-
Flapjack::Data::EntityCheck.create_maintenance(:redis => @redis, :entity => name, :check => check, :type => 'unscheduled', :started => '14/3/1927 3pm', :duration => '30 minutes', :reason => 'Unscheduled maintenance')
|
|
1152
|
-
t = Time.local(1927, 3, 14, 15, 0).to_i
|
|
1153
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1154
|
-
|
|
1155
|
-
ump = Flapjack::Data::EntityCheck.find_maintenance(:redis => @redis, :type => 'unscheduled').sort_by { |k| k[:entity] }
|
|
1156
|
-
expect(ump).to be_an(Array)
|
|
1157
|
-
expect(ump.size).to eq(1)
|
|
1158
|
-
|
|
1159
|
-
expect(ump[0]).to eq(:entity => name,
|
|
1160
|
-
:check => check,
|
|
1161
|
-
# The state here is nil due to no check having gone
|
|
1162
|
-
# through for this item. This is normally 'critical' or 'ok'
|
|
1163
|
-
:state => nil,
|
|
1164
|
-
:start_time => t,
|
|
1165
|
-
:duration => half_an_hour,
|
|
1166
|
-
:end_time => t + half_an_hour,
|
|
1167
|
-
:summary => "Unscheduled maintenance")
|
|
1168
|
-
|
|
1169
|
-
delete = Flapjack::Data::EntityCheck.delete_maintenance(:redis => @redis, :type => 'unscheduled', :duration => '30 minutes')
|
|
1170
|
-
expect(delete).to eq({"abc-123:ping:#{t}"=>"Maintenance can't be deleted as it finished in the past"})
|
|
1171
|
-
end
|
|
1172
|
-
end
|
|
1173
|
-
|
|
1174
|
-
it "returns its state" do
|
|
1175
|
-
@redis.hset("check:#{name}:#{check}", 'state', 'ok')
|
|
1176
|
-
|
|
1177
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1178
|
-
state = ec.state
|
|
1179
|
-
expect(state).not_to be_nil
|
|
1180
|
-
expect(state).to eq('ok')
|
|
1181
|
-
end
|
|
1182
|
-
|
|
1183
|
-
it "updates state" do
|
|
1184
|
-
@redis.hset("check:#{name}:#{check}", 'state', 'ok')
|
|
1185
|
-
|
|
1186
|
-
old_timestamp = @redis.hget("check:#{name}:#{check}", 'last_update')
|
|
1187
|
-
|
|
1188
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1189
|
-
ec.update_state('critical')
|
|
1190
|
-
|
|
1191
|
-
state = @redis.hget("check:#{name}:#{check}", 'state')
|
|
1192
|
-
expect(state).not_to be_nil
|
|
1193
|
-
expect(state).to eq('critical')
|
|
1194
|
-
|
|
1195
|
-
new_timestamp = @redis.hget("check:#{name}:#{check}", 'last_update')
|
|
1196
|
-
expect(new_timestamp).not_to eq(old_timestamp)
|
|
1197
|
-
end
|
|
1198
|
-
|
|
1199
|
-
it "updates enabled checks" do
|
|
1200
|
-
ts = Time.now.to_i
|
|
1201
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1202
|
-
|
|
1203
|
-
# was check.last_update=
|
|
1204
|
-
@redis.hset("check:#{name}:#{check}", 'last_update', ts)
|
|
1205
|
-
@redis.zadd("all_checks", ts, @key)
|
|
1206
|
-
@redis.zadd("all_checks:#{name}", ts, check)
|
|
1207
|
-
@redis.zadd("current_checks:#{name}", ts, check)
|
|
1208
|
-
@redis.zadd('current_entities', ts, name)
|
|
1209
|
-
|
|
1210
|
-
saved_check_ts = @redis.zscore("current_checks:#{name}", check)
|
|
1211
|
-
expect(saved_check_ts).not_to be_nil
|
|
1212
|
-
expect(saved_check_ts).to eq(ts)
|
|
1213
|
-
saved_entity_ts = @redis.zscore("current_entities", name)
|
|
1214
|
-
expect(saved_entity_ts).not_to be_nil
|
|
1215
|
-
expect(saved_entity_ts).to eq(ts)
|
|
1216
|
-
end
|
|
1217
|
-
|
|
1218
|
-
it "exposes that it is enabled" do
|
|
1219
|
-
@redis.zadd("current_checks:#{name}", Time.now.to_i, check)
|
|
1220
|
-
@redis.zadd("current_entities", Time.now.to_i, name)
|
|
1221
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1222
|
-
|
|
1223
|
-
e = ec.enabled?
|
|
1224
|
-
expect(e).to be true
|
|
1225
|
-
end
|
|
1226
|
-
|
|
1227
|
-
it "exposes that it is disabled" do
|
|
1228
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1229
|
-
|
|
1230
|
-
e = ec.enabled?
|
|
1231
|
-
expect(e).to be false
|
|
1232
|
-
end
|
|
1233
|
-
|
|
1234
|
-
it "disables checks" do
|
|
1235
|
-
@redis.zadd("current_checks:#{name}", Time.now.to_i, check)
|
|
1236
|
-
@redis.zadd("current_entities", Time.now.to_i, name)
|
|
1237
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1238
|
-
ec.disable!
|
|
1239
|
-
|
|
1240
|
-
saved_check_ts = @redis.zscore("current_checks:#{name}", check)
|
|
1241
|
-
saved_entity_ts = @redis.zscore("current_entities", name)
|
|
1242
|
-
expect(saved_check_ts).to be_nil
|
|
1243
|
-
expect(saved_entity_ts).to be_nil
|
|
1244
|
-
end
|
|
1245
|
-
|
|
1246
|
-
it "does not update state with invalid value" do
|
|
1247
|
-
@redis.hset("check:#{name}:#{check}", 'state', 'ok')
|
|
1248
|
-
|
|
1249
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1250
|
-
ec.update_state('silly')
|
|
1251
|
-
|
|
1252
|
-
state = @redis.hget("check:#{name}:#{check}", 'state')
|
|
1253
|
-
expect(state).not_to be_nil
|
|
1254
|
-
expect(state).to eq('ok')
|
|
1255
|
-
end
|
|
1256
|
-
|
|
1257
|
-
it "does not update state with a repeated state value" do
|
|
1258
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1259
|
-
ec.update_state('critical', :summary => 'small problem', :details => 'none')
|
|
1260
|
-
changed_at = @redis.hget("check:#{name}:#{check}", 'last_change')
|
|
1261
|
-
summary = ec.summary
|
|
1262
|
-
details = ec.details
|
|
1263
|
-
|
|
1264
|
-
ec.update_state('critical', :summary => 'big problem', :details => 'some')
|
|
1265
|
-
new_changed_at = @redis.hget("check:#{name}:#{check}", 'last_change')
|
|
1266
|
-
new_summary = ec.summary
|
|
1267
|
-
new_details = ec.details
|
|
1268
|
-
|
|
1269
|
-
expect(changed_at).not_to be_nil
|
|
1270
|
-
expect(new_changed_at).not_to be_nil
|
|
1271
|
-
expect(new_changed_at).to eq(changed_at)
|
|
1272
|
-
|
|
1273
|
-
expect(summary).not_to be_nil
|
|
1274
|
-
expect(new_summary).not_to be_nil
|
|
1275
|
-
expect(new_summary).not_to eq(summary)
|
|
1276
|
-
expect(summary).to eq('small problem')
|
|
1277
|
-
expect(new_summary).to eq('big problem')
|
|
1278
|
-
|
|
1279
|
-
expect(details).not_to be_nil
|
|
1280
|
-
expect(new_details).not_to be_nil
|
|
1281
|
-
expect(new_details).not_to eq(details)
|
|
1282
|
-
expect(details).to eq('none')
|
|
1283
|
-
expect(new_details).to eq('some')
|
|
1284
|
-
end
|
|
1285
|
-
|
|
1286
|
-
def time_before(t, min, sec = 0)
|
|
1287
|
-
t - ((60 * min) + sec)
|
|
1288
|
-
end
|
|
1289
|
-
|
|
1290
|
-
it "returns a list of historical states for a time range" do
|
|
1291
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1292
|
-
|
|
1293
|
-
t = Time.now.to_i
|
|
1294
|
-
ec.update_state('ok', :timestamp => time_before(t, 5), :summary => 'a')
|
|
1295
|
-
ec.update_state('critical', :timestamp => time_before(t, 4), :summary => 'b')
|
|
1296
|
-
ec.update_state('ok', :timestamp => time_before(t, 3), :summary => 'c')
|
|
1297
|
-
ec.update_state('critical', :timestamp => time_before(t, 2), :summary => 'd')
|
|
1298
|
-
ec.update_state('ok', :timestamp => time_before(t, 1), :summary => 'e')
|
|
1299
|
-
|
|
1300
|
-
states = ec.historical_states(time_before(t, 4), t)
|
|
1301
|
-
expect(states).not_to be_nil
|
|
1302
|
-
expect(states).to be_an(Array)
|
|
1303
|
-
expect(states.size).to eq(4)
|
|
1304
|
-
expect(states[0][:summary]).to eq('b')
|
|
1305
|
-
expect(states[1][:summary]).to eq('c')
|
|
1306
|
-
expect(states[2][:summary]).to eq('d')
|
|
1307
|
-
expect(states[3][:summary]).to eq('e')
|
|
1308
|
-
end
|
|
1309
|
-
|
|
1310
|
-
it "returns a list of historical unscheduled maintenances for a time range" do
|
|
1311
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1312
|
-
|
|
1313
|
-
t = Time.now.to_i
|
|
1314
|
-
ec.update_state('ok', :timestamp => time_before(t, 5), :summary => 'a')
|
|
1315
|
-
ec.update_state('critical', :timestamp => time_before(t, 4), :summary => 'b')
|
|
1316
|
-
ec.update_state('ok', :timestamp => time_before(t, 3), :summary => 'c')
|
|
1317
|
-
ec.update_state('critical', :timestamp => time_before(t, 2), :summary => 'd')
|
|
1318
|
-
ec.update_state('ok', :timestamp => time_before(t, 1), :summary => 'e')
|
|
1319
|
-
|
|
1320
|
-
states = ec.historical_states(time_before(t, 4), t)
|
|
1321
|
-
expect(states).not_to be_nil
|
|
1322
|
-
expect(states).to be_an(Array)
|
|
1323
|
-
expect(states.size).to eq(4)
|
|
1324
|
-
expect(states[0][:summary]).to eq('b')
|
|
1325
|
-
expect(states[1][:summary]).to eq('c')
|
|
1326
|
-
expect(states[2][:summary]).to eq('d')
|
|
1327
|
-
expect(states[3][:summary]).to eq('e')
|
|
1328
|
-
end
|
|
1329
|
-
|
|
1330
|
-
it "returns a list of historical scheduled maintenances for a time range" do
|
|
1331
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1332
|
-
|
|
1333
|
-
t = Time.now.to_i
|
|
1334
|
-
|
|
1335
|
-
ec.create_scheduled_maintenance(time_before(t, 180),
|
|
1336
|
-
half_an_hour, :summary => "a")
|
|
1337
|
-
ec.create_scheduled_maintenance(time_before(t, 120),
|
|
1338
|
-
half_an_hour, :summary => "b")
|
|
1339
|
-
ec.create_scheduled_maintenance(time_before(t, 60),
|
|
1340
|
-
half_an_hour, :summary => "c")
|
|
1341
|
-
|
|
1342
|
-
sched_maint_periods = ec.maintenances(time_before(t, 150), t,
|
|
1343
|
-
:scheduled => true)
|
|
1344
|
-
expect(sched_maint_periods).not_to be_nil
|
|
1345
|
-
expect(sched_maint_periods).to be_an(Array)
|
|
1346
|
-
expect(sched_maint_periods.size).to eq(2)
|
|
1347
|
-
expect(sched_maint_periods[0][:summary]).to eq('b')
|
|
1348
|
-
expect(sched_maint_periods[1][:summary]).to eq('c')
|
|
1349
|
-
end
|
|
1350
|
-
|
|
1351
|
-
it "returns that it has failed" do
|
|
1352
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1353
|
-
|
|
1354
|
-
@redis.hset("check:#{name}:#{check}", 'state', 'warning')
|
|
1355
|
-
expect(ec).to be_failed
|
|
1356
|
-
|
|
1357
|
-
@redis.hset("check:#{name}:#{check}", 'state', 'critical')
|
|
1358
|
-
expect(ec).to be_failed
|
|
1359
|
-
|
|
1360
|
-
@redis.hset("check:#{name}:#{check}", 'state', 'unknown')
|
|
1361
|
-
expect(ec).to be_failed
|
|
1362
|
-
end
|
|
1363
|
-
|
|
1364
|
-
it "returns that it has not failed" do
|
|
1365
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1366
|
-
|
|
1367
|
-
@redis.hset("check:#{name}:#{check}", 'state', 'ok')
|
|
1368
|
-
expect(ec).not_to be_failed
|
|
1369
|
-
|
|
1370
|
-
@redis.hset("check:#{name}:#{check}", 'state', 'acknowledgement')
|
|
1371
|
-
expect(ec).not_to be_failed
|
|
1372
|
-
end
|
|
1373
|
-
|
|
1374
|
-
it "returns a status summary" do
|
|
1375
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1376
|
-
|
|
1377
|
-
t = Time.now.to_i
|
|
1378
|
-
ec.update_state('ok', :timestamp => time_before(t, 5), :summary => 'a')
|
|
1379
|
-
ec.update_state('critical', :timestamp => time_before(t, 4), :summary => 'b')
|
|
1380
|
-
ec.update_state('ok', :timestamp => time_before(t, 3), :summary => 'c')
|
|
1381
|
-
ec.update_state('critical', :timestamp => time_before(t, 2), :summary => 'd')
|
|
1382
|
-
|
|
1383
|
-
summary = ec.summary
|
|
1384
|
-
expect(summary).to eq('d')
|
|
1385
|
-
end
|
|
1386
|
-
|
|
1387
|
-
it "returns timestamps for its last notifications" do
|
|
1388
|
-
t = Time.now.to_i
|
|
1389
|
-
@redis.set("#{name}:#{check}:last_problem_notification", t - 30)
|
|
1390
|
-
@redis.set("#{name}:#{check}:last_acknowledgement_notification", t - 15)
|
|
1391
|
-
@redis.set("#{name}:#{check}:last_recovery_notification", t)
|
|
1392
|
-
|
|
1393
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1394
|
-
expect(ec.last_notification_for_state(:problem)[:timestamp]).to eq(t - 30)
|
|
1395
|
-
expect(ec.last_notification_for_state(:acknowledgement)[:timestamp]).to eq(t - 15)
|
|
1396
|
-
expect(ec.last_notification_for_state(:recovery)[:timestamp]).to eq(t)
|
|
1397
|
-
end
|
|
1398
|
-
|
|
1399
|
-
it "finds all related contacts" do
|
|
1400
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name(name, check, :redis => @redis)
|
|
1401
|
-
contacts = ec.contacts
|
|
1402
|
-
expect(contacts).not_to be_nil
|
|
1403
|
-
expect(contacts).to be_an(Array)
|
|
1404
|
-
expect(contacts.size).to eq(1)
|
|
1405
|
-
expect(contacts.first.name).to eq('John Johnson')
|
|
1406
|
-
end
|
|
1407
|
-
|
|
1408
|
-
it "generates ephemeral tags for itself" do
|
|
1409
|
-
ec = Flapjack::Data::EntityCheck.for_entity_name('foo-app-01.example.com', 'Disk / Utilisation', :create_entity => true, :redis => @redis)
|
|
1410
|
-
tags = ec.tags
|
|
1411
|
-
expect(tags).not_to be_nil
|
|
1412
|
-
expect(tags).to be_a(Set)
|
|
1413
|
-
expect(['foo-app-01', 'example.com', 'disk', '/', 'utilisation'].to_set.subset?(tags)).to be true
|
|
1414
|
-
end
|
|
1415
|
-
|
|
1416
|
-
it "returns unacknowledged failing checks"
|
|
1417
|
-
|
|
1418
|
-
end
|