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

Fix the display of ignored pings with non-zero exit status

This commit is contained in:
Pēteris Caune 2022-06-30 16:49:09 +03:00
parent ec0be60ca8
commit 0553f0a38a
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
12 changed files with 63 additions and 19 deletions

View file

@ -8,6 +8,9 @@ All notable changes to this project will be documented in this file.
- Implement the "Add Check" dialog
- Include last ping type in Slack, Mattermost, Discord notifications
### Bug Fixes
- Fix the display of ignored pings with non-zero exit status
## v2.2.1 - 2022-06-13
### Improvements

View file

@ -223,3 +223,15 @@ class NotifyEmailTestCase(BaseTestCase):
self.assertIn("The request body data is being processed", email.body)
self.assertIn("The request body data is being processed", html)
def test_it_shows_ignored_nonzero_exitstatus(self):
self.ping.kind = "ign"
self.ping.exitstatus = 123
self.ping.save()
self.channel.notify(self.check)
email = mail.outbox[0]
html = email.alternatives[0][0]
self.assertIn("Ignored", email.body)
self.assertIn("Ignored", html)

View file

@ -97,7 +97,7 @@ class NotifyMsTeamsTestCase(BaseTestCase):
self.assertEqual(facts["Last Ping:"], "Failure, an hour ago")
@patch("hc.api.transports.requests.request")
def test_it_handles_last_ping_ign_nonzero_exitstatus(self, mock_post):
def test_it_shows_ignored_nonzero_exitstatus(self, mock_post):
mock_post.return_value.status_code = 200
self.ping.kind = "ign"

View file

@ -144,7 +144,7 @@ class NotifySlackTestCase(BaseTestCase):
@override_settings(SITE_ROOT="http://testserver")
@patch("hc.api.transports.requests.request")
def test_it_handles_last_ping_ign_nonzero_exitstatus(self, mock_post):
def test_it_shows_ignored_nonzero_exitstatus(self, mock_post):
self._setup_data("123")
mock_post.return_value.status_code = 200

View file

@ -127,3 +127,12 @@ class LogTestCase(BaseTestCase):
self.client.login(username="bob@example.org", password="password")
r = self.client.get(self.url)
self.assertEqual(r.status_code, 200)
def test_it_shows_ignored_nonzero_exitstatus(self):
self.ping.kind = "ign"
self.ping.exitstatus = 123
self.ping.save()
self.client.login(username="alice@example.org", password="password")
r = self.client.get(self.url)
self.assertContains(r, "Ignored", status_code=200)

View file

@ -232,3 +232,10 @@ class PingDetailsTestCase(BaseTestCase):
self.client.login(username="alice@example.org", password="password")
r = self.client.get(self.url)
self.assertContains(r, "please check back later", status_code=200)
def test_it_shows_ignored_nonzero_exitstatus(self):
Ping.objects.create(owner=self.check, n=1, kind="ign", exitstatus=42)
self.client.login(username="alice@example.org", password="password")
r = self.client.get(self.url)
self.assertContains(r, "(ignored)", status_code=200)

View file

@ -81,3 +81,16 @@ class StatusSingleTestCase(BaseTestCase):
self.assertEqual(doc["status"], "paused")
self.assertIn("will ignore pings until resumed", doc["status_text"])
self.assertNotIn("resume-btn", doc["status_text"])
def test_it_shows_ignored_nonzero_exitstatus(self):
p = Ping(owner=self.check)
p.n = 1
p.kind = "ign"
p.exitstatus = 123
p.save()
self.client.login(username="alice@example.org", password="password")
r = self.client.get(self.url)
doc = r.json()
self.assertTrue("Ignored" in doc["events"])

View file

@ -66,7 +66,11 @@
</td>
<td style="padding-right: 32px; padding-bottom: 8px; vertical-align: top;">
<b>Last Ping Type</b><br>
{% if ping.exitstatus > 0 %}
{% if ping.kind == "ign" %}
<span style="background-color: #eeeeee; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
Ignored
</span>
{% elif ping.exitstatus > 0 %}
<span style="background-color: #f2dede; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
Exit status {{ ping.exitstatus }}
</span>
@ -82,10 +86,6 @@
<span style="background-color: #dff0d8; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
Started
</span>
{% elif ping.kind == "ign" %}
<span style="background-color: #eeeeee; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
Ignored
</span>
{% else %}
<span style="background-color: #dff0d8; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
Success

View file

@ -38,14 +38,14 @@
{% if ping %}
{% line %}Last ping: {{ ping.created|naturaltime }}{% if ping.remote_addr %}, from {{ ping.remote_addr }}{% endif %}{% endline %}
{% if ping.exitstatus >= 0 %}
{% if ping.kind == "ign" %}
{% line %}Last ping type: Ignored{% endline %}
{% elif ping.exitstatus >= 0 %}
{% line %}Last ping type: Exit status {{ ping.exitstatus }}{% endline %}
{% elif ping.kind == "fail" %}
{% line %}Last ping type: Failure{% endline %}
{% elif ping.kind == "start" %}
{% line %}Last ping type: Started{% endline %}
{% elif ping.kind == "ign" %}
{% line %}Last ping type: Ignored{% endline %}
{% else %}
{% line %}Last ping type: Success{% endline %}
{% endif %}

View file

@ -8,14 +8,14 @@
<td></td>
<td></td>
<td class="event">
{% if event.exitstatus > 0 %}
{% if event.kind == "ign" %}
<span class="label label-ign">Ignored</span>
{% elif event.exitstatus > 0 %}
<span class="label label-danger">Status {{ event.exitstatus }}</span>
{% elif event.kind == "fail" %}
<span class="label label-danger">Failure</span>
{% elif event.kind == "start" %}
<span class="label label-start">Started</span>
{% elif event.kind == "ign" %}
<span class="label label-ign">Ignored</span>
{% else %}
<span class="label label-success">OK</span>
{% endif %}

View file

@ -49,14 +49,14 @@
<td></td>
<td></td>
<td class="event">
{% if event.exitstatus %}
{% if event.kind == "ign" %}
<span class="label label-ign">Ignored</span>
{% elif event.exitstatus %}
<span class="label label-danger">Status {{ event.exitstatus }}</span>
{% elif event.kind == "fail" %}
<span class="label label-danger">Failure</span>
{% elif event.kind == "start" %}
<span class="label label-start">Started</span>
{% elif event.kind == "ign" %}
<span class="label label-ign">Ignored</span>
{% else %}
<span class="label label-success">OK</span>
{% endif %}

View file

@ -1,6 +1,8 @@
<div class="modal-body">
<h3>Ping #{{ ping.n }}
{% if ping.exitstatus > 0 %}
{% if ping.kind == "ign" %}
<span class="text-muted">(ignored)</span>
{% elif ping.exitstatus > 0 %}
<span class="text-danger">(failure, exit status {{ ping.exitstatus }})</span>
{% elif ping.exitstatus == 0 %}
<span class="text-success">(exit status 0)</span>
@ -8,8 +10,6 @@
<span class="text-danger">(received via the <code>/fail</code> endpoint)</span>
{% elif ping.kind == "start" %}
<span class="text-success">(received via the <code>/start</code> endpoint)</span>
{% elif ping.kind == "ign" %}
<span class="text-muted">(ignored)</span>
{% endif %}
</h3>