Browse Source

Don't trigger "down" notifications when changing schedule interactively in web UI

pull/328/head
Pēteris Caune 5 years ago
parent
commit
5d9944873c
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 27 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +17
    -1
      hc/front/tests/test_update_timeout.py
  3. +9
    -0
      hc/front/views.py

+ 1
- 0
CHANGELOG.md View File

@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
### Bug Fixes ### Bug Fixes
- Increase the allowable length of Matrix room alias to 100 (#320) - Increase the allowable length of Matrix room alias to 100 (#320)
- Make sure Check.last_ping and Ping.created timestamps match exactly - Make sure Check.last_ping and Ping.created timestamps match exactly
- Don't trigger "down" notifications when changing schedule interactively in web UI
## v1.12.0 - 2020-01-02 ## v1.12.0 - 2020-01-02


+ 17
- 1
hc/front/tests/test_update_timeout.py View File

@ -31,7 +31,7 @@ class UpdateTimeoutTestCase(BaseTestCase):
expected_aa = self.check.last_ping + td(seconds=3600 + 60) expected_aa = self.check.last_ping + td(seconds=3600 + 60)
self.assertEqual(self.check.alert_after, expected_aa) self.assertEqual(self.check.alert_after, expected_aa)
def test_it_does_not_update_status(self):
def test_it_does_not_update_status_to_up(self):
self.check.last_ping = timezone.now() - td(days=2) self.check.last_ping = timezone.now() - td(days=2)
self.check.status = "down" self.check.status = "down"
self.check.save() self.check.save()
@ -45,6 +45,22 @@ class UpdateTimeoutTestCase(BaseTestCase):
self.check.refresh_from_db() self.check.refresh_from_db()
self.assertEqual(self.check.status, "down") self.assertEqual(self.check.status, "down")
def test_it_updates_status_to_down(self):
self.check.last_ping = timezone.now() - td(hours=1)
self.check.status = "up"
self.check.alert_after = self.check.going_down_after()
self.check.save()
# 1 + 1 minute:
payload = {"kind": "simple", "timeout": 60, "grace": 60}
self.client.login(username="[email protected]", password="password")
self.client.post(self.url, data=payload)
self.check.refresh_from_db()
self.assertEqual(self.check.status, "down")
self.assertIsNone(self.check.alert_after)
def test_it_saves_cron_expression(self): def test_it_saves_cron_expression(self):
payload = {"kind": "cron", "schedule": "5 * * * *", "tz": "UTC", "grace": 60} payload = {"kind": "cron", "schedule": "5 * * * *", "tz": "UTC", "grace": 60}


+ 9
- 0
hc/front/views.py View File

@ -377,6 +377,15 @@ def update_timeout(request, code):
check.grace = td(minutes=form.cleaned_data["grace"]) check.grace = td(minutes=form.cleaned_data["grace"])
check.alert_after = check.going_down_after() check.alert_after = check.going_down_after()
if check.status == "up" and check.alert_after < timezone.now():
# Checks can flip from "up" to "down" state as a result of changing check's
# schedule. We don't want to send notifications when changing schedule
# interactively in the web UI. So we update the `alert_after` and `status`
# fields here the same way as `sendalerts` would do, but without sending
# an actual alert:
check.alert_after = None
check.status = "down"
check.save() check.save()
if "/details/" in request.META.get("HTTP_REFERER", ""): if "/details/" in request.META.get("HTTP_REFERER", ""):


Loading…
Cancel
Save