2022-07-02 16:00:54 +02:00
|
|
|
import glob
|
|
|
|
import re
|
|
|
|
|
2022-07-10 18:07:11 +02:00
|
|
|
from bs4 import BeautifulSoup
|
2022-07-02 16:00:54 +02:00
|
|
|
|
2023-08-29 18:37:27 +02:00
|
|
|
from utils import deduplicate_list, write_to_file, type_html_to_py
|
2022-07-02 16:00:54 +02:00
|
|
|
|
|
|
|
|
2023-05-20 13:10:12 +02:00
|
|
|
# deprecated or wrong inputs
|
|
|
|
ignored_inputs = {
|
|
|
|
"slack": [
|
|
|
|
"slackbutton"
|
|
|
|
],
|
|
|
|
"rocket.chat": [
|
|
|
|
"rocketbutton"
|
|
|
|
],
|
|
|
|
"octopush": [
|
|
|
|
"octopushDMLogin",
|
|
|
|
"octopushDMAPIKey",
|
|
|
|
"octopushDMPhoneNumber",
|
|
|
|
"octopushDMSenderName",
|
|
|
|
"octopushDMSMSType"
|
|
|
|
],
|
|
|
|
"Splunk": [
|
|
|
|
"pagerdutyIntegrationKey"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2023-08-29 18:37:27 +02:00
|
|
|
input_overwrites = {
|
|
|
|
"showAdditionalHeadersField": "webhookAdditionalHeaders"
|
|
|
|
}
|
|
|
|
|
2023-05-20 13:10:12 +02:00
|
|
|
titles = {
|
|
|
|
"alerta": "Alerta",
|
|
|
|
"AlertNow": "AlertNow",
|
|
|
|
"apprise": "Apprise (Support 50+ Notification services)",
|
|
|
|
"Bark": "Bark",
|
|
|
|
"clicksendsms": "ClickSend SMS",
|
|
|
|
"discord": "Discord",
|
|
|
|
"GoogleChat": "Google Chat (Google Workspace)",
|
|
|
|
"gorush": "Gorush",
|
|
|
|
"gotify": "Gotify",
|
|
|
|
"HomeAssistant": "Home Assistant",
|
|
|
|
"Kook": "Kook",
|
|
|
|
"line": "LINE Messenger",
|
|
|
|
"LineNotify": "LINE Notify",
|
|
|
|
"lunasea": "LunaSea",
|
|
|
|
"matrix": "Matrix",
|
|
|
|
"mattermost": "Mattermost",
|
|
|
|
"ntfy": "Ntfy",
|
|
|
|
"octopush": "Octopush",
|
|
|
|
"OneBot": "OneBot",
|
|
|
|
"Opsgenie": "Opsgenie",
|
|
|
|
"PagerDuty": "PagerDuty",
|
2023-08-29 18:37:27 +02:00
|
|
|
"PagerTree": "PagerTree",
|
2023-05-20 13:10:12 +02:00
|
|
|
"pushbullet": "Pushbullet",
|
|
|
|
"PushByTechulus": "Push by Techulus",
|
|
|
|
"pushover": "Pushover",
|
|
|
|
"pushy": "Pushy",
|
|
|
|
"rocket.chat": "Rocket.Chat",
|
|
|
|
"signal": "Signal",
|
|
|
|
"slack": "Slack",
|
|
|
|
"squadcast": "SquadCast",
|
|
|
|
"SMSEagle": "SMSEagle",
|
|
|
|
"smtp": "Email (SMTP)",
|
|
|
|
"stackfield": "Stackfield",
|
|
|
|
"teams": "Microsoft Teams",
|
|
|
|
"telegram": "Telegram",
|
|
|
|
"twilio": "Twilio",
|
|
|
|
"Splunk": "Splunk",
|
|
|
|
"webhook": "Webhook",
|
|
|
|
"GoAlert": "GoAlert",
|
|
|
|
"ZohoCliq": "ZohoCliq",
|
|
|
|
"AliyunSMS": "AliyunSMS",
|
|
|
|
"DingDing": "DingDing",
|
|
|
|
"Feishu": "Feishu",
|
|
|
|
"FreeMobile": "FreeMobile (mobile.free.fr)",
|
|
|
|
"PushDeer": "PushDeer",
|
|
|
|
"promosms": "PromoSMS",
|
|
|
|
"serwersms": "SerwerSMS.pl",
|
|
|
|
"SMSManager": "SmsManager (smsmanager.cz)",
|
|
|
|
"WeCom": "WeCom",
|
|
|
|
"ServerChan": "ServerChan",
|
2023-08-29 18:37:27 +02:00
|
|
|
"nostr": "Nostr",
|
|
|
|
"FlashDuty": "FlashDuty",
|
|
|
|
"smsc": "SMSC",
|
2023-05-20 13:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-29 18:37:27 +02:00
|
|
|
def build_notification_providers():
|
|
|
|
root = "uptime-kuma"
|
2023-05-20 13:10:12 +02:00
|
|
|
providers = {}
|
|
|
|
|
|
|
|
# get providers and input names
|
|
|
|
for path in sorted(glob.glob(f'{root}/server/notification-providers/*')):
|
2022-07-10 18:07:11 +02:00
|
|
|
with open(path) as f:
|
|
|
|
content = f.read()
|
|
|
|
match = re.search(r'class [^ ]+ extends NotificationProvider {', content)
|
|
|
|
if match:
|
|
|
|
match = re.search(r'name = "([^"]+)";', content)
|
|
|
|
name = match.group(1)
|
2022-07-02 16:00:54 +02:00
|
|
|
|
2023-05-20 13:10:12 +02:00
|
|
|
inputs = re.findall(r'notification\??\.([^ ,.;})\]]+)', content)
|
2022-07-10 18:07:11 +02:00
|
|
|
inputs = deduplicate_list(inputs)
|
|
|
|
inputs = [i.strip() for i in inputs]
|
2022-07-02 16:00:54 +02:00
|
|
|
|
2023-05-20 13:10:12 +02:00
|
|
|
providers[name] = {
|
2023-08-29 18:37:27 +02:00
|
|
|
"title": titles[name],
|
2023-05-20 13:10:12 +02:00
|
|
|
"inputs": {},
|
|
|
|
}
|
|
|
|
for input_ in inputs:
|
|
|
|
if input_ not in ignored_inputs.get(name, []):
|
|
|
|
providers[name]["inputs"][input_] = {}
|
2022-07-02 16:00:54 +02:00
|
|
|
|
2023-05-20 13:10:12 +02:00
|
|
|
# get inputs
|
2022-12-29 00:22:53 +01:00
|
|
|
for path in glob.glob(f'{root}/src/components/notifications/*'):
|
2022-07-10 18:07:11 +02:00
|
|
|
if path.endswith("index.js"):
|
|
|
|
continue
|
|
|
|
with open(path) as f:
|
|
|
|
content = f.read()
|
|
|
|
match = re.search(r'<template>[\s\S]+</template>', content, re.MULTILINE)
|
|
|
|
html = match.group(0)
|
|
|
|
soup = BeautifulSoup(html, "html.parser")
|
2023-05-20 13:10:12 +02:00
|
|
|
inputs = soup.find_all(attrs={"v-model": True})
|
|
|
|
for input_ in inputs:
|
|
|
|
conditions = {}
|
|
|
|
attrs = input_.attrs
|
2022-07-10 18:07:11 +02:00
|
|
|
v_model = attrs.get("v-model")
|
2023-05-20 13:10:12 +02:00
|
|
|
|
2023-08-29 18:37:27 +02:00
|
|
|
v_model_overwrite = input_overwrites.get(v_model)
|
|
|
|
if v_model_overwrite:
|
|
|
|
param_name = v_model_overwrite
|
2023-05-20 13:10:12 +02:00
|
|
|
else:
|
2023-08-29 18:37:27 +02:00
|
|
|
param_name = re.match(r'\$parent.notification.(.*)$', v_model).group(1)
|
|
|
|
|
|
|
|
type_ = attrs.get("type")
|
|
|
|
type_ = type_html_to_py(type_)
|
2023-05-20 13:10:12 +02:00
|
|
|
|
|
|
|
required_true_values = ['', 'true']
|
|
|
|
if attrs.get("required") in required_true_values or attrs.get(":required") in required_true_values:
|
|
|
|
required = True
|
|
|
|
else:
|
|
|
|
required = False
|
|
|
|
|
2022-07-10 18:07:11 +02:00
|
|
|
min_ = attrs.get("min")
|
|
|
|
if min_:
|
2023-05-20 13:10:12 +02:00
|
|
|
conditions["min"] = int(min_)
|
|
|
|
|
|
|
|
max_ = attrs.get("max")
|
2022-07-10 18:07:11 +02:00
|
|
|
if max_:
|
2023-05-20 13:10:12 +02:00
|
|
|
conditions["max"] = int(max_)
|
|
|
|
|
|
|
|
# find provider inputs dict
|
|
|
|
input_found = False
|
|
|
|
for name in list(providers.keys()):
|
|
|
|
inputs = providers[name]["inputs"]
|
|
|
|
for provider_input in inputs:
|
|
|
|
if provider_input == param_name:
|
|
|
|
input_found = True
|
|
|
|
providers[name]["inputs"][provider_input] = {
|
|
|
|
"conditions": conditions,
|
|
|
|
"type": type_,
|
|
|
|
"required": required
|
|
|
|
}
|
|
|
|
assert input_found
|
|
|
|
return providers
|
2022-07-02 16:00:54 +02:00
|
|
|
|
|
|
|
|
2023-08-29 18:37:27 +02:00
|
|
|
notification_providers = build_notification_providers()
|
2023-05-20 13:10:12 +02:00
|
|
|
|
|
|
|
notification_provider_conditions = {}
|
|
|
|
for notification_provider in notification_providers:
|
|
|
|
for notification_provider_input_name in notification_providers[notification_provider]["inputs"]:
|
|
|
|
notification_provider_input = notification_providers[notification_provider]["inputs"][notification_provider_input_name]
|
|
|
|
if notification_provider_input["conditions"]:
|
|
|
|
notification_provider_conditions[notification_provider_input_name] = notification_provider_input["conditions"]
|
2022-12-29 00:22:53 +01:00
|
|
|
|
2023-05-20 13:10:12 +02:00
|
|
|
write_to_file(
|
|
|
|
"notification_providers.py.j2", "./../uptime_kuma_api/notification_providers.py",
|
|
|
|
notification_providers=notification_providers,
|
|
|
|
notification_provider_conditions=notification_provider_conditions
|
|
|
|
)
|