diff --git a/hc/api/tests/test_notify_spike.py b/hc/api/tests/test_notify_spike.py index 240b2bc9..54107f60 100644 --- a/hc/api/tests/test_notify_spike.py +++ b/hc/api/tests/test_notify_spike.py @@ -1,4 +1,3 @@ - from __future__ import annotations from datetime import timedelta as td @@ -38,6 +37,7 @@ class NotifySpikeTestCase(BaseTestCase): self.flip.created = now() self.flip.old_status = "new" self.flip.new_status = "down" + self.flip.reason = "timeout" @patch("hc.api.transports.curl.request", autospec=True) def test_it_works(self, mock_post: Mock) -> None: @@ -48,10 +48,26 @@ class NotifySpikeTestCase(BaseTestCase): payload = mock_post.call_args.kwargs["json"] self.assertEqual(payload["check_id"], self.check.unique_key) - self.assertEqual(payload["title"], "Foo is DOWN") - self.assertIn("Foo is DOWN.", payload["message"]) + self.assertEqual( + payload["title"], + "Foo is DOWN (success signal did not arrive on time, grace time passed)", + ) + self.assertIn("Foo is DOWN", payload["message"]) + self.assertIn("grace time passed", payload["message"]) self.assertIn("Last ping was 10 minutes ago.", payload["message"]) + @patch("hc.api.transports.curl.request", autospec=True) + def test_it_handles_reason_fail(self, mock_post: Mock) -> None: + mock_post.return_value.status_code = 200 + + self.flip.reason = "fail" + self.channel.notify(self.flip) + + payload = mock_post.call_args.kwargs["json"] + self.assertEqual(payload["title"], "Foo is DOWN (received a failure signal)") + self.assertIn("Foo is DOWN", payload["message"]) + self.assertIn("received a failure signal", payload["message"]) + @override_settings(SPIKE_ENABLED=False) def test_it_requires_spike_enabled(self) -> None: self.channel.notify(self.flip) @@ -63,6 +79,7 @@ class NotifySpikeTestCase(BaseTestCase): self.check.name = "Foo & Bar" self.check.save() self.flip.new_status = "up" + self.flip.reason = "" mock_post.return_value.status_code = 200 diff --git a/hc/api/transports.py b/hc/api/transports.py index da05b874..f51b5e46 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -1356,6 +1356,7 @@ class Spike(HttpTransport): url = self.channel.value headers = {"Content-Type": "application/json"} ctx = { + "flip": flip, "check": flip.owner, "status": flip.new_status, "ping": self.last_ping(flip), @@ -1376,7 +1377,7 @@ class LineNotify(HttpTransport): def notify(self, flip: Flip, notification: Notification) -> None: headers = { "Content-Type": "application/x-www-form-urlencoded", - "Authorization": "Bearer %s" % self.channel.linenotify_token, + "Authorization": f"Bearer {self.channel.linenotify_token}", } ctx = { "check": flip.owner, diff --git a/templates/integrations/spike_description.html b/templates/integrations/spike_description.html index 93446ab6..4bfa9488 100644 --- a/templates/integrations/spike_description.html +++ b/templates/integrations/spike_description.html @@ -1,5 +1,5 @@ {% load humanize %} -{{ check.name_then_code|safe }} is {{ status|upper }}. +{{ check.name_then_code|safe }} is {{ status|upper }}{% if flip.reason %} ({{ flip.reason_long }}){% endif %}. {% if status == "down" and ping %} Last ping was {{ ping.created|naturaltime }}. -{% endif %} \ No newline at end of file +{% endif %} diff --git a/templates/integrations/spike_title.html b/templates/integrations/spike_title.html index af4c3b34..66058573 100644 --- a/templates/integrations/spike_title.html +++ b/templates/integrations/spike_title.html @@ -1 +1 @@ -{{ check.name_then_code|safe }} is {{ status|upper }} \ No newline at end of file +{{ check.name_then_code|safe }} is {{ status|upper }}{% if flip.reason %} ({{ flip.reason_long }}){% endif %}