diff --git a/hc/accounts/models.py b/hc/accounts/models.py
index 06c8d38f..cd7f5219 100644
--- a/hc/accounts/models.py
+++ b/hc/accounts/models.py
@@ -300,7 +300,7 @@ class Project(models.Model):
def overall_status(self):
status = "up"
for check in self.check_set.all():
- check_status = check.get_status(with_started=False)
+ check_status = check.get_status()
if status == "up" and check_status == "grace":
status = "grace"
diff --git a/hc/api/management/commands/sendalerts.py b/hc/api/management/commands/sendalerts.py
index be267600..62d09506 100644
--- a/hc/api/management/commands/sendalerts.py
+++ b/hc/api/management/commands/sendalerts.py
@@ -105,7 +105,7 @@ class Command(BaseCommand):
q = Check.objects.filter(id=check.id, status=old_status)
try:
- status = check.get_status(with_started=False)
+ status = check.get_status()
except Exception as e:
# Make sure we don't trip on this check again for an hour:
# Otherwise sendalerts may end up in a crash loop.
diff --git a/hc/api/models.py b/hc/api/models.py
index ba5aa13f..148d4d9e 100644
--- a/hc/api/models.py
+++ b/hc/api/models.py
@@ -160,7 +160,7 @@ class Check(models.Model):
if grace_start is not None:
return grace_start + self.grace
- def get_status(self, now=None, with_started=True):
+ def get_status(self, now=None, with_started=False):
""" Return current status for display. """
if now is None:
@@ -185,6 +185,9 @@ class Check(models.Model):
return "up"
+ def get_status_with_started(self):
+ return self.get_status(with_started=True)
+
def assign_all_channels(self):
channels = Channel.objects.filter(project=self.project)
self.channel_set.set(channels)
@@ -214,7 +217,7 @@ class Check(models.Model):
"desc": self.desc,
"grace": int(self.grace.total_seconds()),
"n_pings": self.n_pings,
- "status": self.get_status(),
+ "status": self.get_status(with_started=True),
"last_ping": isostring(self.last_ping),
"next_ping": isostring(self.get_grace_start()),
"manual_resume": self.manual_resume,
diff --git a/hc/api/tests/test_check_model.py b/hc/api/tests/test_check_model.py
index c279b9ff..45bbef03 100644
--- a/hc/api/tests/test_check_model.py
+++ b/hc/api/tests/test_check_model.py
@@ -29,12 +29,8 @@ class CheckModelTestCase(BaseTestCase):
def test_get_status_handles_paused_check(self):
check = Check()
-
- check.status = "up"
- check.last_ping = timezone.now() - timedelta(days=1, minutes=30)
- self.assertEqual(check.get_status(), "grace")
-
check.status = "paused"
+ check.last_ping = timezone.now() - timedelta(days=1, minutes=30)
self.assertEqual(check.get_status(), "paused")
def test_status_works_with_cron_syntax(self):
@@ -103,7 +99,7 @@ class CheckModelTestCase(BaseTestCase):
check.last_start = timezone.now() - timedelta(minutes=5)
for status in ("new", "paused", "up", "down"):
check.status = status
- self.assertEqual(check.get_status(), "started")
+ self.assertEqual(check.get_status(with_started=True), "started")
def test_get_status_handles_down_then_started_and_expired(self):
check = Check(status="down")
@@ -112,8 +108,8 @@ class CheckModelTestCase(BaseTestCase):
# Last start was 2 hours ago - the check is past its grace time
check.last_start = timezone.now() - timedelta(hours=2)
+ self.assertEqual(check.get_status(with_started=True), "down")
self.assertEqual(check.get_status(), "down")
- self.assertEqual(check.get_status(with_started=False), "down")
def test_get_status_handles_up_then_started(self):
check = Check(status="up")
@@ -122,9 +118,9 @@ class CheckModelTestCase(BaseTestCase):
# Last start was 5 minutes ago
check.last_start = timezone.now() - timedelta(minutes=5)
- self.assertEqual(check.get_status(), "started")
+ self.assertEqual(check.get_status(with_started=True), "started")
# Starting a check starts the grace period:
- self.assertEqual(check.get_status(with_started=False), "grace")
+ self.assertEqual(check.get_status(), "grace")
def test_get_status_handles_up_then_started_and_expired(self):
check = Check(status="up")
@@ -133,23 +129,23 @@ class CheckModelTestCase(BaseTestCase):
# Last start was 2 hours ago - the check is past its grace time
check.last_start = timezone.now() - timedelta(hours=2)
+ self.assertEqual(check.get_status(with_started=True), "down")
self.assertEqual(check.get_status(), "down")
- self.assertEqual(check.get_status(with_started=False), "down")
def test_get_status_handles_paused_then_started_and_expired(self):
check = Check(status="paused")
# Last start was 2 hours ago - the check is past its grace time
check.last_start = timezone.now() - timedelta(hours=2)
+ self.assertEqual(check.get_status(with_started=True), "down")
self.assertEqual(check.get_status(), "down")
- self.assertEqual(check.get_status(with_started=False), "down")
def test_get_status_handles_started_and_mia(self):
check = Check()
check.last_start = timezone.now() - timedelta(hours=2)
+ self.assertEqual(check.get_status(with_started=True), "down")
self.assertEqual(check.get_status(), "down")
- self.assertEqual(check.get_status(with_started=False), "down")
def test_next_ping_with_cron_syntax(self):
dt = timezone.make_aware(datetime(2000, 1, 1), timezone=timezone.utc)
diff --git a/hc/api/views.py b/hc/api/views.py
index 478f4fd2..ed7af4b9 100644
--- a/hc/api/views.py
+++ b/hc/api/views.py
@@ -359,7 +359,7 @@ def badge(request, badge_key, signature, tag, fmt="svg"):
continue
total += 1
- check_status = check.get_status(with_started=False)
+ check_status = check.get_status()
if check_status == "down":
down += 1
diff --git a/hc/front/templatetags/hc_extras.py b/hc/front/templatetags/hc_extras.py
index 23c767b7..b87fe895 100644
--- a/hc/front/templatetags/hc_extras.py
+++ b/hc/front/templatetags/hc_extras.py
@@ -87,7 +87,7 @@ def last_ping_key(check):
def not_down_key(check):
- return check.get_status() != "down"
+ return check.get_status(with_started=True) != "down"
@register.filter
@@ -126,7 +126,7 @@ def down_title(check):
"""
s = "%s – %s" % (check.name_then_code(), settings.SITE_NAME)
- if check.get_status() == "down":
+ if check.get_status(with_started=True) == "down":
s = "DOWN – " + s
return s
diff --git a/hc/front/views.py b/hc/front/views.py
index 4c367f8c..313d3d86 100644
--- a/hc/front/views.py
+++ b/hc/front/views.py
@@ -56,7 +56,7 @@ DOWNTIMES_TMPL = get_template("front/details_downtimes.html")
def _tags_statuses(checks):
tags, down, grace, num_down = {}, {}, {}, 0
for check in checks:
- status = check.get_status(with_started=False)
+ status = check.get_status()
if status == "down":
num_down += 1
@@ -207,7 +207,7 @@ def status(request, code):
details.append(
{
"code": str(check.code),
- "status": check.get_status(),
+ "status": check.get_status(with_started=True),
"last_ping": LAST_PING_TMPL.render(ctx),
}
)
@@ -594,7 +594,7 @@ def copy(request, code):
def status_single(request, code):
check = _get_check_for_user(request, code)
- status = check.get_status()
+ status = check.get_status(with_started=True)
events = _get_events(check, 20)
updated = "1"
if len(events):
@@ -1691,7 +1691,7 @@ def metrics(request, code, key):
TMPL = """hc_check_up{name="%s", tags="%s", unique_key="%s"} %d\n"""
for check in checks:
- value = 0 if check.get_status(with_started=False) == "down" else 1
+ value = 0 if check.get_status() == "down" else 1
yield TMPL % (esc(check.name), esc(check.tags), check.unique_key, value)
tags_statuses, num_down = _tags_statuses(checks)
diff --git a/templates/emails/summary-downtimes-html.html b/templates/emails/summary-downtimes-html.html
index bda9b3e6..d4be6b44 100644
--- a/templates/emails/summary-downtimes-html.html
+++ b/templates/emails/summary-downtimes-html.html
@@ -19,19 +19,21 @@
- {% if check.get_status == "new" %}
+ {% with check.get_status_with_started as status %}
+ {% if status == "new" %}
NEW |
- {% elif check.get_status == "paused" %}
+ {% elif status == "paused" %}
PAUSED |
- {% elif check.get_status == "grace" %}
+ {% elif status == "grace" %}
LATE |
- {% elif check.get_status == "up" %}
+ {% elif status == "up" %}
UP |
- {% elif check.get_status == "started" %}
+ {% elif status == "started" %}
STARTED |
- {% elif check.get_status == "down" %}
+ {% elif status == "down" %}
DOWN |
{% endif %}
+ {% endwith %}
|
diff --git a/templates/emails/summary-html.html b/templates/emails/summary-html.html
index 2172541d..331515ce 100644
--- a/templates/emails/summary-html.html
+++ b/templates/emails/summary-html.html
@@ -13,19 +13,21 @@
- {% if check.get_status == "new" %}
+ {% with check.get_status_with_started as status %}
+ {% if status == "new" %}
NEW |
- {% elif check.get_status == "paused" %}
+ {% elif status == "paused" %}
PAUSED |
- {% elif check.get_status == "grace" %}
+ {% elif status == "grace" %}
LATE |
- {% elif check.get_status == "up" %}
+ {% elif status == "up" %}
UP |
- {% elif check.get_status == "started" %}
+ {% elif status == "started" %}
STARTED |
- {% elif check.get_status == "down" %}
+ {% elif status == "down" %}
DOWN |
{% endif %}
+ {% endwith %}
|
diff --git a/templates/emails/summary-text.html b/templates/emails/summary-text.html
index 5c6e5d37..7cf7c5d5 100644
--- a/templates/emails/summary-text.html
+++ b/templates/emails/summary-text.html
@@ -1,5 +1,5 @@
{% load humanize hc_extras %}
Status | Name | Last Ping
--------+------------------------------------------+-----------------------{% for check in checks %}
- {{ check.get_status|ljust:"6" }} | {{ check.name|default:'unnamed'|ljust:"40" }} | {% if check.last_ping %}{{ check.last_ping|naturaltime }}{% else %}Never{% endif %}{% endfor %}
+ {{ check.get_status_with_started|ljust:"6" }} | {{ check.name|default:'unnamed'|ljust:"40" }} | {% if check.last_ping %}{{ check.last_ping|naturaltime }}{% else %}Never{% endif %}{% endfor %}
diff --git a/templates/front/details.html b/templates/front/details.html
index bc4d9c58..3c802dd3 100644
--- a/templates/front/details.html
+++ b/templates/front/details.html
@@ -111,7 +111,7 @@
-
+
|
{% include "front/log_status_text.html" %}
diff --git a/templates/front/log_status_text.html b/templates/front/log_status_text.html
index 27c612b4..c6e4389e 100644
--- a/templates/front/log_status_text.html
+++ b/templates/front/log_status_text.html
@@ -1,5 +1,5 @@
{% load humanize %}
-{% with check.get_status as status %}
+{% with check.get_status_with_started as status %}
{% if status == "down" %}
This check is down. Last ping was {{ check.last_ping|naturaltime }}.
{% elif status == "up" %}
diff --git a/templates/front/my_checks_desktop.html b/templates/front/my_checks_desktop.html
index aa2e662f..3099c7e4 100644
--- a/templates/front/my_checks_desktop.html
+++ b/templates/front/my_checks_desktop.html
@@ -60,7 +60,7 @@
{% if check in hidden_checks %}style="display: none"{% endif %}>
|
-
+
|
|