0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-07 22:25:35 +00:00

Update notification templates to handle "log" events

This commit is contained in:
Pēteris Caune 2022-07-21 14:22:41 +03:00
parent dc107ff7f5
commit 01720ca9ae
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
7 changed files with 51 additions and 0 deletions

View file

@ -235,3 +235,14 @@ class NotifyEmailTestCase(BaseTestCase):
html = email.alternatives[0][0]
self.assertIn("Ignored", email.body)
self.assertIn("Ignored", html)
def test_it_handles_last_ping_log(self):
self.ping.kind = "log"
self.ping.save()
self.channel.notify(self.check)
email = mail.outbox[0]
html = email.alternatives[0][0]
self.assertIn("Log", email.body)
self.assertIn("Log", html)

View file

@ -96,6 +96,20 @@ class NotifyMsTeamsTestCase(BaseTestCase):
facts = {f["name"]: f["value"] for f in payload["sections"][0]["facts"]}
self.assertEqual(facts["Last Ping:"], "Failure, an hour ago")
@patch("hc.api.transports.requests.request")
def test_it_handles_last_ping_log(self, mock_post):
mock_post.return_value.status_code = 200
self.ping.kind = "log"
self.ping.save()
self.channel.notify(self.check)
args, kwargs = mock_post.call_args
payload = kwargs["json"]
facts = {f["name"]: f["value"] for f in payload["sections"][0]["facts"]}
self.assertEqual(facts["Last Ping:"], "Log, an hour ago")
@patch("hc.api.transports.requests.request")
def test_it_shows_ignored_nonzero_exitstatus(self, mock_post):
mock_post.return_value.status_code = 200

View file

@ -142,6 +142,22 @@ class NotifySlackTestCase(BaseTestCase):
fields = {f["title"]: f["value"] for f in attachment["fields"]}
self.assertEqual(fields["Last Ping"], "Failure, an hour ago")
@override_settings(SITE_ROOT="http://testserver")
@patch("hc.api.transports.requests.request")
def test_it_handles_last_ping_log(self, mock_post):
self._setup_data("123")
mock_post.return_value.status_code = 200
self.ping.kind = "log"
self.ping.save()
self.channel.notify(self.check)
args, kwargs = mock_post.call_args
attachment = kwargs["json"]["attachments"][0]
fields = {f["title"]: f["value"] for f in attachment["fields"]}
self.assertEqual(fields["Last Ping"], "Log, an hour ago")
@override_settings(SITE_ROOT="http://testserver")
@patch("hc.api.transports.requests.request")
def test_it_shows_ignored_nonzero_exitstatus(self, mock_post):

View file

@ -86,6 +86,10 @@
<span style="background-color: #dff0d8; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
Started
</span>
{% elif ping.kind == "log" %}
<span style="background-color: #eeeeee; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
Log
</span>
{% else %}
<span style="background-color: #dff0d8; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
Success

View file

@ -46,6 +46,8 @@
{% line %}Last ping type: Failure{% endline %}
{% elif ping.kind == "start" %}
{% line %}Last ping type: Started{% endline %}
{% elif ping.kind == "log" %}
{% line %}Last ping type: Log{% endline %}
{% else %}
{% line %}Last ping type: Success{% endline %}
{% endif %}

View file

@ -33,6 +33,8 @@
"value": "Failure, {{ ping.created|naturaltime }}"
{% elif ping.kind == "start" %}
"value": "Start, {{ ping.created|naturaltime }}"
{% elif ping.kind == "log" %}
"value": "Log, {{ ping.created|naturaltime }}"
{% else %}
"value": "Success, {{ ping.created|naturaltime }}"
{% endif %}

View file

@ -55,6 +55,8 @@
"value": "Failure, {{ ping.created|naturaltime }}",
{% elif ping.kind == "start" %}
"value": "Start, {{ ping.created|naturaltime }}",
{% elif ping.kind == "log" %}
"value": "Log, {{ ping.created|naturaltime }}",
{% else %}
"value": "Success, {{ ping.created|naturaltime }}",
{% endif %}