From 53599688a378def4be77d0f5ede828012246f67c Mon Sep 17 00:00:00 2001 From: JamesJJ Date: Sat, 15 Feb 2025 18:02:08 +0800 Subject: [PATCH] Fix repeated notifications when delayed (catch-up) notifications are enabled --- simplemonitor/Alerters/alerter.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/simplemonitor/Alerters/alerter.py b/simplemonitor/Alerters/alerter.py index 4bcf15aa..59b8dd26 100644 --- a/simplemonitor/Alerters/alerter.py +++ b/simplemonitor/Alerters/alerter.py @@ -283,20 +283,18 @@ def should_alert(self, monitor: Monitor) -> AlertType: if virtual_failure_count: self.alerter_logger.debug("monitor %s has failed", monitor.name) # Monitor has failed (not just first time) - if self._delay_notification: - # Delayed (catch-up) notifications are enabled - if not out_of_hours: - # Not out of hours - try: - self._ooh_failures.remove(monitor.name) - # if it was in there and we support catchup alerts, do it - if self.support_catchup: - self.alerter_logger.debug( - "alert for monitor %s is CATCHUP", monitor.name - ) - return AlertType.CATCHUP - except ValueError: - pass + if self._delay_notification and not out_of_hours: + # Delayed (catch-up) notifications are enabled, and it's time to send the delayed notification + if monitor.name in self._ooh_failures: + # The monitor had failed during ooh + self._ooh_failures.remove(monitor.name) + # if we support catchup alerts, do it + if self.support_catchup: + self.alerter_logger.debug( + "alert for monitor %s is CATCHUP", monitor.name + ) + return AlertType.CATCHUP + # send failure if catchup wasn't supported self.alerter_logger.debug( "alert for monitor %s is FAILURE", monitor.name )