diff --git a/README.md b/README.md index 0039e68..da4443a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ ## Abstract AWS SNS/Lambda central alert hub taking SNS messages, parsing and formatting them before sending them to any messaging service, like Slack, Matrix, etc +## Tests +All env variables are forwarded into the test container. +Simply set WEBHOOK_URL accordingly before running `make test`. + ## Resources - https://gallery.ecr.aws/zero-downtime/sns-alert-hub - https://github.com/caronc/apprise diff --git a/app.py b/app.py index 3513184..9d27935 100644 --- a/app.py +++ b/app.py @@ -96,6 +96,10 @@ def handler(event, context): msg = {} pass + body = "" + title = "" + msg_type = apprise.NotifyType.INFO + # CloudWatch Alarm ? if "AlarmName" in msg: title = "AWS Cloudwatch Alarm" @@ -133,7 +137,6 @@ def handler(event, context): pass body = body + "\n\n_{}_".format(msg_context) - apobj.notify(body=body, title=title, notify_type=msg_type) elif "Source" in msg and msg["Source"] == "CloudBender": title = "AWS EC2 - CloudBender" @@ -175,7 +178,6 @@ def handler(event, context): body = body + "\n```{}```".format(msg["Attachment"]) body = body + "\n\n_{}_".format(msg_context) - apobj.notify(body=body, title=title, notify_type=msg_type) elif "receiver" in msg and msg["receiver"] == "alerthub-notifications": @@ -234,13 +236,14 @@ def handler(event, context): except KeyError: pass - # Finally send each parsed alert - apobj.notify(body=body, title=title, notify_type=msg_type) + # New simple ElasticCache notifications + elif "ElastiCache:SnapshotComplete" in msg: + title = "ElastiCache Snapshot complete." + body = "Taken on {}".format(msg["ElasticCache:SnapshotComplete"]) else: + title = "Unknown message type" + msg_type = apprise.NotifyType.WARNING body = sns["Message"] - apobj.notify( - body=body, - title="Unknown message type", - notify_type=apprise.NotifyType.WARNING, - ) + + apobj.notify(body=body, title=title, notify_type=msg_type)