aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorParker M <contact@pkrm.dev>2023-09-23 19:11:52 -0500
committerParker M <contact@pkrm.dev>2023-09-23 19:11:52 -0500
commitac8fb456373693d3574dcfc3f2f056fb2e0e1117 (patch)
tree374448fb3ea67525004dece6f57a37b0051770b6 /app
parentfdbb478c19aa22e8852334f56d278f41907a7183 (diff)
Add UptimeKuma Notifcations
Diffstat (limited to 'app')
-rw-r--r--app/initialize_variables.py17
-rw-r--r--app/messagearr.py33
2 files changed, 47 insertions, 3 deletions
diff --git a/app/initialize_variables.py b/app/initialize_variables.py
index 5450036..9dfda1a 100644
--- a/app/initialize_variables.py
+++ b/app/initialize_variables.py
@@ -4,9 +4,10 @@ import requests
supported_sms_services = ['telnyx', 'twilio']
-sms_service = str(os.environ['SMS_SERVICE']).lower()
radarr_host_url = str(os.environ['RADARR_HOST_URL'])
radarr_api_key = str(os.environ['RADARR_API_KEY'])
+enable_kuma_notifications = str(os.environ['ENABLE_KUMA_NOTIFICATIONS']).lower()
+sms_service = str(os.environ['SMS_SERVICE']).lower()
headers = {
'Content-Type': 'application/json',
@@ -26,6 +27,11 @@ try:
api_number = str(file['api_number'])
val_nums = str(file['valid_senders'])
root_folder_path = str(file['root_folder_path'])
+
+ if enable_kuma_notifications == 'true':
+ notif_receivers_nums = str(file['notif_receivers'])
+ authorization_header_token = str(file['authorization_header_token'])
+
if sms_service not in supported_sms_services:
print(f'{sms_service} is not a supported SMS service. Please choose from the supported list: {supported_sms_services}')
exit()
@@ -58,9 +64,14 @@ if value_not_set:
f.write("quality_profile_id:\n")
f.write("home_domain: null\n")
- f.write("api_number:\n")
- f.write("valid_senders:\n")
+ f.write("api_number: ''\n")
+ f.write("valid_senders: ''\n")
f.write("root_folder_path:\n")
+
+ if enable_kuma_notifications == 'true':
+ f.write("notif_receivers: ''\n")
+ f.write("authorization_header_token: uptimekumaauthtoken\n")
+
if sms_service not in supported_sms_services:
print(f'{sms_service} is not a supported SMS service. Please choose from the supported list: {supported_sms_services}')
exit()
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