forked from GithubBackups/healthchecks
Update Check.status field when user edits timeout & grace settings
This commit is contained in:
parent
11f65ff7aa
commit
925d34daad
@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
- Fix after-login redirects (the "?next=" query parameter)
|
- Fix after-login redirects (the "?next=" query parameter)
|
||||||
|
- Update Check.status field when user edits timeout & grace settings
|
||||||
|
|
||||||
|
|
||||||
## 1.3.0 - 2018-11-21
|
## 1.3.0 - 2018-11-21
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from datetime import timedelta as td
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from hc.api.models import Check
|
from hc.api.models import Check
|
||||||
from hc.test import BaseTestCase
|
from hc.test import BaseTestCase
|
||||||
@ -27,6 +29,22 @@ class UpdateTimeoutTestCase(BaseTestCase):
|
|||||||
# alert_after should be updated too
|
# alert_after should be updated too
|
||||||
self.assertEqual(self.check.alert_after, self.check.get_alert_after())
|
self.assertEqual(self.check.alert_after, self.check.get_alert_after())
|
||||||
|
|
||||||
|
def test_it_updates_status(self):
|
||||||
|
self.check.last_ping = timezone.now() - td(days=2)
|
||||||
|
self.check.status = "down"
|
||||||
|
self.check.save()
|
||||||
|
|
||||||
|
url = "/checks/%s/timeout/" % self.check.code
|
||||||
|
# 1 week:
|
||||||
|
payload = {"kind": "simple", "timeout": 3600 * 24 * 7, "grace": 60}
|
||||||
|
|
||||||
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
r = self.client.post(url, data=payload)
|
||||||
|
self.assertRedirects(r, "/checks/")
|
||||||
|
|
||||||
|
self.check.refresh_from_db()
|
||||||
|
self.assertEqual(self.check.status, "up")
|
||||||
|
|
||||||
def test_it_saves_cron_expression(self):
|
def test_it_saves_cron_expression(self):
|
||||||
url = "/checks/%s/timeout/" % self.check.code
|
url = "/checks/%s/timeout/" % self.check.code
|
||||||
payload = {
|
payload = {
|
||||||
|
@ -18,7 +18,7 @@ from django.utils.crypto import get_random_string
|
|||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
from hc.api.models import (DEFAULT_GRACE, DEFAULT_TIMEOUT, Channel, Check,
|
from hc.api.models import (DEFAULT_GRACE, DEFAULT_TIMEOUT, Channel, Check,
|
||||||
Ping, Notification)
|
Flip, Ping, Notification)
|
||||||
from hc.api.transports import Telegram
|
from hc.api.transports import Telegram
|
||||||
from hc.front.forms import (AddWebhookForm, NameTagsForm,
|
from hc.front.forms import (AddWebhookForm, NameTagsForm,
|
||||||
TimeoutForm, AddUrlForm, AddEmailForm,
|
TimeoutForm, AddUrlForm, AddEmailForm,
|
||||||
@ -300,6 +300,17 @@ def update_timeout(request, code):
|
|||||||
if check.last_ping:
|
if check.last_ping:
|
||||||
check.alert_after = check.get_alert_after()
|
check.alert_after = check.get_alert_after()
|
||||||
|
|
||||||
|
# Changing timeout can change check's status:
|
||||||
|
is_up = check.get_status() in ("up", "grace")
|
||||||
|
if is_up and check.status != "up":
|
||||||
|
flip = Flip(owner=check)
|
||||||
|
flip.created = timezone.now()
|
||||||
|
flip.old_status = check.status
|
||||||
|
flip.new_status = "up"
|
||||||
|
flip.save()
|
||||||
|
|
||||||
|
check.status = "up"
|
||||||
|
|
||||||
check.save()
|
check.save()
|
||||||
|
|
||||||
if "/details/" in request.META.get("HTTP_REFERER", ""):
|
if "/details/" in request.META.get("HTTP_REFERER", ""):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user