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.
Files changed (301) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -6
  3. data/.gitmodules +1 -1
  4. data/.rspec +1 -1
  5. data/.ruby-version +1 -1
  6. data/.travis.yml +12 -13
  7. data/CHANGELOG.md +2 -9
  8. data/CONTRIBUTING.md +7 -2
  9. data/Gemfile +4 -13
  10. data/LICENCE +1 -0
  11. data/README.md +8 -2
  12. data/Rakefile +2 -2
  13. data/bin/flapjack +3 -12
  14. data/build.sh +4 -2
  15. data/etc/flapjack_config.toml.example +273 -0
  16. data/features/ack_after_sched_maint.feature +18 -21
  17. data/features/cli.feature +11 -71
  18. data/features/cli_flapjack-feed-events.feature +14 -15
  19. data/features/cli_flapjack-nagios-receiver.feature +12 -41
  20. data/features/cli_flapper.feature +12 -41
  21. data/features/cli_purge.feature +5 -6
  22. data/features/cli_receive-events.feature +6 -7
  23. data/features/cli_simulate-failed-check.feature +5 -6
  24. data/features/events.feature +206 -181
  25. data/features/events_check_names.feature +4 -7
  26. data/features/notification_rules.feature +144 -223
  27. data/features/notifications.feature +65 -57
  28. data/features/rollup.feature +45 -47
  29. data/features/steps/cli_steps.rb +4 -5
  30. data/features/steps/events_steps.rb +163 -373
  31. data/features/steps/notifications_steps.rb +408 -264
  32. data/features/steps/packaging-lintian_steps.rb +0 -4
  33. data/features/steps/time_travel_steps.rb +0 -26
  34. data/features/support/daemons.rb +6 -31
  35. data/features/support/env.rb +65 -74
  36. data/flapjack.gemspec +22 -24
  37. data/lib/flapjack.rb +14 -7
  38. data/lib/flapjack/cli/flapper.rb +74 -173
  39. data/lib/flapjack/cli/maintenance.rb +278 -109
  40. data/lib/flapjack/cli/migrate.rb +950 -0
  41. data/lib/flapjack/cli/purge.rb +19 -22
  42. data/lib/flapjack/cli/receiver.rb +150 -326
  43. data/lib/flapjack/cli/server.rb +8 -235
  44. data/lib/flapjack/cli/simulate.rb +42 -57
  45. data/lib/flapjack/configuration.rb +51 -37
  46. data/lib/flapjack/coordinator.rb +138 -129
  47. data/lib/flapjack/data/acknowledgement.rb +177 -0
  48. data/lib/flapjack/data/alert.rb +97 -158
  49. data/lib/flapjack/data/check.rb +611 -0
  50. data/lib/flapjack/data/condition.rb +70 -0
  51. data/lib/flapjack/data/contact.rb +226 -456
  52. data/lib/flapjack/data/event.rb +96 -184
  53. data/lib/flapjack/data/extensions/associations.rb +59 -0
  54. data/lib/flapjack/data/extensions/short_name.rb +25 -0
  55. data/lib/flapjack/data/medium.rb +428 -0
  56. data/lib/flapjack/data/metrics.rb +194 -0
  57. data/lib/flapjack/data/notification.rb +22 -281
  58. data/lib/flapjack/data/rule.rb +473 -0
  59. data/lib/flapjack/data/scheduled_maintenance.rb +244 -0
  60. data/lib/flapjack/data/state.rb +221 -0
  61. data/lib/flapjack/data/statistic.rb +112 -0
  62. data/lib/flapjack/data/tag.rb +277 -0
  63. data/lib/flapjack/data/test_notification.rb +182 -0
  64. data/lib/flapjack/data/unscheduled_maintenance.rb +159 -0
  65. data/lib/flapjack/data/validators/id_validator.rb +20 -0
  66. data/lib/flapjack/exceptions.rb +6 -0
  67. data/lib/flapjack/filters/acknowledgement.rb +23 -16
  68. data/lib/flapjack/filters/base.rb +0 -5
  69. data/lib/flapjack/filters/delays.rb +53 -43
  70. data/lib/flapjack/filters/ok.rb +23 -14
  71. data/lib/flapjack/filters/scheduled_maintenance.rb +3 -3
  72. data/lib/flapjack/filters/unscheduled_maintenance.rb +12 -3
  73. data/lib/flapjack/gateways/aws_sns.rb +65 -49
  74. data/lib/flapjack/gateways/aws_sns/alert.text.erb +2 -2
  75. data/lib/flapjack/gateways/aws_sns/alert_subject.text.erb +2 -2
  76. data/lib/flapjack/gateways/aws_sns/rollup_subject.text.erb +1 -1
  77. data/lib/flapjack/gateways/email.rb +107 -90
  78. data/lib/flapjack/gateways/email/alert.html.erb +19 -18
  79. data/lib/flapjack/gateways/email/alert.text.erb +20 -14
  80. data/lib/flapjack/gateways/email/alert_subject.text.erb +2 -1
  81. data/lib/flapjack/gateways/email/rollup.html.erb +14 -13
  82. data/lib/flapjack/gateways/email/rollup.text.erb +13 -10
  83. data/lib/flapjack/gateways/jabber.rb +679 -671
  84. data/lib/flapjack/gateways/jabber/alert.text.erb +9 -6
  85. data/lib/flapjack/gateways/jsonapi.rb +164 -350
  86. data/lib/flapjack/gateways/jsonapi/data/join_descriptor.rb +44 -0
  87. data/lib/flapjack/gateways/jsonapi/data/method_descriptor.rb +21 -0
  88. data/lib/flapjack/gateways/jsonapi/helpers/headers.rb +63 -0
  89. data/lib/flapjack/gateways/jsonapi/helpers/miscellaneous.rb +136 -0
  90. data/lib/flapjack/gateways/jsonapi/helpers/resources.rb +227 -0
  91. data/lib/flapjack/gateways/jsonapi/helpers/serialiser.rb +313 -0
  92. data/lib/flapjack/gateways/jsonapi/helpers/swagger_docs.rb +322 -0
  93. data/lib/flapjack/gateways/jsonapi/methods/association_delete.rb +115 -0
  94. data/lib/flapjack/gateways/jsonapi/methods/association_get.rb +288 -0
  95. data/lib/flapjack/gateways/jsonapi/methods/association_patch.rb +178 -0
  96. data/lib/flapjack/gateways/jsonapi/methods/association_post.rb +116 -0
  97. data/lib/flapjack/gateways/jsonapi/methods/metrics.rb +71 -0
  98. data/lib/flapjack/gateways/jsonapi/methods/resource_delete.rb +119 -0
  99. data/lib/flapjack/gateways/jsonapi/methods/resource_get.rb +186 -0
  100. data/lib/flapjack/gateways/jsonapi/methods/resource_patch.rb +239 -0
  101. data/lib/flapjack/gateways/jsonapi/methods/resource_post.rb +197 -0
  102. data/lib/flapjack/gateways/jsonapi/middleware/array_param_fixer.rb +27 -0
  103. data/lib/flapjack/gateways/jsonapi/{rack → middleware}/json_params_parser.rb +7 -6
  104. data/lib/flapjack/gateways/jsonapi/middleware/request_timestamp.rb +18 -0
  105. data/lib/flapjack/gateways/oobetet.rb +222 -170
  106. data/lib/flapjack/gateways/pager_duty.rb +388 -0
  107. data/lib/flapjack/gateways/pager_duty/alert.text.erb +13 -0
  108. data/lib/flapjack/gateways/slack.rb +56 -48
  109. data/lib/flapjack/gateways/slack/alert.text.erb +1 -1
  110. data/lib/flapjack/gateways/slack/rollup.text.erb +1 -1
  111. data/lib/flapjack/gateways/sms_aspsms.rb +155 -0
  112. data/lib/flapjack/gateways/sms_aspsms/alert.text.erb +7 -0
  113. data/lib/flapjack/gateways/sms_aspsms/rollup.text.erb +2 -0
  114. data/lib/flapjack/gateways/sms_messagenet.rb +77 -57
  115. data/lib/flapjack/gateways/sms_messagenet/alert.text.erb +3 -2
  116. data/lib/flapjack/gateways/sms_nexmo.rb +53 -51
  117. data/lib/flapjack/gateways/sms_nexmo/alert.text.erb +2 -2
  118. data/lib/flapjack/gateways/sms_nexmo/rollup.text.erb +1 -1
  119. data/lib/flapjack/gateways/sms_twilio.rb +79 -62
  120. data/lib/flapjack/gateways/sms_twilio/alert.text.erb +3 -2
  121. data/lib/flapjack/gateways/web.rb +437 -345
  122. data/lib/flapjack/gateways/web/middleware/request_timestamp.rb +18 -0
  123. data/lib/flapjack/gateways/web/public/css/bootstrap.css +3793 -4340
  124. data/lib/flapjack/gateways/web/public/css/bootstrap.css.map +1 -0
  125. data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.eot +0 -0
  126. data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.svg +273 -214
  127. data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.ttf +0 -0
  128. data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.woff +0 -0
  129. data/lib/flapjack/gateways/web/public/fonts/glyphicons-halflings-regular.woff2 +0 -0
  130. data/lib/flapjack/gateways/web/public/js/bootstrap.js +1637 -1607
  131. data/lib/flapjack/gateways/web/public/js/self_stats.js +1 -2
  132. data/lib/flapjack/gateways/web/views/_pagination.html.erb +19 -0
  133. data/lib/flapjack/gateways/web/views/check.html.erb +159 -121
  134. data/lib/flapjack/gateways/web/views/checks.html.erb +82 -41
  135. data/lib/flapjack/gateways/web/views/contact.html.erb +59 -71
  136. data/lib/flapjack/gateways/web/views/contacts.html.erb +32 -8
  137. data/lib/flapjack/gateways/web/views/index.html.erb +2 -2
  138. data/lib/flapjack/gateways/web/views/{layout.erb → layout.html.erb} +7 -23
  139. data/lib/flapjack/gateways/web/views/self_stats.html.erb +32 -33
  140. data/lib/flapjack/gateways/web/views/tag.html.erb +32 -0
  141. data/lib/flapjack/gateways/web/views/tags.html.erb +51 -0
  142. data/lib/flapjack/logger.rb +34 -3
  143. data/lib/flapjack/notifier.rb +180 -112
  144. data/lib/flapjack/patches.rb +8 -63
  145. data/lib/flapjack/pikelet.rb +185 -143
  146. data/lib/flapjack/processor.rb +323 -191
  147. data/lib/flapjack/record_queue.rb +33 -0
  148. data/lib/flapjack/redis_proxy.rb +66 -0
  149. data/lib/flapjack/utility.rb +21 -15
  150. data/lib/flapjack/version.rb +2 -1
  151. data/libexec/httpbroker.go +218 -14
  152. data/libexec/oneoff.go +13 -10
  153. data/spec/lib/flapjack/configuration_spec.rb +286 -0
  154. data/spec/lib/flapjack/coordinator_spec.rb +103 -157
  155. data/spec/lib/flapjack/data/check_spec.rb +175 -0
  156. data/spec/lib/flapjack/data/contact_spec.rb +26 -349
  157. data/spec/lib/flapjack/data/event_spec.rb +76 -291
  158. data/spec/lib/flapjack/data/medium_spec.rb +19 -0
  159. data/spec/lib/flapjack/data/rule_spec.rb +43 -0
  160. data/spec/lib/flapjack/data/scheduled_maintenance_spec.rb +976 -0
  161. data/spec/lib/flapjack/data/unscheduled_maintenance_spec.rb +34 -0
  162. data/spec/lib/flapjack/gateways/aws_sns_spec.rb +111 -60
  163. data/spec/lib/flapjack/gateways/email_spec.rb +194 -161
  164. data/spec/lib/flapjack/gateways/jabber_spec.rb +961 -162
  165. data/spec/lib/flapjack/gateways/jsonapi/methods/check_links_spec.rb +155 -0
  166. data/spec/lib/flapjack/gateways/jsonapi/methods/checks_spec.rb +426 -0
  167. data/spec/lib/flapjack/gateways/jsonapi/methods/contact_links_spec.rb +217 -0
  168. data/spec/lib/flapjack/gateways/jsonapi/methods/contacts_spec.rb +425 -0
  169. data/spec/lib/flapjack/gateways/jsonapi/methods/events_spec.rb +271 -0
  170. data/spec/lib/flapjack/gateways/jsonapi/methods/media_spec.rb +257 -0
  171. data/spec/lib/flapjack/gateways/jsonapi/methods/medium_links_spec.rb +163 -0
  172. data/spec/lib/flapjack/gateways/jsonapi/methods/metrics_spec.rb +8 -0
  173. data/spec/lib/flapjack/gateways/jsonapi/methods/rule_links_spec.rb +212 -0
  174. data/spec/lib/flapjack/gateways/jsonapi/methods/rules_spec.rb +289 -0
  175. data/spec/lib/flapjack/gateways/jsonapi/methods/scheduled_maintenance_links_spec.rb +49 -0
  176. data/spec/lib/flapjack/gateways/jsonapi/methods/scheduled_maintenances_spec.rb +242 -0
  177. data/spec/lib/flapjack/gateways/jsonapi/methods/tag_links_spec.rb +274 -0
  178. data/spec/lib/flapjack/gateways/jsonapi/methods/tags_spec.rb +302 -0
  179. data/spec/lib/flapjack/gateways/jsonapi/methods/unscheduled_maintenance_links_spec.rb +49 -0
  180. data/spec/lib/flapjack/gateways/jsonapi/methods/unscheduled_maintenances_spec.rb +339 -0
  181. data/spec/lib/flapjack/gateways/jsonapi_spec.rb +1 -1
  182. data/spec/lib/flapjack/gateways/oobetet_spec.rb +151 -79
  183. data/spec/lib/flapjack/gateways/pager_duty_spec.rb +353 -0
  184. data/spec/lib/flapjack/gateways/slack_spec.rb +53 -53
  185. data/spec/lib/flapjack/gateways/sms_aspsms_spec.rb +106 -0
  186. data/spec/lib/flapjack/gateways/sms_messagenet_spec.rb +111 -54
  187. data/spec/lib/flapjack/gateways/sms_nexmo_spec.rb +50 -51
  188. data/spec/lib/flapjack/gateways/sms_twilio_spec.rb +108 -48
  189. data/spec/lib/flapjack/gateways/web_spec.rb +144 -216
  190. data/spec/lib/flapjack/notifier_spec.rb +132 -1
  191. data/spec/lib/flapjack/pikelet_spec.rb +111 -50
  192. data/spec/lib/flapjack/processor_spec.rb +210 -40
  193. data/spec/lib/flapjack/redis_proxy_spec.rb +45 -0
  194. data/spec/lib/flapjack/utility_spec.rb +11 -15
  195. data/spec/service_consumers/fixture_data.rb +547 -0
  196. data/spec/service_consumers/pact_helper.rb +21 -32
  197. data/spec/service_consumers/pacts/flapjack-diner_v2.0.json +4652 -0
  198. data/spec/service_consumers/provider_states_for_flapjack-diner.rb +279 -322
  199. data/spec/service_consumers/provider_support.rb +8 -0
  200. data/spec/spec_helper.rb +34 -44
  201. data/spec/support/erb_view_helper.rb +1 -1
  202. data/spec/support/factories.rb +58 -0
  203. data/spec/support/jsonapi_helper.rb +15 -26
  204. data/spec/support/mock_logger.rb +43 -0
  205. data/spec/support/xmpp_comparable.rb +24 -0
  206. data/src/flapjack/transport_test.go +30 -1
  207. data/tasks/dump_keys.rake +82 -0
  208. data/tasks/events.rake +7 -7
  209. data/tasks/support/flapjack_config_benchmark.toml +28 -0
  210. data/tasks/support/flapjack_config_benchmark.yaml +0 -2
  211. metadata +175 -222
  212. data/Guardfile +0 -14
  213. data/etc/flapjack_config.yaml.example +0 -477
  214. data/features/cli_flapjack-populator.feature +0 -90
  215. data/features/support/silent_system.rb +0 -4
  216. data/lib/flapjack/cli/import.rb +0 -108
  217. data/lib/flapjack/data/entity.rb +0 -652
  218. data/lib/flapjack/data/entity_check.rb +0 -1044
  219. data/lib/flapjack/data/message.rb +0 -56
  220. data/lib/flapjack/data/migration.rb +0 -234
  221. data/lib/flapjack/data/notification_rule.rb +0 -425
  222. data/lib/flapjack/data/semaphore.rb +0 -44
  223. data/lib/flapjack/data/tagged.rb +0 -48
  224. data/lib/flapjack/gateways/jsonapi/check_methods.rb +0 -206
  225. data/lib/flapjack/gateways/jsonapi/check_presenter.rb +0 -221
  226. data/lib/flapjack/gateways/jsonapi/contact_methods.rb +0 -186
  227. data/lib/flapjack/gateways/jsonapi/entity_methods.rb +0 -223
  228. data/lib/flapjack/gateways/jsonapi/medium_methods.rb +0 -185
  229. data/lib/flapjack/gateways/jsonapi/metrics_methods.rb +0 -132
  230. data/lib/flapjack/gateways/jsonapi/notification_rule_methods.rb +0 -141
  231. data/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods.rb +0 -139
  232. data/lib/flapjack/gateways/jsonapi/report_methods.rb +0 -146
  233. data/lib/flapjack/gateways/pagerduty.rb +0 -318
  234. data/lib/flapjack/gateways/pagerduty/alert.text.erb +0 -10
  235. data/lib/flapjack/gateways/web/public/css/select2-bootstrap.css +0 -87
  236. data/lib/flapjack/gateways/web/public/css/select2.css +0 -615
  237. data/lib/flapjack/gateways/web/public/css/tablesort.css +0 -67
  238. data/lib/flapjack/gateways/web/public/img/select2-spinner.gif +0 -0
  239. data/lib/flapjack/gateways/web/public/img/select2.png +0 -0
  240. data/lib/flapjack/gateways/web/public/img/select2x2.png +0 -0
  241. data/lib/flapjack/gateways/web/public/js/backbone.js +0 -1581
  242. data/lib/flapjack/gateways/web/public/js/backbone.jsonapi.js +0 -322
  243. data/lib/flapjack/gateways/web/public/js/flapjack.js +0 -82
  244. data/lib/flapjack/gateways/web/public/js/jquery.tablesorter.js +0 -1640
  245. data/lib/flapjack/gateways/web/public/js/jquery.tablesorter.widgets.js +0 -1390
  246. data/lib/flapjack/gateways/web/public/js/modules/contact.js +0 -520
  247. data/lib/flapjack/gateways/web/public/js/modules/entity.js +0 -28
  248. data/lib/flapjack/gateways/web/public/js/modules/medium.js +0 -40
  249. data/lib/flapjack/gateways/web/public/js/select2.js +0 -3397
  250. data/lib/flapjack/gateways/web/public/js/tablesort.js +0 -44
  251. data/lib/flapjack/gateways/web/public/js/underscore.js +0 -1276
  252. data/lib/flapjack/gateways/web/views/edit_contacts.html.erb +0 -173
  253. data/lib/flapjack/gateways/web/views/entities.html.erb +0 -30
  254. data/lib/flapjack/gateways/web/views/entity.html.erb +0 -51
  255. data/lib/flapjack/rack_logger.rb +0 -47
  256. data/lib/flapjack/redis_pool.rb +0 -42
  257. data/spec/lib/flapjack/data/entity_check_spec.rb +0 -1418
  258. data/spec/lib/flapjack/data/entity_spec.rb +0 -872
  259. data/spec/lib/flapjack/data/message_spec.rb +0 -30
  260. data/spec/lib/flapjack/data/migration_spec.rb +0 -104
  261. data/spec/lib/flapjack/data/notification_rule_spec.rb +0 -232
  262. data/spec/lib/flapjack/data/notification_spec.rb +0 -53
  263. data/spec/lib/flapjack/data/semaphore_spec.rb +0 -24
  264. data/spec/lib/flapjack/filters/acknowledgement_spec.rb +0 -6
  265. data/spec/lib/flapjack/filters/delays_spec.rb +0 -6
  266. data/spec/lib/flapjack/filters/ok_spec.rb +0 -6
  267. data/spec/lib/flapjack/filters/scheduled_maintenance_spec.rb +0 -6
  268. data/spec/lib/flapjack/filters/unscheduled_maintenance_spec.rb +0 -6
  269. data/spec/lib/flapjack/gateways/jsonapi/check_methods_spec.rb +0 -315
  270. data/spec/lib/flapjack/gateways/jsonapi/check_presenter_spec.rb +0 -223
  271. data/spec/lib/flapjack/gateways/jsonapi/contact_methods_spec.rb +0 -131
  272. data/spec/lib/flapjack/gateways/jsonapi/entity_methods_spec.rb +0 -389
  273. data/spec/lib/flapjack/gateways/jsonapi/medium_methods_spec.rb +0 -231
  274. data/spec/lib/flapjack/gateways/jsonapi/notification_rule_methods_spec.rb +0 -169
  275. data/spec/lib/flapjack/gateways/jsonapi/pagerduty_credential_methods_spec.rb +0 -114
  276. data/spec/lib/flapjack/gateways/jsonapi/report_methods_spec.rb +0 -590
  277. data/spec/lib/flapjack/gateways/pagerduty_spec.rb +0 -249
  278. data/spec/lib/flapjack/gateways/web/views/check.html.erb_spec.rb +0 -21
  279. data/spec/lib/flapjack/gateways/web/views/contact.html.erb_spec.rb +0 -24
  280. data/spec/lib/flapjack/gateways/web/views/index.html.erb_spec.rb +0 -16
  281. data/spec/lib/flapjack/redis_pool_spec.rb +0 -29
  282. data/spec/service_consumers/pacts/flapjack-diner_v1.0.json +0 -4702
  283. data/tasks/entities.rake +0 -151
  284. data/tasks/profile.rake +0 -282
  285. data/tmp/acknowledge.rb +0 -13
  286. data/tmp/create_config_yaml.rb +0 -16
  287. data/tmp/create_event_ok.rb +0 -30
  288. data/tmp/create_event_unknown.rb +0 -30
  289. data/tmp/create_events_failure.rb +0 -34
  290. data/tmp/create_events_ok.rb +0 -32
  291. data/tmp/create_events_ok_fail_ack_ok.rb +0 -53
  292. data/tmp/create_events_ok_failure.rb +0 -41
  293. data/tmp/create_events_ok_failure_ack.rb +0 -53
  294. data/tmp/dummy_contacts.json +0 -43
  295. data/tmp/dummy_entities.json +0 -37
  296. data/tmp/generate_nagios_test_hosts.rb +0 -16
  297. data/tmp/notification_rules.rb +0 -73
  298. data/tmp/parse_config_yaml.rb +0 -7
  299. data/tmp/redis_find_spurious_unknown_states.rb +0 -52
  300. data/tmp/test_json_post.rb +0 -19
  301. 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">&times;</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">&times;</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>&nbsp;</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
- &nbsp;
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">&minus;</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) << "&amp;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 %>
@@ -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
@@ -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