diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bb27a80..9aa5bb7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. ### Bug Fixes - Increase the allowable length of Matrix room alias to 100 (#320) - 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 diff --git a/hc/front/tests/test_update_timeout.py b/hc/front/tests/test_update_timeout.py index 0b82909a..2404251e 100644 --- a/hc/front/tests/test_update_timeout.py +++ b/hc/front/tests/test_update_timeout.py @@ -31,7 +31,7 @@ class UpdateTimeoutTestCase(BaseTestCase): expected_aa = self.check.last_ping + td(seconds=3600 + 60) 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.status = "down" self.check.save() @@ -45,6 +45,22 @@ class UpdateTimeoutTestCase(BaseTestCase): self.check.refresh_from_db() 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="alice@example.org", 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): payload = {"kind": "cron", "schedule": "5 * * * *", "tz": "UTC", "grace": 60} diff --git a/hc/front/views.py b/hc/front/views.py index ca7bc55c..926c4c01 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -377,6 +377,15 @@ def update_timeout(request, code): check.grace = td(minutes=form.cleaned_data["grace"]) 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() if "/details/" in request.META.get("HTTP_REFERER", ""):