flapjack 1.6.0 → 2.0.0b1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -3,233 +3,1032 @@ require 'flapjack/gateways/jabber'
|
|
3
3
|
|
4
4
|
describe Flapjack::Gateways::Jabber, :logger => true do
|
5
5
|
|
6
|
-
let(:config) { {'queue'
|
7
|
-
'server'
|
8
|
-
'port'
|
9
|
-
'jabberid'
|
10
|
-
'password'
|
11
|
-
'alias'
|
6
|
+
let(:config) { {'queue' => 'jabber_notifications',
|
7
|
+
'server' => 'example.com',
|
8
|
+
'port' => '5222',
|
9
|
+
'jabberid' => 'flapjack@example.com',
|
10
|
+
'password' => 'password',
|
11
|
+
'alias' => 'flapjack',
|
12
12
|
'identifiers' => ['@flapjack'],
|
13
|
-
'rooms'
|
13
|
+
'rooms' => ['flapjacktest@conference.example.com'],
|
14
|
+
'chatbot_announce' => true
|
14
15
|
}
|
15
16
|
}
|
16
17
|
|
18
|
+
let(:check) { double(Flapjack::Data::Check, :id => SecureRandom.uuid) }
|
19
|
+
|
20
|
+
let(:redis) { double(::Redis) }
|
17
21
|
let(:stanza) { double('stanza') }
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
let(:now) { Time.now }
|
24
|
+
|
25
|
+
let(:lock) { double(Monitor) }
|
26
|
+
let(:stop_cond) { double(MonitorMixin::ConditionVariable) }
|
21
27
|
|
22
|
-
|
23
|
-
|
28
|
+
before(:each) do
|
29
|
+
allow(Flapjack).to receive(:redis).and_return(redis)
|
30
|
+
end
|
24
31
|
|
25
|
-
|
32
|
+
context 'notifications' do
|
26
33
|
|
27
|
-
|
28
|
-
expect(fj).to receive(:on_ready).with(stanza)
|
34
|
+
let(:queue) { double(Flapjack::RecordQueue) }
|
29
35
|
|
30
|
-
|
31
|
-
expect(fj).to receive(:register_handler).with(:message, :groupchat?, body_matchers).and_yield(stanza)
|
32
|
-
expect(fj).to receive(:on_groupchat).with(stanza)
|
36
|
+
let(:alert) { double(Flapjack::Data::Alert) }
|
33
37
|
|
34
|
-
|
35
|
-
|
38
|
+
it "starts and is stopped by an exception" do
|
39
|
+
expect(Flapjack::RecordQueue).to receive(:new).with('jabber_notifications',
|
40
|
+
Flapjack::Data::Alert).and_return(queue)
|
36
41
|
|
37
|
-
|
38
|
-
|
42
|
+
expect(lock).to receive(:synchronize).and_yield
|
43
|
+
expect(queue).to receive(:foreach).and_yield(alert)
|
44
|
+
expect(queue).to receive(:wait).and_raise(Flapjack::PikeletStop)
|
39
45
|
|
40
|
-
|
41
|
-
|
46
|
+
expect(redis).to receive(:quit)
|
47
|
+
|
48
|
+
fjn = Flapjack::Gateways::Jabber::Notifier.new(:lock => lock,
|
49
|
+
:config => config)
|
50
|
+
expect(fjn).to receive(:handle_alert).with(alert)
|
51
|
+
|
52
|
+
expect { fjn.start }.to raise_error(Flapjack::PikeletStop)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "handles notifications received via Redis" do
|
56
|
+
bot = double(Flapjack::Gateways::Jabber::Bot)
|
57
|
+
expect(bot).to receive(:respond_to?).with(:announce).and_return(true)
|
58
|
+
expect(bot).to receive(:announce).with('johns@example.com', /Problem: /)
|
59
|
+
expect(bot).to receive(:alias).and_return('flapjack')
|
42
60
|
|
43
|
-
|
44
|
-
expect(Flapjack::RedisPool).to receive(:new)
|
61
|
+
expect(check).to receive(:name).twice.and_return('app-02:ping')
|
45
62
|
|
46
|
-
|
47
|
-
|
63
|
+
expect(alert).to receive(:address).and_return('johns@example.com')
|
64
|
+
expect(alert).to receive(:check).twice.and_return(check)
|
65
|
+
expect(alert).to receive(:state).and_return('critical')
|
66
|
+
expect(alert).to receive(:state_title_case).and_return('Critical')
|
67
|
+
expect(alert).to receive(:summary).twice.and_return('')
|
68
|
+
# expect(alert).to receive(:event_count).and_return(33)
|
69
|
+
expect(alert).to receive(:type).twice.and_return('problem')
|
70
|
+
expect(alert).to receive(:type_sentence_case).and_return('Problem')
|
71
|
+
expect(alert).to receive(:rollup).and_return(nil)
|
72
|
+
expect(alert).to receive(:event_hash).and_return('abcd1234')
|
48
73
|
|
49
|
-
|
50
|
-
|
51
|
-
|
74
|
+
fjn = Flapjack::Gateways::Jabber::Notifier.new(:config => config)
|
75
|
+
fjn.instance_variable_set('@siblings', [bot])
|
76
|
+
fjn.send(:handle_alert, alert)
|
77
|
+
end
|
52
78
|
|
53
|
-
fj.on_ready(stanza)
|
54
79
|
end
|
55
80
|
|
56
|
-
|
57
|
-
expect(stanza).to receive(:body).twice.and_return('flapjack: ACKID 1f8ac10f fixing now duration: 90m')
|
58
|
-
from = double('from')
|
59
|
-
expect(from).to receive(:stripped).and_return('sender')
|
60
|
-
expect(stanza).to receive(:from).and_return(from)
|
81
|
+
context 'commands' do
|
61
82
|
|
62
|
-
|
63
|
-
expect(redis).to receive(:hget).with('checks_by_hash', '1f8ac10f').
|
64
|
-
and_return('main-example.com:ping')
|
83
|
+
let(:bot) { double(Flapjack::Gateways::Jabber::Bot) }
|
65
84
|
|
66
|
-
|
67
|
-
expect(entity_check).to receive(:in_unscheduled_maintenance?)
|
85
|
+
let(:tag) { double(Flapjack::Data::Tag, :id => SecureRandom.uuid) }
|
68
86
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
87
|
+
let(:checks) { double('checks', :ids => [check.id]) }
|
88
|
+
let(:tags) { double('tags', :all => [tag]) }
|
89
|
+
let(:states) { double('states', :last => state) }
|
90
|
+
let(:sorted_checks) { double('sorted_checks', :ids => [check.id])}
|
73
91
|
|
74
|
-
|
75
|
-
|
76
|
-
|
92
|
+
# TODO use separate threads in the test instead?
|
93
|
+
it "starts and is stopped by a signal" do
|
94
|
+
expect(lock).to receive(:synchronize).and_yield
|
77
95
|
|
78
|
-
|
79
|
-
|
96
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:lock => lock, :stop_condition => stop_cond,
|
97
|
+
:config => config)
|
98
|
+
msg = {:room => 'room1', :nick => 'jim', :time => now.to_i, :message => 'help'}
|
99
|
+
fji.instance_variable_get('@messages').push(msg)
|
100
|
+
expect(stop_cond).to receive(:wait_while) {
|
101
|
+
fji.instance_variable_set('@should_quit', true)
|
102
|
+
}
|
80
103
|
|
81
|
-
|
82
|
-
expect(fj).to receive(:connected?).and_return(true)
|
83
|
-
expect(fj).to receive(:write).with(an_instance_of(Blather::Stanza::Message))
|
104
|
+
expect(fji).to receive(:interpret).with('room1', 'jim', now.to_i, 'help')
|
84
105
|
|
85
|
-
|
86
|
-
|
106
|
+
expect(redis).to receive(:quit)
|
107
|
+
fji.start
|
108
|
+
end
|
87
109
|
|
88
|
-
|
89
|
-
|
90
|
-
and_return('flapjack: tell me about <span style="text-decoration: underline;">' +
|
91
|
-
'<a href="http://example.org/">example.org</a></span>')
|
110
|
+
it "receives a message and and signals a condition variable" do
|
111
|
+
expect(lock).to receive(:synchronize).and_yield
|
92
112
|
|
93
|
-
|
94
|
-
|
95
|
-
|
113
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:lock => lock, :stop_condition => stop_cond,
|
114
|
+
:config => config)
|
115
|
+
expect(fji.instance_variable_get('@messages')).to be_empty
|
116
|
+
expect(stop_cond).to receive(:signal)
|
96
117
|
|
97
|
-
|
98
|
-
|
99
|
-
|
118
|
+
fji.receive_message('room1', 'jim', now.to_i, 'help')
|
119
|
+
expect(fji.instance_variable_get('@messages').size).to eq(1)
|
120
|
+
end
|
100
121
|
|
101
|
-
|
102
|
-
:
|
122
|
+
it "interprets a received help command (from a room)" do
|
123
|
+
expect(bot).to receive(:announce).with('room1', /^commands:/)
|
103
124
|
|
104
|
-
|
105
|
-
|
106
|
-
|
125
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
126
|
+
fji.instance_variable_set('@bot', bot)
|
127
|
+
fji.interpret('room1', 'jim', now.to_i, 'help')
|
128
|
+
end
|
107
129
|
|
108
|
-
|
109
|
-
:
|
130
|
+
it "interprets a received help command (from a user)" do
|
131
|
+
expect(bot).to receive(:say).with('jim', /^commands:/)
|
110
132
|
|
111
|
-
|
112
|
-
|
133
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
134
|
+
fji.instance_variable_set('@bot', bot)
|
135
|
+
fji.interpret(nil, 'jim', now.to_i, 'help')
|
136
|
+
end
|
113
137
|
|
114
|
-
|
115
|
-
|
116
|
-
|
138
|
+
it "interprets a received identify command " do
|
139
|
+
expect(bot).to receive(:announce).with('room1', /System CPU Time/)
|
140
|
+
expect(bot).to receive(:identifiers).and_return(['@flapjack'])
|
117
141
|
|
118
|
-
|
119
|
-
|
142
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config,
|
143
|
+
:boot_time => now)
|
144
|
+
fji.instance_variable_set('@bot', bot)
|
145
|
+
fji.interpret('room1', 'jim', now.to_i + 60, 'identify')
|
146
|
+
end
|
120
147
|
|
121
|
-
|
122
|
-
|
123
|
-
and_return("flapjack: tell me about \nexample.com")
|
148
|
+
it "interprets a received find command (with regex)" do
|
149
|
+
expect(bot).to receive(:announce).with('room1', "Checks matching /example/:\nexample.com:ping is OK")
|
124
150
|
|
125
|
-
|
126
|
-
expect(from).to receive(:stripped).and_return('sender')
|
127
|
-
expect(stanza).to receive(:from).and_return(from)
|
151
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
128
152
|
|
129
|
-
|
130
|
-
|
131
|
-
|
153
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
154
|
+
with(no_args).
|
155
|
+
and_yield
|
132
156
|
|
133
|
-
|
134
|
-
:redis => redis).and_return(entity)
|
157
|
+
expect(check).to receive(:condition).and_return('ok')
|
135
158
|
|
136
|
-
|
137
|
-
|
138
|
-
|
159
|
+
expect(Flapjack::Data::Check).to receive(:find_by_ids).with(check.id).and_return([check])
|
160
|
+
expect(checks).to receive(:count).and_return(5)
|
161
|
+
expect(checks).to receive(:sort).with(:name, :limit => 30).and_return(sorted_checks)
|
162
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
163
|
+
with(:name => Regexp.new("example")).and_return(checks)
|
139
164
|
|
140
|
-
|
141
|
-
|
165
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
166
|
+
fji.instance_variable_set('@bot', bot)
|
167
|
+
fji.interpret('room1', 'jim', now.to_i, 'find checks matching /example/')
|
168
|
+
end
|
142
169
|
|
143
|
-
|
144
|
-
|
170
|
+
it "interprets a received find command (with limited results)" do
|
171
|
+
expect(bot).to receive(:announce).with('room1', "Checks matching /example/:\nShowing first 2 results of 5:\nexample.com:ping is OK")
|
145
172
|
|
146
|
-
|
147
|
-
expect(fj).to receive(:connected?).and_return(true)
|
148
|
-
expect(fj).to receive(:write).with(an_instance_of(Blather::Stanza::Message))
|
173
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
149
174
|
|
150
|
-
|
151
|
-
|
175
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
176
|
+
with(no_args).
|
177
|
+
and_yield
|
152
178
|
|
153
|
-
|
154
|
-
expect(stanza).to receive(:body).twice.and_return('flapjack: hello!')
|
155
|
-
from = double('from')
|
156
|
-
expect(from).to receive(:stripped).and_return('sender')
|
157
|
-
expect(stanza).to receive(:from).and_return(from)
|
179
|
+
expect(check).to receive(:condition).and_return('ok')
|
158
180
|
|
159
|
-
|
160
|
-
|
181
|
+
expect(Flapjack::Data::Check).to receive(:find_by_ids).with(check.id).and_return([check])
|
182
|
+
expect(checks).to receive(:count).and_return(5)
|
183
|
+
expect(checks).to receive(:sort).with(:name, :limit => 2).and_return(sorted_checks)
|
184
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
185
|
+
with(:name => Regexp.new("example")).and_return(checks)
|
161
186
|
|
162
|
-
|
163
|
-
|
164
|
-
|
187
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
188
|
+
fji.instance_variable_set('@bot', bot)
|
189
|
+
fji.interpret('room1', 'jim', now.to_i, 'find 2 checks matching /example/')
|
190
|
+
end
|
165
191
|
|
166
|
-
|
167
|
-
|
192
|
+
it "interprets a received find command (with an invalid regex)" do
|
193
|
+
expect(bot).to receive(:announce).with('room1', 'Error parsing /(example/')
|
168
194
|
|
169
|
-
|
170
|
-
|
171
|
-
|
195
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
196
|
+
with(no_args).
|
197
|
+
and_yield
|
172
198
|
|
173
|
-
|
199
|
+
expect(Flapjack::Data::Check).not_to receive(:intersect)
|
174
200
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
raise StandardError.new unless attempts > 3
|
180
|
-
}
|
201
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
202
|
+
fji.instance_variable_set('@bot', bot)
|
203
|
+
fji.interpret('room1', 'jim', now.to_i, 'find checks matching /(example/')
|
204
|
+
end
|
181
205
|
|
182
|
-
|
183
|
-
|
184
|
-
|
206
|
+
it "interprets a received find command (with tag)" do
|
207
|
+
expect(bot).to receive(:announce).with('room1', "Checks with tag 'example.com':\nexample.com:ping is OK")
|
208
|
+
|
209
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
210
|
+
|
211
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
212
|
+
with(Flapjack::Data::Tag).
|
213
|
+
and_yield
|
214
|
+
|
215
|
+
expect(check).to receive(:condition).and_return('ok')
|
216
|
+
expect(checks).to receive(:sort).with(:name, :limit => 30).and_return(sorted_checks)
|
217
|
+
|
218
|
+
expect(Flapjack::Data::Check).to receive(:find_by_ids).with(check.id).and_return([check])
|
219
|
+
|
220
|
+
expect(checks).to receive(:count).and_return(5)
|
221
|
+
expect(tag).to receive(:checks).and_return(checks)
|
222
|
+
expect(Flapjack::Data::Tag).to receive(:intersect).
|
223
|
+
with(:name => 'example.com').and_return(tags)
|
224
|
+
|
225
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
226
|
+
fji.instance_variable_set('@bot', bot)
|
227
|
+
fji.interpret('room1', 'jim', now.to_i, 'find checks with tag example.com')
|
228
|
+
end
|
229
|
+
|
230
|
+
it "interprets a received state command (with name)" do
|
231
|
+
expect(bot).to receive(:announce).with('room1', /example.com:ping - OK/)
|
232
|
+
|
233
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
234
|
+
with(:id => [check.id]).and_return([check])
|
235
|
+
|
236
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
237
|
+
with(no_args).
|
238
|
+
and_yield
|
239
|
+
|
240
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
241
|
+
expect(check).to receive(:condition).and_return('ok')
|
242
|
+
|
243
|
+
expect(checks).to receive(:empty?).and_return(false)
|
244
|
+
expect(checks).to receive(:count).and_return(5)
|
245
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
246
|
+
with(:name => 'example.com:ping').and_return(checks)
|
247
|
+
|
248
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
249
|
+
fji.instance_variable_set('@bot', bot)
|
250
|
+
fji.interpret('room1', 'jim', now.to_i, 'state of example.com:ping')
|
251
|
+
end
|
252
|
+
|
253
|
+
it "interprets a received state command (with tag)" do
|
254
|
+
expect(bot).to receive(:announce).with('room1', /example.com:ping - OK/)
|
255
|
+
|
256
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
257
|
+
with(:id => [check.id]).and_return([check])
|
258
|
+
|
259
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
260
|
+
with(Flapjack::Data::Tag).
|
261
|
+
and_yield
|
262
|
+
|
263
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
264
|
+
expect(check).to receive(:condition).and_return('ok')
|
265
|
+
|
266
|
+
expect(checks).to receive(:count).and_return(5)
|
267
|
+
expect(tag).to receive(:checks).and_return(checks)
|
268
|
+
|
269
|
+
expect(Flapjack::Data::Tag).to receive(:intersect).
|
270
|
+
with(:name => 'example.com').and_return(tags)
|
271
|
+
|
272
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
273
|
+
fji.instance_variable_set('@bot', bot)
|
274
|
+
fji.interpret('room1', 'jim', now.to_i, 'state of checks with tag example.com')
|
275
|
+
end
|
276
|
+
|
277
|
+
it "interprets a received state command (with regex)" do
|
278
|
+
expect(bot).to receive(:announce).with('room1', /example.com:ping - OK/)
|
279
|
+
|
280
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
281
|
+
with(:id => [check.id]).and_return([check])
|
282
|
+
|
283
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
284
|
+
with(no_args).
|
285
|
+
and_yield
|
286
|
+
|
287
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
288
|
+
expect(check).to receive(:condition).and_return('ok')
|
289
|
+
|
290
|
+
expect(checks).to receive(:count).and_return(5)
|
291
|
+
|
292
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
293
|
+
with(:name => Regexp.new("^example.com:p")).and_return(checks)
|
294
|
+
|
295
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
296
|
+
fji.instance_variable_set('@bot', bot)
|
297
|
+
fji.interpret('room1', 'jim', now.to_i, 'state of checks matching /^example.com:p/')
|
298
|
+
end
|
299
|
+
|
300
|
+
let(:start_range) { double(Zermelo::Filters::IndexRange) }
|
301
|
+
let(:end_range) { double(Zermelo::Filters::IndexRange) }
|
302
|
+
|
303
|
+
let(:scheduled_maintenances) { double('scheduled_maintenances') }
|
304
|
+
let(:unscheduled_maintenances) { double('unscheduled_maintenances') }
|
305
|
+
|
306
|
+
let(:no_scheduled_maintenances) { double('no_scheduled_maintenances', :all => [])}
|
307
|
+
let(:no_unscheduled_maintenances) { double('no_unscheduled_maintenances', :all => [])}
|
308
|
+
|
309
|
+
it "interprets a received information command (with name)" do
|
310
|
+
expect(bot).to receive(:announce).with('room1', /Not in scheduled or unscheduled maintenance./)
|
311
|
+
|
312
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
313
|
+
with(Flapjack::Data::ScheduledMaintenance,
|
314
|
+
Flapjack::Data::UnscheduledMaintenance).
|
315
|
+
and_yield
|
316
|
+
|
317
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
318
|
+
with(:id => [check.id]).and_return([check])
|
319
|
+
|
320
|
+
expect(Zermelo::Filters::IndexRange).to receive(:new).
|
321
|
+
with(nil, an_instance_of(Time), :by_score => true).
|
322
|
+
and_return(start_range)
|
323
|
+
|
324
|
+
expect(Zermelo::Filters::IndexRange).to receive(:new).
|
325
|
+
with(an_instance_of(Time), nil, :by_score => true).
|
326
|
+
and_return(end_range)
|
327
|
+
|
328
|
+
expect(unscheduled_maintenances).to receive(:intersect).
|
329
|
+
with(:start_time => start_range, :end_time => end_range).
|
330
|
+
and_return(no_unscheduled_maintenances)
|
331
|
+
expect(scheduled_maintenances).to receive(:intersect).
|
332
|
+
with(:start_time => start_range, :end_time => end_range).
|
333
|
+
and_return(no_scheduled_maintenances)
|
334
|
+
expect(check).to receive(:scheduled_maintenances).and_return(scheduled_maintenances)
|
335
|
+
expect(check).to receive(:unscheduled_maintenances).and_return(unscheduled_maintenances)
|
336
|
+
|
337
|
+
expect(checks).to receive(:empty?).and_return(false)
|
338
|
+
expect(checks).to receive(:count).and_return(5)
|
339
|
+
expect(checks).to receive(:sort).with(:name, :limit => 30).and_return(sorted_checks)
|
340
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
341
|
+
with(:name => 'example.com:ping').and_return(checks)
|
342
|
+
|
343
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
344
|
+
fji.instance_variable_set('@bot', bot)
|
345
|
+
fji.interpret('room1', 'jim', now.to_i, 'tell me about example.com:ping')
|
346
|
+
end
|
347
|
+
|
348
|
+
it "handles a received information command (with name, with newline in the command)" do
|
349
|
+
expect(bot).to receive(:announce).with('room1', /Not in scheduled or unscheduled maintenance./)
|
350
|
+
|
351
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
352
|
+
with(Flapjack::Data::ScheduledMaintenance,
|
353
|
+
Flapjack::Data::UnscheduledMaintenance).
|
354
|
+
and_yield
|
355
|
+
|
356
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
357
|
+
with(:id => [check.id]).and_return([check])
|
358
|
+
|
359
|
+
expect(Zermelo::Filters::IndexRange).to receive(:new).
|
360
|
+
with(nil, an_instance_of(Time), :by_score => true).
|
361
|
+
and_return(start_range)
|
362
|
+
|
363
|
+
expect(Zermelo::Filters::IndexRange).to receive(:new).
|
364
|
+
with(an_instance_of(Time), nil, :by_score => true).
|
365
|
+
and_return(end_range)
|
366
|
+
|
367
|
+
expect(unscheduled_maintenances).to receive(:intersect).
|
368
|
+
with(:start_time => start_range, :end_time => end_range).
|
369
|
+
and_return(no_unscheduled_maintenances)
|
370
|
+
expect(scheduled_maintenances).to receive(:intersect).
|
371
|
+
with(:start_time => start_range, :end_time => end_range).
|
372
|
+
and_return(no_scheduled_maintenances)
|
373
|
+
expect(check).to receive(:scheduled_maintenances).and_return(scheduled_maintenances)
|
374
|
+
expect(check).to receive(:unscheduled_maintenances).and_return(unscheduled_maintenances)
|
375
|
+
|
376
|
+
expect(checks).to receive(:empty?).and_return(false)
|
377
|
+
expect(checks).to receive(:count).and_return(5)
|
378
|
+
expect(checks).to receive(:sort).with(:name, :limit => 30).and_return(sorted_checks)
|
379
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
380
|
+
with(:name => 'example.com:ping').and_return(checks)
|
381
|
+
|
382
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
383
|
+
fji.instance_variable_set('@bot', bot)
|
384
|
+
fji.interpret('room1', 'jim', now.to_i, "tell me \nabout example.com:ping")
|
385
|
+
end
|
386
|
+
|
387
|
+
it "interprets a received information command (with tag)" do
|
388
|
+
expect(bot).to receive(:announce).with('room1', /Not in scheduled or unscheduled maintenance./)
|
389
|
+
|
390
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
391
|
+
with(Flapjack::Data::Tag,
|
392
|
+
Flapjack::Data::ScheduledMaintenance,
|
393
|
+
Flapjack::Data::UnscheduledMaintenance).
|
394
|
+
and_yield
|
395
|
+
|
396
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
397
|
+
with(:id => [check.id]).and_return([check])
|
398
|
+
|
399
|
+
expect(Zermelo::Filters::IndexRange).to receive(:new).
|
400
|
+
with(nil, an_instance_of(Time), :by_score => true).
|
401
|
+
and_return(start_range)
|
402
|
+
|
403
|
+
expect(Zermelo::Filters::IndexRange).to receive(:new).
|
404
|
+
with(an_instance_of(Time), nil, :by_score => true).
|
405
|
+
and_return(end_range)
|
406
|
+
|
407
|
+
expect(unscheduled_maintenances).to receive(:intersect).
|
408
|
+
with(:start_time => start_range, :end_time => end_range).
|
409
|
+
and_return(no_unscheduled_maintenances)
|
410
|
+
expect(scheduled_maintenances).to receive(:intersect).
|
411
|
+
with(:start_time => start_range, :end_time => end_range).
|
412
|
+
and_return(no_scheduled_maintenances)
|
413
|
+
expect(check).to receive(:scheduled_maintenances).and_return(scheduled_maintenances)
|
414
|
+
expect(check).to receive(:unscheduled_maintenances).and_return(unscheduled_maintenances)
|
415
|
+
|
416
|
+
expect(checks).to receive(:count).and_return(5)
|
417
|
+
expect(checks).to receive(:sort).with(:name, :limit => 30).and_return(sorted_checks)
|
418
|
+
expect(tag).to receive(:checks).and_return(checks)
|
419
|
+
|
420
|
+
expect(Flapjack::Data::Tag).to receive(:intersect).
|
421
|
+
with(:name => 'example.com').and_return(tags)
|
422
|
+
|
423
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
424
|
+
fji.instance_variable_set('@bot', bot)
|
425
|
+
fji.interpret('room1', 'jim', now.to_i, 'tell me about checks with tag example.com')
|
426
|
+
end
|
427
|
+
|
428
|
+
it "interprets a received information command (with regex)" do
|
429
|
+
expect(bot).to receive(:announce).with('room1', /Not in scheduled or unscheduled maintenance./)
|
430
|
+
|
431
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
432
|
+
with(Flapjack::Data::ScheduledMaintenance,
|
433
|
+
Flapjack::Data::UnscheduledMaintenance).
|
434
|
+
and_yield
|
435
|
+
|
436
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
437
|
+
with(:id => [check.id]).and_return([check])
|
438
|
+
|
439
|
+
expect(Zermelo::Filters::IndexRange).to receive(:new).
|
440
|
+
with(nil, an_instance_of(Time), :by_score => true).
|
441
|
+
and_return(start_range)
|
442
|
+
|
443
|
+
expect(Zermelo::Filters::IndexRange).to receive(:new).
|
444
|
+
with(an_instance_of(Time), nil, :by_score => true).
|
445
|
+
and_return(end_range)
|
446
|
+
|
447
|
+
expect(unscheduled_maintenances).to receive(:intersect).
|
448
|
+
with(:start_time => start_range, :end_time => end_range).
|
449
|
+
and_return(no_unscheduled_maintenances)
|
450
|
+
expect(scheduled_maintenances).to receive(:intersect).
|
451
|
+
with(:start_time => start_range, :end_time => end_range).
|
452
|
+
and_return(no_scheduled_maintenances)
|
453
|
+
expect(check).to receive(:scheduled_maintenances).and_return(scheduled_maintenances)
|
454
|
+
expect(check).to receive(:unscheduled_maintenances).and_return(unscheduled_maintenances)
|
455
|
+
|
456
|
+
expect(checks).to receive(:count).and_return(5)
|
457
|
+
expect(checks).to receive(:sort).with(:name, :limit => 30).and_return(sorted_checks)
|
458
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
459
|
+
with(:name => Regexp.new("^example.com:p")).and_return(checks)
|
460
|
+
|
461
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
462
|
+
fji.instance_variable_set('@bot', bot)
|
463
|
+
fji.interpret('room1', 'jim', now.to_i, 'tell me about checks matching /^example.com:p/')
|
464
|
+
end
|
465
|
+
|
466
|
+
it "interprets a received information command (with limited results)" do
|
467
|
+
expect(bot).to receive(:announce).with('room1', /Showing first 2 results of 5:\nNot in scheduled or unscheduled maintenance./)
|
468
|
+
|
469
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
470
|
+
with(Flapjack::Data::ScheduledMaintenance,
|
471
|
+
Flapjack::Data::UnscheduledMaintenance).
|
472
|
+
and_yield
|
473
|
+
|
474
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
475
|
+
with(:id => [check.id]).and_return([check])
|
476
|
+
|
477
|
+
expect(Zermelo::Filters::IndexRange).to receive(:new).
|
478
|
+
with(nil, an_instance_of(Time), :by_score => true).
|
479
|
+
and_return(start_range)
|
480
|
+
|
481
|
+
expect(Zermelo::Filters::IndexRange).to receive(:new).
|
482
|
+
with(an_instance_of(Time), nil, :by_score => true).
|
483
|
+
and_return(end_range)
|
484
|
+
|
485
|
+
expect(unscheduled_maintenances).to receive(:intersect).
|
486
|
+
with(:start_time => start_range, :end_time => end_range).
|
487
|
+
and_return(no_unscheduled_maintenances)
|
488
|
+
expect(scheduled_maintenances).to receive(:intersect).
|
489
|
+
with(:start_time => start_range, :end_time => end_range).
|
490
|
+
and_return(no_scheduled_maintenances)
|
491
|
+
expect(check).to receive(:scheduled_maintenances).and_return(scheduled_maintenances)
|
492
|
+
expect(check).to receive(:unscheduled_maintenances).and_return(unscheduled_maintenances)
|
493
|
+
|
494
|
+
expect(checks).to receive(:count).and_return(5)
|
495
|
+
expect(checks).to receive(:sort).with(:name, :limit => 2).and_return(sorted_checks)
|
496
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
497
|
+
with(:name => Regexp.new("^example.com:p")).and_return(checks)
|
498
|
+
|
499
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
500
|
+
fji.instance_variable_set('@bot', bot)
|
501
|
+
fji.interpret('room1', 'jim', now.to_i, 'tell me about 2 checks matching /^example.com:p/')
|
502
|
+
end
|
503
|
+
|
504
|
+
it "interprets a received ACKID command" do
|
505
|
+
expect(bot).to receive(:announce).with('room1', "ACKing example.com:ping (abcd1234)")
|
506
|
+
|
507
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
508
|
+
expect(check).to receive(:in_unscheduled_maintenance?).and_return(false)
|
509
|
+
|
510
|
+
expect(checks).to receive(:all).and_return([check])
|
511
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
512
|
+
with(:ack_hash => 'abcd1234').and_return(checks)
|
513
|
+
|
514
|
+
expect(Flapjack::Data::Event).to receive(:create_acknowledgements).
|
515
|
+
with('events', [check],
|
516
|
+
:summary => 'JJ looking', :acknowledgement_id => 'abcd1234',
|
517
|
+
:duration => (60 * 60))
|
518
|
+
|
519
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
520
|
+
fji.instance_variable_set('@bot', bot)
|
521
|
+
fji.interpret('room1', 'jim', now.to_i, 'ACKID abcd1234 JJ looking duration: 1 hour')
|
522
|
+
end
|
523
|
+
|
524
|
+
it "interprets a received acknowledgement command (with check name)" do
|
525
|
+
expect(bot).to receive(:announce).with('room1', "Ack list:\nexample.com:ping")
|
526
|
+
|
527
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
528
|
+
with(Flapjack::Data::UnscheduledMaintenance).
|
529
|
+
and_yield
|
530
|
+
|
531
|
+
expect(checks).to receive(:empty?).and_return(false)
|
532
|
+
|
533
|
+
expect(checks).to receive(:count).and_return(5)
|
534
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
535
|
+
with(:name => 'example.com:ping').and_return(checks)
|
536
|
+
|
537
|
+
failing_checks = double('failing_checks')
|
538
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
539
|
+
with(:id => [check.id], :failing => true).and_return(failing_checks)
|
540
|
+
|
541
|
+
expect(failing_checks).to receive(:empty?).and_return(false)
|
542
|
+
|
543
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
544
|
+
expect(failing_checks).to receive(:map) {|&arg| [arg.call(check)] }
|
545
|
+
|
546
|
+
expect(Flapjack::Data::Event).to receive(:create_acknowledgements).
|
547
|
+
with('events', failing_checks,
|
548
|
+
:summary => 'jim: Set via chatbot', :duration => (60 * 60))
|
549
|
+
|
550
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
551
|
+
fji.instance_variable_set('@bot', bot)
|
552
|
+
fji.interpret('room1', 'jim', now.to_i, 'ack example.com:ping')
|
553
|
+
end
|
554
|
+
|
555
|
+
it "interprets a received acknowledgement command (with tag)" do
|
556
|
+
expect(bot).to receive(:announce).with('room1', "Ack list:\nexample.com:ping")
|
557
|
+
|
558
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
559
|
+
with(Flapjack::Data::Tag,
|
560
|
+
Flapjack::Data::UnscheduledMaintenance).
|
561
|
+
and_yield
|
562
|
+
|
563
|
+
expect(tag).to receive(:checks).and_return(checks)
|
564
|
+
|
565
|
+
expect(checks).to receive(:count).and_return(5)
|
566
|
+
|
567
|
+
failing_checks = double('failing_checks')
|
568
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
569
|
+
with(:id => [check.id], :failing => true).and_return(failing_checks)
|
570
|
+
|
571
|
+
expect(failing_checks).to receive(:empty?).and_return(false)
|
572
|
+
|
573
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
574
|
+
expect(failing_checks).to receive(:map) {|&arg| [arg.call(check)] }
|
575
|
+
|
576
|
+
expect(Flapjack::Data::Tag).to receive(:intersect).
|
577
|
+
with(:name => 'example.com').and_return(tags)
|
185
578
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
expect(EM::Hiredis).to receive(:connect).and_return(shutdown_redis)
|
579
|
+
expect(Flapjack::Data::Event).to receive(:create_acknowledgements).
|
580
|
+
with('events', failing_checks,
|
581
|
+
:summary => 'jim: Set via chatbot', :duration => (60 * 60))
|
190
582
|
|
191
|
-
|
192
|
-
|
193
|
-
|
583
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
584
|
+
fji.instance_variable_set('@bot', bot)
|
585
|
+
fji.interpret('room1', 'jim', now.to_i, 'ack checks with tag example.com')
|
586
|
+
end
|
587
|
+
|
588
|
+
it "interprets a received acknowledgement command (with regex)" do
|
589
|
+
expect(bot).to receive(:announce).with('room1', "Ack list:\nexample.com:ping")
|
590
|
+
|
591
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
592
|
+
with(Flapjack::Data::UnscheduledMaintenance).
|
593
|
+
and_yield
|
594
|
+
|
595
|
+
failing_checks = double('failing_checks')
|
596
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
597
|
+
with(:id => [check.id], :failing => true).and_return(failing_checks)
|
598
|
+
|
599
|
+
expect(failing_checks).to receive(:empty?).and_return(false)
|
600
|
+
|
601
|
+
expect(failing_checks).to receive(:map) {|&arg| [arg.call(check)] }
|
602
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
603
|
+
|
604
|
+
expect(checks).to receive(:count).and_return(5)
|
605
|
+
|
606
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
607
|
+
with(:name => Regexp.new("^example.com:p")).and_return(checks)
|
608
|
+
|
609
|
+
expect(Flapjack::Data::Event).to receive(:create_acknowledgements).
|
610
|
+
with('events', failing_checks,
|
611
|
+
:summary => 'jim: Set via chatbot', :duration => (60 * 60))
|
612
|
+
|
613
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
614
|
+
fji.instance_variable_set('@bot', bot)
|
615
|
+
fji.interpret('room1', 'jim', now.to_i, 'ack checks matching /^example.com:p/')
|
616
|
+
end
|
617
|
+
|
618
|
+
it "interprets a received maintenance command (with name)" do
|
619
|
+
now = Time.now
|
620
|
+
t = now.to_i + 60
|
621
|
+
expect(Time).to receive(:now).and_return(now)
|
622
|
+
|
623
|
+
expect(bot).to receive(:announce).with('room1',
|
624
|
+
"Scheduled maintenance for 180 minutes starting at #{Time.at(t)} on:\nexample.com:ping")
|
625
|
+
|
626
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
627
|
+
with(Flapjack::Data::ScheduledMaintenance).
|
628
|
+
and_yield
|
629
|
+
|
630
|
+
expect(Flapjack::Data::Check).to receive(:find_by_ids).with(check.id).and_return([check])
|
631
|
+
|
632
|
+
expect(checks).to receive(:empty?).and_return(false)
|
633
|
+
expect(checks).to receive(:count).and_return(5)
|
634
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
635
|
+
with(:name => 'example.com:ping').and_return(checks)
|
636
|
+
|
637
|
+
sched_maint = double(Flapjack::Data::ScheduledMaintenance)
|
638
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:new).with(
|
639
|
+
:start_time => t,
|
640
|
+
:end_time => t + (3 * 60 * 60),
|
641
|
+
:summary => 'test'
|
642
|
+
).and_return(sched_maint)
|
643
|
+
expect(sched_maint).to receive(:save).and_return(true)
|
644
|
+
|
645
|
+
sched_maints = double('sched_maints')
|
646
|
+
expect(sched_maints).to receive(:<<).with(sched_maint)
|
647
|
+
expect(check).to receive(:scheduled_maintenances).and_return(sched_maints)
|
648
|
+
|
649
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
650
|
+
|
651
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
652
|
+
fji.instance_variable_set('@bot', bot)
|
653
|
+
fji.interpret('room1', 'jim', now.to_i, 'maint example.com:ping start-in: 1 minute duration: 3 hour comment: test')
|
654
|
+
end
|
655
|
+
|
656
|
+
it "interprets a received maintenance command (with tag)" do
|
657
|
+
now = Time.now
|
658
|
+
t = now.to_i + 60
|
659
|
+
expect(Time).to receive(:now).and_return(now)
|
660
|
+
|
661
|
+
expect(bot).to receive(:announce).with('room1',
|
662
|
+
"Scheduled maintenance for 180 minutes starting at #{Time.at(t)} on:\nexample.com:ping")
|
663
|
+
|
664
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
665
|
+
with(Flapjack::Data::Tag, Flapjack::Data::ScheduledMaintenance).
|
666
|
+
and_yield
|
667
|
+
|
668
|
+
expect(Flapjack::Data::Check).to receive(:find_by_ids).with(check.id).and_return([check])
|
669
|
+
|
670
|
+
expect(checks).to receive(:count).and_return(5)
|
671
|
+
expect(tag).to receive(:checks).and_return(checks)
|
672
|
+
|
673
|
+
expect(Flapjack::Data::Tag).to receive(:intersect).
|
674
|
+
with(:name => 'example.com').and_return(tags)
|
675
|
+
|
676
|
+
sched_maint = double(Flapjack::Data::ScheduledMaintenance)
|
677
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:new).with(
|
678
|
+
:start_time => t,
|
679
|
+
:end_time => t + (3 * 60 * 60),
|
680
|
+
:summary => 'test'
|
681
|
+
).and_return(sched_maint)
|
682
|
+
expect(sched_maint).to receive(:save).and_return(true)
|
683
|
+
|
684
|
+
sched_maints = double('sched_maints')
|
685
|
+
expect(sched_maints).to receive(:<<).with(sched_maint)
|
686
|
+
expect(check).to receive(:scheduled_maintenances).and_return(sched_maints)
|
687
|
+
|
688
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
689
|
+
|
690
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
691
|
+
fji.instance_variable_set('@bot', bot)
|
692
|
+
fji.interpret('room1', 'jim', now.to_i, 'maint checks with tag example.com start-in: 1 minute duration: 3 hour comment: test')
|
693
|
+
end
|
694
|
+
|
695
|
+
it "interprets a received maintenance command (with regex)" do
|
696
|
+
now = Time.now
|
697
|
+
t = now.to_i + 60
|
698
|
+
expect(Time).to receive(:now).and_return(now)
|
699
|
+
|
700
|
+
expect(bot).to receive(:announce).with('room1',
|
701
|
+
"Scheduled maintenance for 180 minutes starting at #{Time.at(t)} on:\nexample.com:ping")
|
702
|
+
|
703
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
704
|
+
with(Flapjack::Data::ScheduledMaintenance).
|
705
|
+
and_yield
|
706
|
+
|
707
|
+
expect(Flapjack::Data::Check).to receive(:find_by_ids).with(check.id).and_return([check])
|
708
|
+
|
709
|
+
expect(checks).to receive(:count).and_return(5)
|
710
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
711
|
+
with(:name => Regexp.new("^example.com:p")).and_return(checks)
|
712
|
+
|
713
|
+
sched_maint = double(Flapjack::Data::ScheduledMaintenance)
|
714
|
+
expect(Flapjack::Data::ScheduledMaintenance).to receive(:new).with(
|
715
|
+
:start_time => t,
|
716
|
+
:end_time => t + (3 * 60 * 60),
|
717
|
+
:summary => 'test'
|
718
|
+
).and_return(sched_maint)
|
719
|
+
expect(sched_maint).to receive(:save).and_return(true)
|
720
|
+
|
721
|
+
sched_maints = double('sched_maints')
|
722
|
+
expect(sched_maints).to receive(:<<).with(sched_maint)
|
723
|
+
expect(check).to receive(:scheduled_maintenances).and_return(sched_maints)
|
724
|
+
|
725
|
+
expect(check).to receive(:name).and_return('example.com:ping')
|
726
|
+
|
727
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
728
|
+
fji.instance_variable_set('@bot', bot)
|
729
|
+
fji.interpret('room1', 'jim', now.to_i, 'maint checks matching /^example.com:p/ start-in: 1 minute duration: 3 hour comment: test')
|
730
|
+
end
|
731
|
+
|
732
|
+
it "interprets a received test notifications command (with name)" do
|
733
|
+
expect(bot).to receive(:announce).with('room1', /Testing notifications for check with name 'example.com:ping'/)
|
734
|
+
|
735
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
736
|
+
with(no_args).
|
737
|
+
and_yield
|
738
|
+
|
739
|
+
expect(Flapjack::Data::Check).to receive(:find_by_ids).with(check.id).and_return([check])
|
740
|
+
|
741
|
+
expect(checks).to receive(:empty?).and_return(false)
|
742
|
+
expect(checks).to receive(:count).and_return(5)
|
743
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
744
|
+
with(:name => 'example.com:ping').and_return(checks)
|
745
|
+
|
746
|
+
expect(Flapjack::Data::Event).to receive(:test_notifications).
|
747
|
+
with('events', [check], an_instance_of(Hash))
|
748
|
+
|
749
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
750
|
+
fji.instance_variable_set('@bot', bot)
|
751
|
+
fji.interpret('room1', 'jim', now.to_i, 'test notifications for example.com:ping')
|
752
|
+
end
|
753
|
+
|
754
|
+
it "interprets a received test notifications command (with tag)" do
|
755
|
+
expect(bot).to receive(:announce).with('room1', /Testing notifications for check with tag 'example.com'/)
|
756
|
+
|
757
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
758
|
+
with(Flapjack::Data::Tag).
|
759
|
+
and_yield
|
760
|
+
|
761
|
+
expect(Flapjack::Data::Check).to receive(:find_by_ids).with(check.id).and_return([check])
|
762
|
+
|
763
|
+
expect(checks).to receive(:count).and_return(5)
|
764
|
+
expect(tag).to receive(:checks).and_return(checks)
|
765
|
+
|
766
|
+
expect(Flapjack::Data::Tag).to receive(:intersect).
|
767
|
+
with(:name => 'example.com').and_return(tags)
|
768
|
+
|
769
|
+
expect(Flapjack::Data::Event).to receive(:test_notifications).
|
770
|
+
with('events', [check], an_instance_of(Hash))
|
771
|
+
|
772
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
773
|
+
fji.instance_variable_set('@bot', bot)
|
774
|
+
fji.interpret('room1', 'jim', now.to_i, 'test notifications for checks with tag example.com')
|
775
|
+
end
|
776
|
+
|
777
|
+
it "interprets a received test notifications command (with regex)" do
|
778
|
+
expect(bot).to receive(:announce).with('room1', /Testing notifications for check matching \/\^example.com:p\//)
|
779
|
+
|
780
|
+
expect(Flapjack::Data::Check).to receive(:lock).
|
781
|
+
with(no_args).
|
782
|
+
and_yield
|
783
|
+
|
784
|
+
expect(Flapjack::Data::Check).to receive(:find_by_ids).with(check.id).and_return([check])
|
785
|
+
|
786
|
+
expect(checks).to receive(:count).and_return(5)
|
787
|
+
expect(Flapjack::Data::Check).to receive(:intersect).
|
788
|
+
with(:name => Regexp.new("^example.com:p")).and_return(checks)
|
789
|
+
|
790
|
+
expect(Flapjack::Data::Event).to receive(:test_notifications).
|
791
|
+
with('events', [check], an_instance_of(Hash))
|
792
|
+
|
793
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
794
|
+
fji.instance_variable_set('@bot', bot)
|
795
|
+
fji.interpret('room1', 'jim', now.to_i, 'test notifications for checks matching /^example.com:p/')
|
796
|
+
end
|
797
|
+
|
798
|
+
it "doesn't interpret an unmatched command" do
|
799
|
+
expect(bot).to receive(:announce).with('room1', /^what do you mean/)
|
800
|
+
|
801
|
+
fji = Flapjack::Gateways::Jabber::Interpreter.new(:config => config)
|
802
|
+
fji.instance_variable_set('@bot', bot)
|
803
|
+
fji.interpret('room1', 'jim', now.to_i, 'hello!')
|
804
|
+
end
|
194
805
|
|
195
|
-
fj.stop
|
196
806
|
end
|
197
807
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
808
|
+
context 'XMPP' do
|
809
|
+
|
810
|
+
let(:client) { double(::Jabber::Client) }
|
811
|
+
let(:muc_client) { double(::Jabber::MUC::SimpleMUCClient) }
|
812
|
+
let(:muc_clients) { {config['rooms'].first => muc_client} }
|
813
|
+
|
814
|
+
# TODO use separate threads in the test instead?
|
815
|
+
it "starts and is stopped by a signal" do
|
816
|
+
interpreter = double(Flapjack::Gateways::Jabber::Interpreter)
|
817
|
+
expect(interpreter).to receive(:respond_to?).with(:interpret).and_return(true)
|
818
|
+
expect(interpreter).to receive(:receive_message).with(nil, 'jim', nil, 'hello!')
|
819
|
+
expect(interpreter).to receive(:receive_message).with(config['rooms'].first, 'jim', now.to_i, 'hello!')
|
820
|
+
|
821
|
+
expect(client).to receive(:on_exception)
|
822
|
+
|
823
|
+
msg_client = double('msg_client')
|
824
|
+
expect(msg_client).to receive(:type).and_return(:chat)
|
825
|
+
expect(msg_client).to receive(:body).exactly(3).times.and_return('hello!')
|
826
|
+
expect(msg_client).to receive(:from).and_return('jim')
|
827
|
+
expect(msg_client).to receive(:each_element).and_yield([]) # TODO improve
|
828
|
+
|
829
|
+
expect(client).to receive(:add_message_callback).and_yield(msg_client)
|
830
|
+
|
831
|
+
expect(muc_client).to receive(:on_message).and_yield(now.to_i, 'jim', 'flapjack: hello!')
|
832
|
+
expect(client).to receive(:is_connected?).times.and_return(true)
|
833
|
+
|
834
|
+
expect(::Jabber::Client).to receive(:new).and_return(client)
|
835
|
+
expect(::Jabber::MUC::SimpleMUCClient).to receive(:new).and_return(muc_client)
|
836
|
+
|
837
|
+
expect(lock).to receive(:synchronize).twice.and_yield
|
838
|
+
stop_cond = double(MonitorMixin::ConditionVariable)
|
839
|
+
|
840
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
841
|
+
:stop_condition => stop_cond, :config => config)
|
842
|
+
expect(stop_cond).to receive(:wait_until) {
|
843
|
+
fjb.instance_variable_set('@should_quit', true)
|
844
|
+
}
|
845
|
+
fjb.instance_variable_set('@siblings', [interpreter])
|
846
|
+
|
847
|
+
expect(fjb).to receive(:_join).with(client, muc_clients)
|
848
|
+
expect(fjb).to receive(:_leave).with(client, muc_clients)
|
849
|
+
|
850
|
+
fjb.start
|
851
|
+
end
|
852
|
+
|
853
|
+
it "should handle an exception and signal for leave and rejoin"
|
854
|
+
|
855
|
+
it "strips XML from a received string"
|
856
|
+
|
857
|
+
it "handles an announce state change" do
|
858
|
+
expect(client).to receive(:is_connected?).and_return(true)
|
859
|
+
|
860
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
861
|
+
:config => config)
|
862
|
+
expect(fjb).to receive(:_announce).with(muc_clients)
|
863
|
+
fjb.instance_variable_set('@state_buffer', ['announce'])
|
864
|
+
fjb.handle_state_change(client, muc_clients)
|
865
|
+
end
|
866
|
+
|
867
|
+
it "handles a say state change" do
|
868
|
+
expect(client).to receive(:is_connected?).and_return(true)
|
869
|
+
|
870
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
871
|
+
:config => config)
|
872
|
+
expect(fjb).to receive(:_say).with(client)
|
873
|
+
fjb.instance_variable_set('@state_buffer', ['say'])
|
874
|
+
fjb.handle_state_change(client, muc_clients)
|
875
|
+
end
|
876
|
+
|
877
|
+
it "handles a leave state change (when connected)" do
|
878
|
+
expect(client).to receive(:is_connected?).and_return(true)
|
879
|
+
|
880
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
881
|
+
:config => config)
|
882
|
+
expect(fjb).to receive(:_leave).with(client, muc_clients)
|
883
|
+
fjb.instance_variable_set('@state_buffer', ['leave'])
|
884
|
+
fjb.handle_state_change(client, muc_clients)
|
885
|
+
end
|
886
|
+
|
887
|
+
it "handles a leave state change (when not connected)" do
|
888
|
+
expect(client).to receive(:is_connected?).and_return(false)
|
889
|
+
|
890
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
891
|
+
:config => config)
|
892
|
+
expect(fjb).to receive(:_deactivate).with(muc_clients)
|
893
|
+
fjb.instance_variable_set('@state_buffer', ['leave'])
|
894
|
+
fjb.handle_state_change(client, muc_clients)
|
895
|
+
end
|
896
|
+
|
897
|
+
it "handles a rejoin state change" do
|
898
|
+
expect(client).to receive(:is_connected?).and_return(false)
|
899
|
+
|
900
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
901
|
+
:config => config)
|
902
|
+
expect(fjb).to receive(:_join).with(client, muc_clients, :rejoin => true)
|
903
|
+
fjb.instance_variable_set('@state_buffer', ['rejoin'])
|
904
|
+
fjb.handle_state_change(client, muc_clients)
|
905
|
+
end
|
906
|
+
|
907
|
+
it "joins the jabber client with chatbot_announce on" do
|
908
|
+
expect(client).to receive(:connect)
|
909
|
+
expect(client).to receive(:auth).with('password')
|
910
|
+
expect(client).to receive(:send) # .with(kind_of(::Jabber::Presence))
|
911
|
+
|
912
|
+
expect(lock).to receive(:synchronize).twice.and_yield.and_yield
|
913
|
+
|
914
|
+
expect(muc_client).to receive(:join).with('flapjacktest@conference.example.com/flapjack', nil, :history => false)
|
915
|
+
expect(muc_client).to receive(:say).with(/^flapjack jabber gateway started/)
|
916
|
+
|
917
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
918
|
+
:config => config)
|
919
|
+
fjb._join(client, muc_clients)
|
920
|
+
end
|
921
|
+
|
922
|
+
it "joins the jabber client with chatbot_announce off" do
|
923
|
+
config['chatbot_announce'] = false
|
924
|
+
expect(client).to receive(:connect)
|
925
|
+
expect(client).to receive(:auth).with('password')
|
926
|
+
expect(client).to receive(:send) # .with(kind_of(::Jabber::Presence))
|
927
|
+
|
928
|
+
expect(lock).to receive(:synchronize).twice.and_yield.and_yield
|
929
|
+
|
930
|
+
expect(muc_client).to receive(:join).with('flapjacktest@conference.example.com/flapjack', nil, :history => false)
|
931
|
+
expect(muc_client).to_not receive(:say).with(/^flapjack jabber gateway started/)
|
932
|
+
|
933
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
934
|
+
:config => config)
|
935
|
+
fjb._join(client, muc_clients)
|
936
|
+
end
|
937
|
+
|
938
|
+
it "rejoins the jabber client with chatbot_announce on" do
|
939
|
+
expect(client).to receive(:connect)
|
940
|
+
expect(client).to receive(:auth).with('password')
|
941
|
+
expect(client).to receive(:send).with(an_instance_of(::Jabber::Presence))
|
942
|
+
|
943
|
+
expect(lock).to receive(:synchronize).twice.and_yield.and_yield
|
944
|
+
|
945
|
+
expect(muc_client).to receive(:join).with('flapjacktest@conference.example.com/flapjack', nil, :history => false)
|
946
|
+
expect(muc_client).to receive(:say).with(/^flapjack jabber gateway rejoining/)
|
947
|
+
|
948
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
949
|
+
:config => config)
|
950
|
+
fjb._join(client, muc_clients, :rejoin => true)
|
951
|
+
end
|
952
|
+
|
953
|
+
it "rejoins the jabber client with chatbot_announce off" do
|
954
|
+
config['chatbot_announce'] = false
|
955
|
+
expect(client).to receive(:connect)
|
956
|
+
expect(client).to receive(:auth).with('password')
|
957
|
+
expect(client).to receive(:send).with(an_instance_of(::Jabber::Presence))
|
958
|
+
|
959
|
+
expect(lock).to receive(:synchronize).twice.and_yield.and_yield
|
960
|
+
|
961
|
+
expect(muc_client).to receive(:join).with('flapjacktest@conference.example.com/flapjack', nil, :history => false)
|
962
|
+
expect(muc_client).to_not receive(:say).with(/^flapjack jabber gateway rejoining/)
|
963
|
+
|
964
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
965
|
+
:config => config)
|
966
|
+
fjb._join(client, muc_clients, :rejoin => true)
|
967
|
+
end
|
968
|
+
|
969
|
+
it "leaves the jabber client (connected)" do
|
970
|
+
expect(muc_client).to receive(:active?).and_return(true)
|
971
|
+
expect(muc_client).to receive(:exit)
|
972
|
+
expect(client).to receive(:close)
|
973
|
+
|
974
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
975
|
+
:config => config)
|
976
|
+
fjb.instance_variable_set('@joined', true)
|
977
|
+
fjb._leave(client, muc_clients)
|
978
|
+
end
|
979
|
+
|
980
|
+
it "deactivates the jabber client (not connected)" do
|
981
|
+
expect(muc_client).to receive(:deactivate)
|
982
|
+
|
983
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock,
|
984
|
+
:config => config)
|
985
|
+
fjb._deactivate(muc_clients)
|
986
|
+
end
|
987
|
+
|
988
|
+
it "speaks its announce buffer" do
|
989
|
+
expect(muc_client).to receive(:active?).and_return(true)
|
990
|
+
expect(muc_client).to receive(:say).with('hello!')
|
991
|
+
|
992
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock, :config => config)
|
993
|
+
fjb.instance_variable_set('@announce_buffer', [{:room => 'room1', :msg => 'hello!'}])
|
994
|
+
fjb._announce('room1' => muc_client)
|
995
|
+
end
|
202
996
|
|
203
|
-
|
997
|
+
it "speaks its say buffer" do
|
998
|
+
message = double(::Jabber::Message)
|
999
|
+
expect(message).to receive(:type=).with(:chat)
|
1000
|
+
expect(::Jabber::Message).to receive(:new).
|
1001
|
+
with('jim', 'hello!').and_return(message)
|
204
1002
|
|
205
|
-
|
206
|
-
fj = Flapjack::Gateways::Jabber.new(:config => config, :logger => @logger)
|
207
|
-
expect(fj).to receive(:register_handler).exactly(4).times
|
1003
|
+
expect(client).to receive(:send).with(message)
|
208
1004
|
|
209
|
-
|
210
|
-
|
1005
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock, :config => config)
|
1006
|
+
fjb.instance_variable_set('@say_buffer', [{:nick => 'jim', :msg => 'hello!'}])
|
1007
|
+
fjb._say(client)
|
1008
|
+
end
|
211
1009
|
|
212
|
-
|
1010
|
+
it "buffers an announce message and sends a signal" do
|
1011
|
+
expect(lock).to receive(:synchronize).and_yield
|
1012
|
+
expect(stop_cond).to receive(:signal)
|
213
1013
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
else
|
221
|
-
fj.instance_variable_set('@should_quit', true)
|
222
|
-
["jabber_notifications", %q{{"notification_type":"shutdown"}}]
|
223
|
-
end
|
224
|
-
}
|
1014
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock, :stop_condition => stop_cond,
|
1015
|
+
:config => config)
|
1016
|
+
fjb.announce('room1', 'hello!')
|
1017
|
+
expect(fjb.instance_variable_get('@state_buffer')).to eq(['announce'])
|
1018
|
+
expect(fjb.instance_variable_get('@announce_buffer')).to eq([{:room => 'room1', :msg => 'hello!'}])
|
1019
|
+
end
|
225
1020
|
|
226
|
-
|
227
|
-
|
228
|
-
|
1021
|
+
it "buffers a say message and sends a signal" do
|
1022
|
+
expect(lock).to receive(:synchronize).and_yield
|
1023
|
+
expect(stop_cond).to receive(:signal)
|
229
1024
|
|
230
|
-
|
1025
|
+
fjb = Flapjack::Gateways::Jabber::Bot.new(:lock => lock, :stop_condition => stop_cond,
|
1026
|
+
:config => config)
|
1027
|
+
fjb.say('jim', 'hello!')
|
1028
|
+
expect(fjb.instance_variable_get('@state_buffer')).to eq(['say'])
|
1029
|
+
expect(fjb.instance_variable_get('@say_buffer')).to eq([{:nick => 'jim', :msg => 'hello!'}])
|
1030
|
+
end
|
231
1031
|
|
232
|
-
expect(@logger.errors).to be_empty
|
233
1032
|
end
|
234
1033
|
|
235
1034
|
end
|