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

Update Zulip notification template to include failure reason

cc: 
This commit is contained in:
Pēteris Caune 2024-12-18 09:00:56 +02:00
parent bc5354b05b
commit fd0d58e96d
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
3 changed files with 15 additions and 5 deletions

View file

@ -1,4 +1,3 @@
from __future__ import annotations
import json
@ -39,6 +38,7 @@ class NotifyZulipTestCase(BaseTestCase):
self.flip.created = now()
self.flip.old_status = "new"
self.flip.new_status = "down"
self.flip.reason = "timeout"
def definition(self, **kwargs: str) -> dict[str, str]:
d = {
@ -62,13 +62,23 @@ class NotifyZulipTestCase(BaseTestCase):
payload = mock_post.call_args.kwargs["data"]
self.assertEqual(payload["topic"], "Foobar is DOWN")
self.assertIn("is **DOWN**.", payload["content"])
self.assertIn("Last ping was 10 minutes ago.", payload["content"])
self.assertIn("is **DOWN**", payload["content"])
self.assertIn("grace time passed", payload["content"])
# payload should not contain check's code
serialized = json.dumps(payload)
self.assertNotIn(str(self.check.code), serialized)
@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["data"]
self.assertIn("received a failure signal", payload["content"])
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_uses_custom_topic(self, mock_post: Mock) -> None:
self.channel.value = json.dumps(self.definition(topic="foo"))

View file

@ -1333,9 +1333,9 @@ class Zulip(HttpTransport):
auth = (self.channel.zulip.bot_email, self.channel.zulip.api_key)
content = tmpl(
"zulip_content.html",
flip=flip,
check=flip.owner,
status=flip.new_status,
ping=self.last_ping(flip),
)
data = {
"type": self.channel.zulip.mtype,

View file

@ -1,6 +1,6 @@
{% load hc_extras humanize %}
[{{ check.name_then_code }}]({{ check.cloaked_url }}) is **{{ status|upper }}**. {% if status == "down" and ping %}Last ping was {{ ping.created|naturaltime }}.{% endif %}
[{{ check.name_then_code }}]({{ check.cloaked_url }}) is **{{ status|upper }}**{% if flip.reason %} ({{ flip.reason_long }}){% endif %}.
{% if check.desc %}
---