mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-03-15 20:54:53 +00:00
Update Telegram notification template to include failure reason
cc: #1069
This commit is contained in:
parent
28d1ce056e
commit
645efa5ce4
6 changed files with 15 additions and 5 deletions
hc/api
templates/integrations
|
@ -121,7 +121,6 @@ class NotifyEmailTestCase(BaseTestCase):
|
|||
@override_settings(DEFAULT_FROM_EMAIL="alerts@example.org")
|
||||
def test_it_handles_reason_failure(self) -> None:
|
||||
self.flip.reason = "fail"
|
||||
self.flip.save()
|
||||
self.channel.notify(self.flip)
|
||||
|
||||
email = mail.outbox[0]
|
||||
|
|
|
@ -68,7 +68,6 @@ class NotifyMatrixTestCase(BaseTestCase):
|
|||
mock_post.return_value.status_code = 200
|
||||
|
||||
self.flip.reason = "fail"
|
||||
self.flip.save()
|
||||
self.channel.notify(self.flip)
|
||||
assert Notification.objects.count() == 1
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
@ -40,6 +39,7 @@ class NotifyTelegramTestCase(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:
|
||||
|
@ -54,6 +54,7 @@ class NotifyTelegramTestCase(BaseTestCase):
|
|||
self.assertIn("The check", payload["text"])
|
||||
self.assertIn(">DB Backup</a>", payload["text"])
|
||||
self.assertIn(self.check.cloaked_url(), payload["text"])
|
||||
self.assertIn("grace time passed", payload["text"])
|
||||
|
||||
self.assertIn("<b>Project:</b> Alices Project\n", payload["text"])
|
||||
self.assertIn("<b>Tags:</b> foo, bar, baz\n", payload["text"])
|
||||
|
@ -65,6 +66,16 @@ class NotifyTelegramTestCase(BaseTestCase):
|
|||
# other checks:
|
||||
self.assertNotIn("All the other checks are up.", payload["text"])
|
||||
|
||||
@patch("hc.api.transports.curl.request", autospec=True)
|
||||
def test_it_handles_reason_failure(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.assertIn("received a failure signal", payload["text"])
|
||||
|
||||
@patch("hc.api.transports.curl.request", autospec=True)
|
||||
def test_it_shows_exitstatus(self, mock_post: Mock) -> None:
|
||||
mock_post.return_value.status_code = 200
|
||||
|
|
|
@ -927,6 +927,7 @@ class Telegram(HttpTransport):
|
|||
|
||||
ping = self.last_ping(flip)
|
||||
ctx = {
|
||||
"flip": flip,
|
||||
"check": flip.owner,
|
||||
"status": flip.new_status,
|
||||
"down_checks": self.down_checks(flip.owner),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% load humanize hc_extras %}
|
||||
{% if flip.new_status == "down" %}
|
||||
{% if status == "down" %}
|
||||
🔴 The check <a href="{{ check.cloaked_url }}">{{ check.name_then_code }}</a>
|
||||
is <b>DOWN</b>{% if flip.reason %} ({{ flip.reason_long }}){% endif %}.
|
||||
{% else %}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% load hc_extras humanize linemode %}{% linemode %}
|
||||
{% if status == "down" %}
|
||||
{% line %}🔴 The check <a href="{{ check.cloaked_url }}">{{ check.name_then_code }}</a> is <b>DOWN</b>.{% endline %}
|
||||
{% line %}🔴 The check <a href="{{ check.cloaked_url }}">{{ check.name_then_code }}</a> is <b>DOWN</b>{% if flip.reason %} ({{ flip.reason_long }}){% endif %}.{% endline %}
|
||||
{% else %}
|
||||
{% line %}🟢 The check <a href="{{ check.cloaked_url }}">{{ check.name_then_code }}</a> is now <b>UP</b>.{% endline %}
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in a new issue