Resolves #18: Ensure all matching messages are removed, if enabled

This commit is contained in:
Scott Wallace 2020-10-29 21:45:45 +00:00
parent a6aad06dac
commit 3c9128c233
2 changed files with 7 additions and 9 deletions

View file

@ -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):
"""

View file

@ -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: