diff options
author | Parker M <contact@pkrm.dev> | 2023-09-23 19:11:52 -0500 |
---|---|---|
committer | Parker M <contact@pkrm.dev> | 2023-09-23 19:11:52 -0500 |
commit | ac8fb456373693d3574dcfc3f2f056fb2e0e1117 (patch) | |
tree | 374448fb3ea67525004dece6f57a37b0051770b6 /app/messagearr.py | |
parent | fdbb478c19aa22e8852334f56d278f41907a7183 (diff) |
Add UptimeKuma Notifcations
Diffstat (limited to 'app/messagearr.py')
-rw-r--r-- | app/messagearr.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/messagearr.py b/app/messagearr.py index 3b7d7be..8bacd7c 100644 --- a/app/messagearr.py +++ b/app/messagearr.py @@ -39,6 +39,39 @@ valid_senders = [] for number in val_nums.split(', '): valid_senders.append(number) +if notif_receivers_nums: + notif_receivers = [] + + for number in notif_receivers_nums.split(', '): + notif_receivers.append(number) + + +""" +POST request route to accept incoming notifications from UptimeKuma +regarding the status of certain services. Messages are sent to the +'notif_receivers' list whenever a service goes down or comes back up. +""" +@app.route('/kuma', methods=['POST']) +def api(): + # Make sure the request is coming from UptimeKuma (Configured to use this authorization token) + if flask.request.headers.get('Authorization') == authorization_header_token: + data = flask.request.get_json() + + if data['heartbeat']['status'] == 0: + message = f"❌ {data['monitor']['name']} is down!" + + elif data['heartbeat']['status'] == 1: + message = f"✅ {data['monitor']['name']} is up!" + + for number in notif_receivers: + create_message(number, message) + + return 'OK' + # If the request does not contain the correct authorization token, return 401 + else: + return 'Unauthorized', 401 + + """ POST request route to accept incoming message from the SMS API, then process the incoming message in order to see if it is a valid command |