0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-05 05:15:26 +00:00

Update PagerDuty notification template to include failure reason

cc: 
This commit is contained in:
Pēteris Caune 2024-12-17 08:46:35 +02:00
parent cd70e88c52
commit 4628deb395
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
3 changed files with 22 additions and 5 deletions
hc/api
templates/integrations

View file

@ -1,4 +1,3 @@
from __future__ import annotations
import json
@ -41,6 +40,7 @@ class NotifyPdTestCase(BaseTestCase):
self.flip.created = now()
self.flip.old_status = "new"
self.flip.new_status = status
self.flip.reason = "timeout"
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_works(self, mock_post: Mock) -> None:
@ -51,7 +51,10 @@ class NotifyPdTestCase(BaseTestCase):
assert Notification.objects.count() == 1
payload = mock_post.call_args.kwargs["json"]
self.assertEqual(payload["description"], "Foo is DOWN")
self.assertEqual(
payload["description"],
"Foo is DOWN (success signal did not arrive on time, grace time passed).",
)
self.assertEqual(payload["details"]["Description"], "Description goes here")
self.assertEqual(payload["event_type"], "trigger")
self.assertEqual(payload["service_key"], "123")
@ -59,6 +62,19 @@ class NotifyPdTestCase(BaseTestCase):
self.assertEqual(payload["details"]["Total pings"], 112233)
self.assertEqual(payload["incident_key"], self.check.unique_key)
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_handles_reason_fail(self, mock_post: Mock) -> None:
self._setup_data("123")
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["description"], "Foo is DOWN (received a failure signal)."
)
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_shows_cron_schedule_and_tz(self, mock_post: Mock) -> None:
self._setup_data("123")
@ -117,7 +133,7 @@ class NotifyPdTestCase(BaseTestCase):
self.channel.notify(self.flip)
payload = mock_post.call_args.kwargs["json"]
self.assertEqual(payload["description"], "Foo & Bar is DOWN")
self.assertIn("Foo & Bar is DOWN", payload["description"])
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_handles_no_last_ping(self, mock_post: Mock) -> None:

View file

@ -616,7 +616,8 @@ class PagerDuty(HttpTransport):
details["Schedule"] = check.schedule
details["Time zone"] = check.tz
description = tmpl("pd_description.html", check=check, status=flip.new_status)
ctx = {"flip": flip, "check": check, "status": flip.new_status}
description = tmpl("pd_description.html", **ctx)
payload = {
"service_key": self.channel.pd.service_key,
"incident_key": check.unique_key,

View file

@ -1,5 +1,5 @@
{% if status == "down" %}
{{ check.name_then_code|safe }} is DOWN
{{ check.name_then_code|safe }} is DOWN{% if flip.reason %} ({{ flip.reason_long }}){% endif %}.
{% else %}
{{ check.name_then_code|safe }} received a ping and is now UP
{% endif %}