diff --git a/hc/api/tests/test_notify_pagertree.py b/hc/api/tests/test_notify_pagertree.py index f3dadcb0..84f5eafc 100644 --- a/hc/api/tests/test_notify_pagertree.py +++ b/hc/api/tests/test_notify_pagertree.py @@ -1,4 +1,3 @@ - from __future__ import annotations from datetime import timedelta as td @@ -38,6 +37,7 @@ class NotifyPagertreeTestCase(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: @@ -49,7 +49,30 @@ class NotifyPagertreeTestCase(BaseTestCase): payload = mock_post.call_args.kwargs["json"] self.assertEqual(payload["event_type"], "trigger") self.assertEqual(payload["incident_key"], self.check.unique_key) - self.assertIn("Foo is DOWN.", payload["description"]) + self.assertEqual( + "Foo is DOWN (success signal did not arrive on time, grace time passed)", + payload["title"], + ) + + self.assertIn( + "Foo is DOWN (success signal did not arrive on time, grace time passed).", + payload["description"], + ) + self.assertIn("Last ping was 10 minutes ago.", payload["description"]) + + @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("Foo is DOWN (received a failure signal)", payload["title"]) + + self.assertIn( + "Foo is DOWN (received a failure signal).", payload["description"] + ) self.assertIn("Last ping was 10 minutes ago.", payload["description"]) @override_settings(PAGERTREE_ENABLED=False) @@ -69,7 +92,7 @@ class NotifyPagertreeTestCase(BaseTestCase): self.channel.notify(self.flip) payload = mock_post.call_args.kwargs["json"] - self.assertEqual(payload["title"], "Foo & Bar is DOWN") + self.assertIn("Foo & Bar is DOWN", payload["title"]) @patch("hc.api.transports.curl.request", autospec=True) def test_it_handles_no_last_ping(self, mock_post: Mock) -> None: diff --git a/hc/api/transports.py b/hc/api/transports.py index 442886e0..da05b874 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -639,6 +639,7 @@ class PagerTree(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), @@ -650,7 +651,7 @@ class PagerTree(HttpTransport): "description": tmpl("pagertree_description.html", **ctx), "client": settings.SITE_NAME, "client_url": settings.SITE_ROOT, - "tags": ",".join(flip.owner.tags_list()), + "tags": " ".join(flip.owner.tags_list()), } self.post(url, json=payload, headers=headers) diff --git a/templates/integrations/pagertree_description.html b/templates/integrations/pagertree_description.html index fc95821e..faa19f51 100644 --- a/templates/integrations/pagertree_description.html +++ b/templates/integrations/pagertree_description.html @@ -1,5 +1,5 @@ {% load humanize %} -{{ check.name_then_code }} is {{ status|upper }}. +{{ check.name_then_code }} is {{ status|upper }}{% if flip.reason %} ({{ flip.reason_long }}){% endif %}. {% if status == "down" and ping %} Last ping was {{ ping.created|naturaltime }}. {% endif %} diff --git a/templates/integrations/pagertree_title.html b/templates/integrations/pagertree_title.html index 002e0f4b..66058573 100644 --- a/templates/integrations/pagertree_title.html +++ b/templates/integrations/pagertree_title.html @@ -1 +1 @@ -{{ check.name_then_code|safe }} is {{ status|upper }} +{{ check.name_then_code|safe }} is {{ status|upper }}{% if flip.reason %} ({{ flip.reason_long }}){% endif %}