Browse Source

Check.get_status() returns "up" also during grace period

pull/64/head
Pēteris Caune 9 years ago
parent
commit
ce23d65ebf
7 changed files with 21 additions and 12 deletions
  1. +1
    -1
      hc/api/models.py
  2. +11
    -1
      hc/api/tests/test_check_model.py
  3. +1
    -2
      hc/api/tests/test_sendalerts.py
  4. +2
    -2
      templates/emails/alert-body-html.html
  5. +2
    -2
      templates/emails/report-body-html.html
  6. +2
    -2
      templates/front/my_checks_desktop.html
  7. +2
    -2
      templates/front/my_checks_mobile.html

+ 1
- 1
hc/api/models.py View File

@ -85,7 +85,7 @@ class Check(models.Model):
now = timezone.now() now = timezone.now()
if self.last_ping + self.timeout > now:
if self.last_ping + self.timeout + self.grace > now:
return "up" return "up"
return "down" return "down"


+ 11
- 1
hc/api/tests/test_check_model.py View File

@ -1,5 +1,7 @@
from django.test import TestCase
from datetime import timedelta
from django.test import TestCase
from django.utils import timezone
from hc.api.models import Check from hc.api.models import Check
@ -17,3 +19,11 @@ class CheckModelTestCase(TestCase):
def test_in_grace_period_handles_new_check(self): def test_in_grace_period_handles_new_check(self):
check = Check() check = Check()
self.assertFalse(check.in_grace_period()) self.assertFalse(check.in_grace_period())
def test_status_works_with_grace_period(self):
check = Check()
check.status = "up"
check.last_ping = timezone.now() - timedelta(days=1, minutes=30)
self.assertTrue(check.in_grace_period())
self.assertEqual(check.get_status(), "up")

+ 1
- 2
hc/api/tests/test_sendalerts.py View File

@ -1,11 +1,10 @@
from datetime import timedelta from datetime import timedelta
from django.utils import timezone from django.utils import timezone
from mock import patch
from hc.api.management.commands.sendalerts import Command from hc.api.management.commands.sendalerts import Command
from hc.api.models import Check from hc.api.models import Check
from hc.test import BaseTestCase from hc.test import BaseTestCase
from mock import patch
class SendAlertsTestCase(BaseTestCase): class SendAlertsTestCase(BaseTestCase):


+ 2
- 2
templates/emails/alert-body-html.html View File

@ -49,10 +49,10 @@
<td> <td>
{% if check.get_status == "new" %} {% if check.get_status == "new" %}
<span class="badge new">NEW</span> <span class="badge new">NEW</span>
{% elif check.get_status == "up" %}
<span class="badge up">UP</span>
{% elif check.in_grace_period %} {% elif check.in_grace_period %}
<span class="badge grace">LATE</span> <span class="badge grace">LATE</span>
{% elif check.get_status == "up" %}
<span class="badge up">UP</span>
{% elif check.get_status == "down" %} {% elif check.get_status == "down" %}
<span class="badge down">DOWN</span> <span class="badge down">DOWN</span>
{% endif %} {% endif %}


+ 2
- 2
templates/emails/report-body-html.html View File

@ -46,10 +46,10 @@
<td> <td>
{% if check.get_status == "new" %} {% if check.get_status == "new" %}
<span class="badge new">NEW</span> <span class="badge new">NEW</span>
{% elif check.get_status == "up" %}
<span class="badge up">UP</span>
{% elif check.in_grace_period %} {% elif check.in_grace_period %}
<span class="badge grace">LATE</span> <span class="badge grace">LATE</span>
{% elif check.get_status == "up" %}
<span class="badge up">UP</span>
{% elif check.get_status == "down" %} {% elif check.get_status == "down" %}
<span class="badge down">DOWN</span> <span class="badge down">DOWN</span>
{% endif %} {% endif %}


+ 2
- 2
templates/front/my_checks_desktop.html View File

@ -16,10 +16,10 @@
<td class="indicator-cell"> <td class="indicator-cell">
{% if check.get_status == "new" %} {% if check.get_status == "new" %}
<span class="glyphicon glyphicon-question-sign new"></span> <span class="glyphicon glyphicon-question-sign new"></span>
{% elif check.get_status == "up" %}
<span class="glyphicon glyphicon-ok-sign up"></span>
{% elif check.in_grace_period %} {% elif check.in_grace_period %}
<span class="glyphicon glyphicon-exclamation-sign grace"></span> <span class="glyphicon glyphicon-exclamation-sign grace"></span>
{% elif check.get_status == "up" %}
<span class="glyphicon glyphicon-ok-sign up"></span>
{% elif check.get_status == "down" %} {% elif check.get_status == "down" %}
<span class="glyphicon glyphicon-exclamation-sign down"></span> <span class="glyphicon glyphicon-exclamation-sign down"></span>
{% endif %} {% endif %}


+ 2
- 2
templates/front/my_checks_mobile.html View File

@ -25,10 +25,10 @@
<td> <td>
{% if check.get_status == "new" %} {% if check.get_status == "new" %}
<span class="label label-default">NEW</span> <span class="label label-default">NEW</span>
{% elif check.get_status == "up" %}
<span class="label label-success">UP</span>
{% elif check.in_grace_period %} {% elif check.in_grace_period %}
<span class="label label-warning">LATE</span> <span class="label label-warning">LATE</span>
{% elif check.get_status == "up" %}
<span class="label label-success">UP</span>
{% elif check.get_status == "down" %} {% elif check.get_status == "down" %}
<span class="label label-danger">DOWN</span> <span class="label label-danger">DOWN</span>
{% endif %} {% endif %}


Loading…
Cancel
Save