From 4f3365e235fec4b6ddf7731bb5a21a78089430b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 2 Aug 2016 09:48:17 +0300 Subject: [PATCH] Cleanup, handle "paused" state in email alerts and reports --- hc/api/models.py | 2 +- hc/api/tests/test_check_model.py | 10 ++++++++++ hc/front/views.py | 2 +- templates/emails/summary-html.html | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hc/api/models.py b/hc/api/models.py index 7cf7059f..a7888362 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -92,7 +92,7 @@ class Check(models.Model): return "down" def in_grace_period(self): - if not self.last_ping: + if self.status in ("new", "paused"): return False up_ends = self.last_ping + self.timeout diff --git a/hc/api/tests/test_check_model.py b/hc/api/tests/test_check_model.py index 73b7181f..0269e0cc 100644 --- a/hc/api/tests/test_check_model.py +++ b/hc/api/tests/test_check_model.py @@ -27,3 +27,13 @@ class CheckModelTestCase(TestCase): self.assertTrue(check.in_grace_period()) self.assertEqual(check.get_status(), "up") + + def test_paused_check_is_not_in_grace_period(self): + check = Check() + + check.status = "up" + check.last_ping = timezone.now() - timedelta(days=1, minutes=30) + self.assertTrue(check.in_grace_period()) + + check.status = "paused" + self.assertFalse(check.in_grace_period()) diff --git a/hc/front/views.py b/hc/front/views.py index 1d2500d4..555668d6 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -44,7 +44,7 @@ def my_checks(request): if status == "down": down_tags.add(tag) - elif check.in_grace_period() and status != "paused": + elif check.in_grace_period(): grace_tags.add(tag) ctx = { diff --git a/templates/emails/summary-html.html b/templates/emails/summary-html.html index 19c78783..9bccf6f8 100644 --- a/templates/emails/summary-html.html +++ b/templates/emails/summary-html.html @@ -57,6 +57,8 @@ {% if check.get_status == "new" %} NEW + {% elif check.get_status == "paused" %} + PAUSED {% elif check.in_grace_period %} LATE {% elif check.get_status == "up" %}