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

Update PushBullet notification template to include failure reason

cc: 
This commit is contained in:
Pēteris Caune 2024-12-18 08:50:58 +02:00
parent 90ab7e0180
commit 46c51787bb
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
3 changed files with 20 additions and 12 deletions

View file

@ -1,4 +1,3 @@
from __future__ import annotations
from datetime import timedelta as td
@ -37,6 +36,7 @@ class NotifyPushbulletTestCase(BaseTestCase):
self.flip.created = now()
self.flip.old_status = "new"
self.flip.new_status = "up"
self.flip.reason = "timeout"
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_works(self, mock_post: Mock) -> None:
@ -50,8 +50,20 @@ class NotifyPushbulletTestCase(BaseTestCase):
self.assertEqual(kwargs["headers"]["Access-Token"], "fake-token")
payload = kwargs["json"]
self.assertEqual(payload["type"], "note")
self.assertIn("""The check "Foo" is DOWN.""", payload["body"])
self.assertIn("""Last ping was 10 minutes ago.""", payload["body"])
self.assertIn("""The check "Foo" is DOWN""", payload["body"])
self.assertIn("grace time passed", payload["body"])
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_handles_reason_fail(self, mock_post: Mock) -> None:
self.flip.new_status = "down"
self.flip.reason = "fail"
mock_post.return_value.status_code = 200
self.channel.notify(self.flip)
_, kwargs = mock_post.call_args
payload = kwargs["json"]
self.assertIn("received a failure signal", payload["body"])
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_handles_up(self, mock_post: Mock) -> None:
@ -62,9 +74,7 @@ class NotifyPushbulletTestCase(BaseTestCase):
_, kwargs = mock_post.call_args
self.assertEqual(kwargs["json"]["type"], "note")
self.assertEqual(
kwargs["json"]["body"], 'The check "Foo" received a ping and is now UP.'
)
self.assertEqual(kwargs["json"]["body"], 'The check "Foo" is UP.')
self.assertEqual(kwargs["headers"]["Access-Token"], "fake-token")
@patch("hc.api.transports.curl.request", autospec=True)
@ -78,7 +88,7 @@ class NotifyPushbulletTestCase(BaseTestCase):
_, kwargs = mock_post.call_args
self.assertEqual(
kwargs["json"]["body"],
'The check "Foo & Bar" received a ping and is now UP.',
'The check "Foo & Bar" is UP.',
)
@patch("hc.api.transports.curl.request", autospec=True)

View file

@ -665,9 +665,9 @@ class Pushbullet(HttpTransport):
}
text = tmpl(
"pushbullet_message.html",
flip=flip,
check=flip.owner,
status=flip.new_status,
ping=self.last_ping(flip),
)
payload = {"type": "note", "title": settings.SITE_NAME, "body": text}
self.post(url, json=payload, headers=headers)

View file

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