Browse Source

Update Check.status field when user edits timeout & grace settings

pull/211/head
Pēteris Caune 6 years ago
parent
commit
925d34daad
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 31 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +18
    -0
      hc/front/tests/test_update_timeout.py
  3. +12
    -1
      hc/front/views.py

+ 1
- 0
CHANGELOG.md View File

@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
### Bug Fixes
- Fix after-login redirects (the "?next=" query parameter)
- Update Check.status field when user edits timeout & grace settings
## 1.3.0 - 2018-11-21


+ 18
- 0
hc/front/tests/test_update_timeout.py View File

@ -1,3 +1,5 @@
from datetime import timedelta as td
from django.utils import timezone
from hc.api.models import Check
from hc.test import BaseTestCase
@ -27,6 +29,22 @@ class UpdateTimeoutTestCase(BaseTestCase):
# alert_after should be updated too
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="[email protected]", 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):
url = "/checks/%s/timeout/" % self.check.code
payload = {


+ 12
- 1
hc/front/views.py View File

@ -18,7 +18,7 @@ from django.utils.crypto import get_random_string
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from hc.api.models import (DEFAULT_GRACE, DEFAULT_TIMEOUT, Channel, Check,
Ping, Notification)
Flip, Ping, Notification)
from hc.api.transports import Telegram
from hc.front.forms import (AddWebhookForm, NameTagsForm,
TimeoutForm, AddUrlForm, AddEmailForm,
@ -300,6 +300,17 @@ def update_timeout(request, code):
if check.last_ping:
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()
if "/details/" in request.META.get("HTTP_REFERER", ""):


Loading…
Cancel
Save