0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-10 23:40:11 +00:00

Update ntfy notification template to include failure reason

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

View file

@ -1,4 +1,3 @@
from __future__ import annotations
import json
@ -49,6 +48,7 @@ class NotifyNtfyTestCase(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:
@ -58,7 +58,10 @@ class NotifyNtfyTestCase(BaseTestCase):
assert Notification.objects.count() == 1
payload = mock_post.call_args.kwargs["json"]
self.assertEqual(payload["title"], "Foo is DOWN")
self.assertEqual(
payload["title"],
"Foo is DOWN (success signal did not arrive on time, grace time passed)",
)
self.assertIn("Project: Alices Project", payload["message"])
self.assertIn("Tags: foo, bar", payload["message"])
self.assertIn("Period: 1 day", payload["message"])
@ -68,6 +71,19 @@ class NotifyNtfyTestCase(BaseTestCase):
self.assertEqual(payload["actions"][0]["url"], self.check.cloaked_url())
self.assertNotIn("All the other checks are up.", 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)",
)
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_reports_last_pings_exit_code(self, mock_post: Mock) -> None:
mock_post.return_value.status_code = 200
@ -101,7 +117,7 @@ class NotifyNtfyTestCase(BaseTestCase):
self.channel.notify(self.flip)
payload = mock_post.call_args.kwargs["json"]
self.assertEqual(payload["title"], "<Name> is DOWN")
self.assertIn("<Name> is DOWN", payload["title"])
self.assertIn("Project: <Alice's Project>", payload["message"])
self.assertIn("Tags: <foo>", payload["message"])
self.assertIn("<Foobar>", payload["message"])

View file

@ -1603,6 +1603,7 @@ class Ntfy(HttpTransport):
def notify(self, flip: Flip, notification: Notification) -> None:
ctx = {
"flip": flip,
"check": flip.owner,
"status": flip.new_status,
"ping": self.last_ping(flip),

View file

@ -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 %}