Generic alert send

This commit is contained in:
Einar Forselv 2019-12-04 20:55:01 +01:00
parent 850df45a69
commit d9a082d044
1 changed files with 18 additions and 1 deletions

View File

@ -12,7 +12,24 @@ ALERT_TYPES = [ALERT_INFO, ALERT_ERROR]
BACKENDS = [SMTPAlert, DiscordWebhookAlert] BACKENDS = [SMTPAlert, DiscordWebhookAlert]
def configured_alert_classes(): def send(subject: str = None, body: str = None, alert_type: str = 'INFO'):
"""Send alert to all configured backends"""
alert_classes = configured_alert_types()
for instance in alert_classes:
logger.info('Configured: %s', instance.name)
try:
instance.send(
subject=f'[{alert_type}] {subject}',
body=body,
)
except Exception as ex:
logger.error("Exception raised when sending alert [%s]: %s", instance.name, ex)
if len(alert_classes) == 0:
logger.info("No alerts configured")
def configured_alert_types():
"""Returns a list of configured alert class instances""" """Returns a list of configured alert class instances"""
logger.debug('Getting alert backends') logger.debug('Getting alert backends')
entires = [] entires = []