Browse Source

Update notification templates to handle "log" events

pull/680/head
Pēteris Caune 2 years ago
parent
commit
01720ca9ae
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
  1. 11
      hc/api/tests/test_notify_email.py
  2. 14
      hc/api/tests/test_notify_msteams.py
  3. 16
      hc/api/tests/test_notify_slack.py
  4. 4
      templates/emails/alert-body-html.html
  5. 2
      templates/emails/alert-body-text.html
  6. 2
      templates/integrations/msteams_message.json
  7. 2
      templates/integrations/slack_message.json

11
hc/api/tests/test_notify_email.py

@ -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)

14
hc/api/tests/test_notify_msteams.py

@ -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

16
hc/api/tests/test_notify_slack.py

@ -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):

4
templates/emails/alert-body-html.html

@ -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

2
templates/emails/alert-body-text.html

@ -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 %}

2
templates/integrations/msteams_message.json

@ -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 %}

2
templates/integrations/slack_message.json

@ -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 %}

Loading…
Cancel
Save