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

Update Spike notification template to include failure reason

cc: 
This commit is contained in:
Pēteris Caune 2024-12-18 09:39:56 +02:00
parent 3fa80a8800
commit 22695bfdde
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
4 changed files with 25 additions and 7 deletions

View file

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

View file

@ -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,

View file

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

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