forked from GithubBackups/healthchecks
Refactor: change Check.get_status(with_started=...) default value from True to False (with_started=False is or will be useful in more places)
This commit is contained in:
parent
eccc193b87
commit
a18eb134f5
@ -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"
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -19,19 +19,21 @@
|
||||
<td style="border-top: 1px solid #EDEFF2; padding: 16px 8px;">
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
{% if check.get_status == "new" %}
|
||||
{% with check.get_status_with_started as status %}
|
||||
{% if status == "new" %}
|
||||
<td style="background: #AAA; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; margin: 0; border-radius: 3px;">NEW</td>
|
||||
{% elif check.get_status == "paused" %}
|
||||
{% elif status == "paused" %}
|
||||
<td style="background: #AAA; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; border-radius: 3px;">PAUSED</td>
|
||||
{% elif check.get_status == "grace" %}
|
||||
{% elif status == "grace" %}
|
||||
<td style="background: #f0ad4e; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; border-radius: 3px;">LATE</td>
|
||||
{% elif check.get_status == "up" %}
|
||||
{% elif status == "up" %}
|
||||
<td style="background: #5cb85c; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; border-radius: 3px;">UP</td>
|
||||
{% elif check.get_status == "started" %}
|
||||
{% elif status == "started" %}
|
||||
<td style="background: #5cb85c; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; border-radius: 3px;">STARTED</td>
|
||||
{% elif check.get_status == "down" %}
|
||||
{% elif status == "down" %}
|
||||
<td style="background: #d9534f; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; border-radius: 3px;">DOWN</td>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
|
@ -13,19 +13,21 @@
|
||||
<td style="border-top: 1px solid #EDEFF2; padding: 16px 8px;">
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
{% if check.get_status == "new" %}
|
||||
{% with check.get_status_with_started as status %}
|
||||
{% if status == "new" %}
|
||||
<td style="background: #AAA; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; margin: 0; border-radius: 3px;">NEW</td>
|
||||
{% elif check.get_status == "paused" %}
|
||||
{% elif status == "paused" %}
|
||||
<td style="background: #AAA; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; border-radius: 3px;">PAUSED</td>
|
||||
{% elif check.get_status == "grace" %}
|
||||
{% elif status == "grace" %}
|
||||
<td style="background: #f0ad4e; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; border-radius: 3px;">LATE</td>
|
||||
{% elif check.get_status == "up" %}
|
||||
{% elif status == "up" %}
|
||||
<td style="background: #5cb85c; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; border-radius: 3px;">UP</td>
|
||||
{% elif check.get_status == "started" %}
|
||||
{% elif status == "started" %}
|
||||
<td style="background: #5cb85c; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; border-radius: 3px;">STARTED</td>
|
||||
{% elif check.get_status == "down" %}
|
||||
{% elif status == "down" %}
|
||||
<td style="background: #d9534f; font-family: Helvetica, Arial, sans-serif; font-weight: bold; font-size: 10px; line-height: 10px; color: white; padding: 6px; border-radius: 3px;">DOWN</td>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
|
@ -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 %}
|
||||
|
||||
|
@ -111,7 +111,7 @@
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<span id="log-status-icon" class="status icon-{{ check.get_status }}"></span>
|
||||
<span id="log-status-icon" class="status icon-{{ check.get_status_with_started }}"></span>
|
||||
</td>
|
||||
<td >
|
||||
<p id="log-status-text">{% include "front/log_status_text.html" %}</p>
|
||||
|
@ -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" %}
|
||||
|
@ -60,7 +60,7 @@
|
||||
{% if check in hidden_checks %}style="display: none"{% endif %}>
|
||||
|
||||
<td class="indicator-cell">
|
||||
<span class="status icon-{{ check.get_status }}" data-toggle="tooltip"></span>
|
||||
<span class="status icon-{{ check.get_status_with_started }}" data-toggle="tooltip"></span>
|
||||
</td>
|
||||
<td>
|
||||
<div data-name="{{ check.name }}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user