mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-04 21:05:26 +00:00
Update PagerTree notification template to include failure reason
cc: #1069
This commit is contained in:
parent
fd0d58e96d
commit
3fa80a8800
4 changed files with 30 additions and 6 deletions
hc/api
templates/integrations
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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 %}
|
||||
|
|
Loading…
Add table
Reference in a new issue