mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-10 23:40:11 +00:00
Update Signal notification template to include failure reason
cc: #1069
This commit is contained in:
parent
3769bf3ede
commit
4808f35a4c
3 changed files with 20 additions and 5 deletions
|
@ -102,6 +102,7 @@ class NotifySignalTestCase(BaseTestCase):
|
||||||
self.flip.created = now()
|
self.flip.created = now()
|
||||||
self.flip.old_status = "new"
|
self.flip.old_status = "new"
|
||||||
self.flip.new_status = "down"
|
self.flip.new_status = "down"
|
||||||
|
self.flip.reason = "timeout"
|
||||||
|
|
||||||
def get_html(self, email: EmailMessage) -> str:
|
def get_html(self, email: EmailMessage) -> str:
|
||||||
assert isinstance(email, EmailMultiAlternatives)
|
assert isinstance(email, EmailMultiAlternatives)
|
||||||
|
@ -125,6 +126,7 @@ class NotifySignalTestCase(BaseTestCase):
|
||||||
params = socketobj.req["params"]
|
params = socketobj.req["params"]
|
||||||
self.assertIn("Daily Backup is DOWN", params["message"])
|
self.assertIn("Daily Backup is DOWN", params["message"])
|
||||||
self.assertEqual(params["textStyle"][0], "10:12:BOLD")
|
self.assertEqual(params["textStyle"][0], "10:12:BOLD")
|
||||||
|
self.assertIn("grace time passed", params["message"])
|
||||||
|
|
||||||
self.assertIn("Project: Alices Project", params["message"])
|
self.assertIn("Project: Alices Project", params["message"])
|
||||||
self.assertIn("Tags: foo, bar", params["message"])
|
self.assertIn("Tags: foo, bar", params["message"])
|
||||||
|
@ -137,6 +139,17 @@ class NotifySignalTestCase(BaseTestCase):
|
||||||
# other checks:
|
# other checks:
|
||||||
self.assertNotIn("All the other checks are up.", params["message"])
|
self.assertNotIn("All the other checks are up.", params["message"])
|
||||||
|
|
||||||
|
@patch("hc.api.transports.socket.socket")
|
||||||
|
def test_it_handles_reason_fail(self, socket: Mock) -> None:
|
||||||
|
socketobj = setup_mock(socket, {})
|
||||||
|
|
||||||
|
self.flip.reason = "fail"
|
||||||
|
self.channel.notify(self.flip)
|
||||||
|
|
||||||
|
assert socketobj.req
|
||||||
|
params = socketobj.req["params"]
|
||||||
|
self.assertIn("received a failure signal", params["message"])
|
||||||
|
|
||||||
@patch("hc.api.transports.socket.socket")
|
@patch("hc.api.transports.socket.socket")
|
||||||
def test_it_shows_exitstatus(self, socket: Mock) -> None:
|
def test_it_shows_exitstatus(self, socket: Mock) -> None:
|
||||||
socketobj = setup_mock(socket, {})
|
socketobj = setup_mock(socket, {})
|
||||||
|
@ -504,15 +517,16 @@ class NotifySignalTestCase(BaseTestCase):
|
||||||
email = emails["alice@example.org"]
|
email = emails["alice@example.org"]
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
email.subject,
|
email.subject,
|
||||||
"Signal notification failed: The check Foo & Co is DOWN.",
|
"Signal notification failed: The check Foo & Co is DOWN"
|
||||||
|
" (success signal did not arrive on time, grace time passed).",
|
||||||
)
|
)
|
||||||
# The plaintext version should have no HTML markup, and should
|
# The plaintext version should have no HTML markup, and should
|
||||||
# have no &, < > stuff:
|
# have no &, < > stuff:
|
||||||
self.assertIn("The check Foo & Co is DOWN.", email.body)
|
self.assertIn("The check Foo & Co is DOWN", email.body)
|
||||||
# The HTML version should retain styling, and escape special characters
|
# The HTML version should retain styling, and escape special characters
|
||||||
# in project name, check name, etc.:
|
# in project name, check name, etc.:
|
||||||
html = self.get_html(email)
|
html = self.get_html(email)
|
||||||
self.assertIn("The check <b>Foo & Co</b> is <b>DOWN</b>.", html)
|
self.assertIn("The check <b>Foo & Co</b> is <b>DOWN</b>", html)
|
||||||
|
|
||||||
@patch("hc.api.transports.socket.socket")
|
@patch("hc.api.transports.socket.socket")
|
||||||
def test_it_handles_null_data(self, socket: Mock) -> None:
|
def test_it_handles_null_data(self, socket: Mock) -> None:
|
||||||
|
|
|
@ -1507,7 +1507,7 @@ class Signal(Transport):
|
||||||
raise TransportError("signal-cli call timed out")
|
raise TransportError("signal-cli call timed out")
|
||||||
|
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
msg = "signal-cli call failed (%s)" % e
|
msg = f"signal-cli call failed ({e})"
|
||||||
# Log the exception, so any configured logging handlers can pick it up
|
# Log the exception, so any configured logging handlers can pick it up
|
||||||
logger.exception(msg)
|
logger.exception(msg)
|
||||||
|
|
||||||
|
@ -1524,6 +1524,7 @@ class Signal(Transport):
|
||||||
raise TransportError("Rate limit exceeded")
|
raise TransportError("Rate limit exceeded")
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
|
"flip": flip,
|
||||||
"check": flip.owner,
|
"check": flip.owner,
|
||||||
"status": flip.new_status,
|
"status": flip.new_status,
|
||||||
"ping": self.last_ping(flip),
|
"ping": self.last_ping(flip),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% load hc_extras humanize linemode %}{% linemode %}
|
{% load hc_extras humanize linemode %}{% linemode %}
|
||||||
{% if status == "down" %}
|
{% if status == "down" %}
|
||||||
{% line %}The check <b>{{ check.name_then_code }}</b> is <b>DOWN</b>.{% endline %}
|
{% line %}The check <b>{{ check.name_then_code }}</b> is <b>DOWN</b>{% if flip.reason %} ({{ flip.reason_long }}){% endif %}.{% endline %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% line %}The check <b>{{ check.name_then_code }}</b> is now <b>UP</b>.{% endline %}
|
{% line %}The check <b>{{ check.name_then_code }}</b> is now <b>UP</b>.{% endline %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue