From 3c9128c233a35eabfa0b158aff56a2fb0c12ef80 Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Thu, 29 Oct 2020 21:45:45 +0000 Subject: [PATCH] Resolves #18: Ensure all matching messages are removed, if enabled --- src/alertify/gotify.py | 9 ++++----- src/alertify/messaging.py | 7 +++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/alertify/gotify.py b/src/alertify/gotify.py index f298b35..2ae6e0a 100644 --- a/src/alertify/gotify.py +++ b/src/alertify/gotify.py @@ -77,20 +77,19 @@ class Gotify: logging.debug('No fingerprint found in new message') return None + msg_list = [] for old_message in self.messages(): try: old_fingerprint = old_message['extras']['alertify']['fingerprint'] if old_fingerprint == new_fingerprint: - return old_message['id'] + msg_list.append(old_message['id']) except KeyError: - logging.debug( + logging.warning( 'No fingerprint found in message ID: %s', old_message['id'], ) - continue - logging.debug('No fingerprint matched.') - return None + return msg_list def messages(self): """ diff --git a/src/alertify/messaging.py b/src/alertify/messaging.py index eb4778e..fb03764 100644 --- a/src/alertify/messaging.py +++ b/src/alertify/messaging.py @@ -28,10 +28,9 @@ class MessageHandler: } if self.delete_onresolve: - alert_id = self.gotify.find_byfingerprint(alert) - if alert_id: - return self.gotify.delete(alert_id) - logging.warning('Could not find a matching message to delete.') + for alert_id in self.gotify.find_byfingerprint(alert): + if not self.gotify.delete(alert_id): + logging.error('There was a problem removing message ID %d', alert_id) prefix = 'resolved' else: