From 345fbdbbd26e49894443ba7b2498bc131aaaa088 Mon Sep 17 00:00:00 2001 From: lucasheld Date: Sat, 20 May 2023 12:37:04 +0200 Subject: [PATCH 1/3] feat: add required value to notification options --- scripts/build_notifications.py | 178 +++++-- scripts/notification_providers.py.j2 | 32 +- uptime_kuma_api/notification_providers.py | 622 +++++++++++----------- 3 files changed, 466 insertions(+), 366 deletions(-) diff --git a/scripts/build_notifications.py b/scripts/build_notifications.py index 2f09d6c..665cbd4 100644 --- a/scripts/build_notifications.py +++ b/scripts/build_notifications.py @@ -6,9 +6,84 @@ from bs4 import BeautifulSoup from utils import deduplicate_list, write_to_file +# deprecated or wrong inputs +ignored_inputs = { + "slack": [ + "slackbutton" + ], + "rocket.chat": [ + "rocketbutton" + ], + "octopush": [ + "octopushDMLogin", + "octopushDMAPIKey", + "octopushDMPhoneNumber", + "octopushDMSenderName", + "octopushDMSMSType" + ], + "Splunk": [ + "pagerdutyIntegrationKey" + ] +} + +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", + "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", +} + + def build_notification_providers(root): - providers = [] - for path in glob.glob(f'{root}/server/notification-providers/*'): + providers = {} + + # get providers and input names + for path in sorted(glob.glob(f'{root}/server/notification-providers/*')): with open(path) as f: content = f.read() match = re.search(r'class [^ ]+ extends NotificationProvider {', content) @@ -16,19 +91,19 @@ def build_notification_providers(root): match = re.search(r'name = "([^"]+)";', content) name = match.group(1) - inputs = re.findall(r'notification\.([^ ,.;})\]]+)', content) + inputs = re.findall(r'notification\??\.([^ ,.;})\]]+)', content) inputs = deduplicate_list(inputs) inputs = [i.strip() for i in inputs] - providers.append({ - "name": name, - "inputs": inputs, - }) - return providers + providers[name] = { + "title": titles.get(name, name), + "inputs": {}, + } + for input_ in inputs: + if input_ not in ignored_inputs.get(name, []): + providers[name]["inputs"][input_] = {} - -def build_notification_provider_conditions(root): - conditions = {} + # get inputs for path in glob.glob(f'{root}/src/components/notifications/*'): if path.endswith("index.js"): continue @@ -37,21 +112,45 @@ def build_notification_provider_conditions(root): match = re.search(r'', content, re.MULTILINE) html = match.group(0) soup = BeautifulSoup(html, "html.parser") - inputs = soup.find_all("input") - for input in inputs: - condition = {} - attrs = input.attrs + inputs = soup.find_all(attrs={"v-model": True}) + for input_ in inputs: + conditions = {} + attrs = input_.attrs v_model = attrs.get("v-model") - min_ = attrs.get("min") - max_ = attrs.get("max") - if min_: - condition["min"] = int(min_) - if max_: - condition["max"] = int(max_) param_name = re.match(r'\$parent.notification.(.*)$', v_model).group(1) - if condition: - conditions[param_name] = condition - return conditions + type_ = attrs.get("type") + if type_ == "number": + type_ = "int" + elif type_ == "checkbox": + type_ = "bool" + else: + type_ = "str" + required = attrs.get("required") + if required in ['', 'true']: + required = True + else: + required = False + min_ = attrs.get("min") + if min_: + conditions["min"] = int(min_) + max_ = attrs.get("max") + if max_: + 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 def diff(old, new): @@ -64,16 +163,25 @@ def diff(old, new): print("") -# write_to_file( -# "notification_providers.py.j2", "./../uptime_kuma_api/notification_providers.py", -# notification_providers=notification_providers, -# notification_provider_conditions=notification_provider_conditions -# ) +notification_providers = build_notification_providers("uptime-kuma") -notification_providers_old = build_notification_providers("uptime-kuma-old") -notification_providers_new = build_notification_providers("uptime-kuma") -diff(notification_providers_old, notification_providers_new) +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"] -notification_provider_conditions_old = build_notification_provider_conditions("uptime-kuma-old") -notification_provider_conditions_new = build_notification_provider_conditions("uptime-kuma") -diff(notification_provider_conditions_old, notification_provider_conditions_new) +write_to_file( + "notification_providers.py.j2", "./../uptime_kuma_api/notification_providers.py", + notification_providers=notification_providers, + notification_provider_conditions=notification_provider_conditions +) + +# notification_providers_old = build_notification_providers("uptime-kuma-old") +# notification_providers_new = build_notification_providers("uptime-kuma") +# diff(notification_providers_old, notification_providers_new) +# +# notification_provider_conditions_old = build_notification_provider_conditions("uptime-kuma-old") +# notification_provider_conditions_new = build_notification_provider_conditions("uptime-kuma") +# diff(notification_provider_conditions_old, notification_provider_conditions_new) diff --git a/scripts/notification_providers.py.j2 b/scripts/notification_providers.py.j2 index 896f05d..058f468 100644 --- a/scripts/notification_providers.py.j2 +++ b/scripts/notification_providers.py.j2 @@ -2,30 +2,30 @@ from enum import Enum class NotificationType(str, Enum): -{%- for notification_provider in notification_providers %} - {%- set name = notification_provider["name"] %} - {{ name.upper().replace(".", "_") }} = "{{ name }}" -{%- endfor %} - + """Enumerate notification types.""" +{% for provider in notification_providers %} + {{ provider.upper().replace(".", "_") }} = "{{ provider }}" + """{{ notification_providers[provider]["title"] }}""" +{% endfor %} notification_provider_options = { -{%- for notification_provider in notification_providers %} - {%- set name = notification_provider["name"] %} - NotificationType.{{ name.upper().replace(".", "_") }}: [ - {%- for input in notification_provider["inputs"] %} - "{{ input }}", +{%- for provider in notification_providers %} + NotificationType.{{ provider.upper().replace(".", "_") }}: dict( + {%- for input_name in notification_providers[provider]["inputs"] %} + {%- set input = notification_providers[provider]["inputs"][input_name] %} + {{ input_name }}=dict(type="{{ input["type"] }}", required={{ input["required"] }}), {%- endfor %} - ], + ), {%- endfor %} } -notification_provider_conditions = { +notification_provider_conditions = dict( {%- for provider in notification_provider_conditions %} - "{{ provider }}": { + {{ provider }}=dict( {%- for key, value in notification_provider_conditions[provider].items() %} - "{{ key }}": {{ value }}, + {{ key }}={{ value }}, {%- endfor %} - }, + ), {%- endfor %} -} +) diff --git a/uptime_kuma_api/notification_providers.py b/uptime_kuma_api/notification_providers.py index ab23fb9..df288cd 100644 --- a/uptime_kuma_api/notification_providers.py +++ b/uptime_kuma_api/notification_providers.py @@ -7,12 +7,18 @@ class NotificationType(str, Enum): ALERTA = "alerta" """Alerta""" + ALERTNOW = "AlertNow" + """AlertNow""" + ALIYUNSMS = "AliyunSMS" """AliyunSMS""" APPRISE = "apprise" """Apprise (Support 50+ Notification services)""" + BARK = "Bark" + """Bark""" + CLICKSENDSMS = "clicksendsms" """ClickSend SMS""" @@ -25,8 +31,14 @@ class NotificationType(str, Enum): FEISHU = "Feishu" """Feishu""" + FREEMOBILE = "FreeMobile" + """FreeMobile (mobile.free.fr)""" + + GOALERT = "GoAlert" + """GoAlert""" + GOOGLECHAT = "GoogleChat" - """Google Chat (Google Workspace only)""" + """Google Chat (Google Workspace)""" GORUSH = "gorush" """Gorush""" @@ -34,8 +46,17 @@ class NotificationType(str, Enum): GOTIFY = "gotify" """Gotify""" + HOMEASSISTANT = "HomeAssistant" + """Home Assistant""" + + KOOK = "Kook" + """Kook""" + LINE = "line" - """Line Messenger""" + """LINE Messenger""" + + LINENOTIFY = "LineNotify" + """LINE Notify""" LUNASEA = "lunasea" """LunaSea""" @@ -46,9 +67,18 @@ class NotificationType(str, Enum): MATTERMOST = "mattermost" """Mattermost""" + NTFY = "ntfy" + """Ntfy""" + + OCTOPUSH = "octopush" + """Octopush""" + ONEBOT = "OneBot" """OneBot""" + OPSGENIE = "Opsgenie" + """Opsgenie""" + PAGERDUTY = "PagerDuty" """PagerDuty""" @@ -73,6 +103,9 @@ class NotificationType(str, Enum): ROCKET_CHAT = "rocket.chat" """Rocket.Chat""" + SERVERCHAN = "ServerChan" + """ServerChan""" + SERWERSMS = "serwersms" """SerwerSMS.pl""" @@ -82,374 +115,333 @@ class NotificationType(str, Enum): SLACK = "slack" """Slack""" + SMSEAGLE = "SMSEagle" + """SMSEagle""" + + SMSMANAGER = "SMSManager" + """SmsManager (smsmanager.cz)""" + SMTP = "smtp" """Email (SMTP)""" + SPLUNK = "Splunk" + """Splunk""" + + SQUADCAST = "squadcast" + """SquadCast""" + STACKFIELD = "stackfield" """Stackfield""" + TEAMS = "teams" + """Microsoft Teams""" + PUSHBYTECHULUS = "PushByTechulus" """Push by Techulus""" TELEGRAM = "telegram" """Telegram""" + TWILIO = "twilio" + """Twilio""" + WEBHOOK = "webhook" """Webhook""" WECOM = "WeCom" """WeCom""" - ALERTNOW = "AlertNow" - """AlertNow""" - - HOMEASSISTANT = "HomeAssistant" - """Home Assistant""" - - LINENOTIFY = "LineNotify" - """LineNotify""" - - BARK = "Bark" - """Bark""" - - GOALERT = "GoAlert" - """GoAlert""" - - OCTOPUSH = "octopush" - """Octopush""" - - SERVERCHAN = "ServerChan" - """ServerChan""" - - SMSMANAGER = "SMSManager" - """SMSManager""" - - SQUADCAST = "squadcast" - """Squadcast""" - - TEAMS = "teams" - """Microsoft Teams""" - - FREEMOBILE = "FreeMobile" - """FreeMobile""" - - NTFY = "ntfy" - """ntfy""" - - SMSEAGLE = "SMSEagle" - """SMSEagle""" - ZOHOCLIQ = "ZohoCliq" """ZohoCliq""" - KOOK = "Kook" - """Kook""" - - SPLUNK = "Splunk" - """Splunk""" - - OPSGENIE = "Opsgenie" - """Opsgenie""" - - TWILIO = "twilio" - """twilio""" - notification_provider_options = { NotificationType.ALERTA: dict( - alertaApiEndpoint=dict( - type="str" - ), - alertaApiKey=dict(type="str"), - alertaEnvironment=dict(type="str"), - alertaAlertState=dict(type="str"), - alertaRecoverState=dict(type="str"), - ), - NotificationType.ALIYUNSMS: dict( - phonenumber=dict(type="str"), - templateCode=dict(type="str"), - signName=dict(type="str"), - accessKeyId=dict(type="str"), - secretAccessKey=dict(type="str"), - ), - NotificationType.APPRISE: dict( - appriseURL=dict(type="str"), - title=dict(type="str"), - ), - NotificationType.CLICKSENDSMS: dict( - clicksendsmsLogin=dict(type="str"), - clicksendsmsPassword=dict(type="str"), - clicksendsmsToNumber=dict(type="str"), - clicksendsmsSenderName=dict(type="str"), - ), - NotificationType.DINGDING: dict( - webHookUrl=dict(type="str"), - secretKey=dict(type="str"), - ), - NotificationType.DISCORD: dict( - discordUsername=dict(type="str"), - discordWebhookUrl=dict(type="str"), - discordPrefixMessage=dict(type="str"), - ), - NotificationType.FEISHU: dict( - feishuWebHookUrl=dict(type="str"), - ), - NotificationType.GOOGLECHAT: dict( - googleChatWebhookURL=dict(type="str"), - ), - NotificationType.GORUSH: dict( - gorushDeviceToken=dict(type="str"), - gorushPlatform=dict(type="str"), - gorushTitle=dict(type="str"), - gorushPriority=dict(type="str"), - gorushRetry=dict(type="str"), - gorushTopic=dict(type="str"), - gorushServerURL=dict(type="str"), - ), - NotificationType.GOTIFY: dict( - gotifyserverurl=dict(type="str"), - gotifyapplicationToken=dict(type="str"), - gotifyPriority=dict(type="int"), - ), - NotificationType.LINE: dict( - lineChannelAccessToken=dict(type="str"), - lineUserID=dict(type="str"), - ), - NotificationType.LUNASEA: dict( - lunaseaTarget=dict(type="str"), - lunaseaUserID=dict(type="str"), - lunaseaDevice=dict(type="str"), - ), - NotificationType.MATRIX: dict( - internalRoomId=dict(type="str"), - accessToken=dict(type="str"), - homeserverUrl=dict(type="str"), - ), - NotificationType.MATTERMOST: dict( - mattermostusername=dict(type="str"), - mattermostWebhookUrl=dict(type="str"), - mattermostchannel=dict(type="str"), - mattermosticonemo=dict(type="str"), - mattermosticonurl=dict(type="str"), - ), - NotificationType.ONEBOT: dict( - httpAddr=dict(type="str"), - accessToken=dict(type="str"), - msgType=dict(type="str"), - recieverId=dict(type="str"), - ), - NotificationType.PAGERDUTY: dict( - pagerdutyAutoResolve=dict(type="str"), - pagerdutyIntegrationUrl=dict(type="str"), - pagerdutyPriority=dict(type="str"), - pagerdutyIntegrationKey=dict(type="str"), - ), - NotificationType.PAGERTREE: dict( - pagertreeAutoResolve=dict(type="str"), - pagertreeIntegrationUrl=dict(type="str"), - pagertreeUrgency=dict(type="str"), - ), - NotificationType.PROMOSMS: dict( - promosmsLogin=dict(type="str"), - promosmsPassword=dict(type="str"), - promosmsPhoneNumber=dict(type="str"), - promosmsSMSType=dict(type="str"), - promosmsSenderName=dict(type="str"), - promosmsAllowLongSMS=dict(type="bool"), - ), - NotificationType.PUSHBULLET: dict( - pushbulletAccessToken=dict(type="str"), - ), - NotificationType.PUSHDEER: dict( - pushdeerKey=dict(type="str"), - ), - NotificationType.PUSHOVER: dict( - pushoveruserkey=dict(type="str"), - pushoverapptoken=dict(type="str"), - pushoversounds=dict(type="str"), - pushoverpriority=dict(type="str"), - pushovertitle=dict(type="str"), - pushoverdevice=dict(type="str"), - ), - NotificationType.PUSHY: dict( - pushyAPIKey=dict(type="str"), - pushyToken=dict(type="str"), - ), - NotificationType.ROCKET_CHAT: dict( - rocketchannel=dict(type="str"), - rocketusername=dict(type="str"), - rocketiconemo=dict(type="str"), - rocketwebhookURL=dict(type="str"), - rocketbutton=dict(type="str"), - ), - NotificationType.SERWERSMS: dict( - serwersmsUsername=dict(type="str"), - serwersmsPassword=dict(type="str"), - serwersmsPhoneNumber=dict(type="str"), - serwersmsSenderName=dict(type="str"), - ), - NotificationType.SIGNAL: dict( - signalNumber=dict(type="str"), - signalRecipients=dict(type="str"), - signalURL=dict(type="str"), - ), - NotificationType.SLACK: dict( - slackbutton=dict(type="str"), - slackchannel=dict(type="str"), - slackusername=dict(type="str"), - slackiconemo=dict(type="str"), - slackwebhookURL=dict(type="str"), - ), - NotificationType.SMTP: dict( - smtpHost=dict(type="str"), - smtpPort=dict(type="int"), - smtpSecure=dict(type="str"), - smtpIgnoreTLSError=dict(type="str"), - smtpDkimDomain=dict(type="str"), - smtpDkimKeySelector=dict(type="str"), - smtpDkimPrivateKey=dict(type="str"), - smtpDkimHashAlgo=dict(type="str"), - smtpDkimheaderFieldNames=dict(type="str"), - smtpDkimskipFields=dict(type="str"), - smtpUsername=dict(type="str"), - smtpPassword=dict(type="str"), - customSubject=dict(type="str"), - smtpFrom=dict(type="str"), - smtpCC=dict(type="str"), - smtpBCC=dict(type="str"), - smtpTo=dict(type="str"), - ), - NotificationType.STACKFIELD: dict( - stackfieldwebhookURL=dict(type="str"), - ), - NotificationType.PUSHBYTECHULUS: dict( - pushAPIKey=dict(type="str"), - ), - NotificationType.TELEGRAM: dict( - telegramChatID=dict(type="str"), - telegramSendSilently=dict(type="bool"), - telegramProtectContent=dict(type="bool"), - telegramMessageThreadID=dict(type="str"), - telegramBotToken=dict(type="str"), - ), - NotificationType.WEBHOOK: dict( - webhookContentType=dict(type="str"), - webhookAdditionalHeaders=dict(type="str"), - webhookURL=dict(type="str"), - ), - NotificationType.WECOM: dict( - weComBotKey=dict(type="str"), + alertaApiEndpoint=dict(type="str", required=True), + alertaApiKey=dict(type="str", required=True), + alertaEnvironment=dict(type="str", required=True), + alertaAlertState=dict(type="str", required=True), + alertaRecoverState=dict(type="str", required=True), ), NotificationType.ALERTNOW: dict( - alertNowWebhookURL=dict(type="str"), + alertNowWebhookURL=dict(type="str", required=True), ), - NotificationType.HOMEASSISTANT: dict( - homeAssistantUrl=dict(type="str"), - longLivedAccessToken=dict(type="str"), + NotificationType.ALIYUNSMS: dict( + phonenumber=dict(type="str", required=True), + templateCode=dict(type="str", required=True), + signName=dict(type="str", required=True), + accessKeyId=dict(type="str", required=True), + secretAccessKey=dict(type="str", required=True), ), - NotificationType.LINENOTIFY: dict( - lineNotifyAccessToken=dict(type="str"), + NotificationType.APPRISE: dict( + appriseURL=dict(type="str", required=True), + title=dict(type="str", required=False), ), NotificationType.BARK: dict( - barkEndpoint=dict(type="str"), - barkGroup=dict(type="str"), - barkSound=dict(type="str"), + barkEndpoint=dict(type="str", required=True), + barkGroup=dict(type="str", required=True), + barkSound=dict(type="str", required=True), ), - NotificationType.GOALERT: dict( - goAlertBaseURL=dict(type="str"), - goAlertToken=dict(type="str"), + NotificationType.CLICKSENDSMS: dict( + clicksendsmsLogin=dict(type="str", required=True), + clicksendsmsPassword=dict(type="str", required=False), + clicksendsmsToNumber=dict(type="str", required=True), + clicksendsmsSenderName=dict(type="str", required=False), ), - NotificationType.OCTOPUSH: dict( - octopushVersion=dict(type="str"), - octopushAPIKey=dict(type="str"), - octopushLogin=dict(type="str"), - octopushPhoneNumber=dict(type="str"), - octopushSMSType=dict(type="str"), - octopushSenderName=dict(type="str"), - octopushDMLogin=dict(type="str"), - octopushDMAPIKey=dict(type="str"), - octopushDMPhoneNumber=dict(type="str"), - octopushDMSenderName=dict(type="str"), - octopushDMSMSType=dict(type="str"), + NotificationType.DINGDING: dict( + webHookUrl=dict(type="str", required=True), + secretKey=dict(type="str", required=True), ), - NotificationType.SERVERCHAN: dict( - serverChanSendKey=dict(type="str"), + NotificationType.DISCORD: dict( + discordUsername=dict(type="str", required=False), + discordWebhookUrl=dict(type="str", required=True), + discordPrefixMessage=dict(type="str", required=False), ), - NotificationType.SMSMANAGER: dict( - smsmanagerApiKey=dict(type="str"), - numbers=dict(type="str"), - messageType=dict(type="str"), - ), - NotificationType.SQUADCAST: dict( - squadcastWebhookURL=dict(type="str"), - ), - NotificationType.TEAMS: dict( - webhookUrl=dict(type="str"), + NotificationType.FEISHU: dict( + feishuWebHookUrl=dict(type="str", required=True), ), NotificationType.FREEMOBILE: dict( - freemobileUser=dict(type="str"), - freemobilePass=dict(type="str"), + freemobileUser=dict(type="str", required=True), + freemobilePass=dict(type="str", required=True), ), - NotificationType.NTFY: dict( - ntfyusername=dict(type="str"), - ntfypassword=dict(type="str"), - ntfytopic=dict(type="str"), - ntfyPriority=dict(type="int"), - ntfyIcon=dict(type="str"), - ntfyserverurl=dict(type="str"), + NotificationType.GOALERT: dict( + goAlertBaseURL=dict(type="str", required=True), + goAlertToken=dict(type="str", required=False), ), - NotificationType.SMSEAGLE: dict( - smseagleEncoding=dict(type="bool"), - smseaglePriority=dict(type="int"), - smseagleRecipientType=dict(type="str"), - smseagleToken=dict(type="str"), - smseagleRecipient=dict(type="str"), - smseagleUrl=dict(type="str") + NotificationType.GOOGLECHAT: dict( + googleChatWebhookURL=dict(type="str", required=True), ), - NotificationType.ZOHOCLIQ: dict( - webhookUrl=dict(type="str") + NotificationType.GORUSH: dict( + gorushDeviceToken=dict(type="str", required=True), + gorushPlatform=dict(type="str", required=False), + gorushTitle=dict(type="str", required=False), + gorushPriority=dict(type="str", required=False), + gorushRetry=dict(type="int", required=False), + gorushTopic=dict(type="str", required=False), + gorushServerURL=dict(type="str", required=True), + ), + NotificationType.GOTIFY: dict( + gotifyserverurl=dict(type="str", required=True), + gotifyapplicationToken=dict(type="str", required=False), + gotifyPriority=dict(type="int", required=True), + ), + NotificationType.HOMEASSISTANT: dict( + notificationService=dict(type="str", required=False), + homeAssistantUrl=dict(type="str", required=True), + longLivedAccessToken=dict(type="str", required=True), ), NotificationType.KOOK: dict( - kookGuildID=dict(type="str"), - kookBotToken=dict(type="str") + kookGuildID=dict(type="str", required=True), + kookBotToken=dict(type="str", required=False), ), - NotificationType.SPLUNK: dict( - splunkAutoResolve=dict(type="str"), - splunkSeverity=dict(type="str"), - splunkRestURL=dict(type="str") + NotificationType.LINE: dict( + lineChannelAccessToken=dict(type="str", required=False), + lineUserID=dict(type="str", required=True), + ), + NotificationType.LINENOTIFY: dict( + lineNotifyAccessToken=dict(type="str", required=False), + ), + NotificationType.LUNASEA: dict( + lunaseaTarget=dict(type="str", required=True), + lunaseaUserID=dict(type="str", required=False), + lunaseaDevice=dict(type="str", required=False), + ), + NotificationType.MATRIX: dict( + internalRoomId=dict(type="str", required=True), + accessToken=dict(type="str", required=True), + homeserverUrl=dict(type="str", required=False), + ), + NotificationType.MATTERMOST: dict( + mattermostusername=dict(type="str", required=False), + mattermostWebhookUrl=dict(type="str", required=True), + mattermostchannel=dict(type="str", required=False), + mattermosticonemo=dict(type="str", required=False), + mattermosticonurl=dict(type="str", required=False), + ), + NotificationType.NTFY: dict( + ntfyusername=dict(type="str", required=False), + ntfypassword=dict(type="str", required=False), + ntfytopic=dict(type="str", required=True), + ntfyPriority=dict(type="int", required=True), + ntfyIcon=dict(type="str", required=False), + ntfyserverurl=dict(type="str", required=True), + ), + NotificationType.OCTOPUSH: dict( + octopushVersion=dict(type="str", required=False), + octopushAPIKey=dict(type="str", required=False), + octopushLogin=dict(type="str", required=True), + octopushPhoneNumber=dict(type="str", required=True), + octopushSMSType=dict(type="str", required=False), + octopushSenderName=dict(type="str", required=False), + ), + NotificationType.ONEBOT: dict( + httpAddr=dict(type="str", required=True), + accessToken=dict(type="str", required=True), + msgType=dict(type="str", required=False), + recieverId=dict(type="str", required=True), ), NotificationType.OPSGENIE: dict( - opsgeniePriority=dict(type="int"), - opsgenieRegion=dict(type="str"), - opsgenieApiKey=dict(type="str") + opsgeniePriority=dict(type="int", required=False), + opsgenieRegion=dict(type="str", required=True), + opsgenieApiKey=dict(type="str", required=True), + ), + NotificationType.PAGERDUTY: dict( + pagerdutyAutoResolve=dict(type="str", required=False), + pagerdutyIntegrationUrl=dict(type="str", required=False), + pagerdutyPriority=dict(type="str", required=False), + pagerdutyIntegrationKey=dict(type="str", required=False), + ), + NotificationType.PAGERTREE: dict( + pagertreeAutoResolve=dict(type="str", required=False), + pagertreeIntegrationUrl=dict(type="str", required=False), + pagertreeUrgency=dict(type="str", required=False), + ), + NotificationType.PROMOSMS: dict( + promosmsAllowLongSMS=dict(type="bool", required=False), + promosmsLogin=dict(type="str", required=True), + promosmsPassword=dict(type="str", required=False), + promosmsPhoneNumber=dict(type="str", required=True), + promosmsSMSType=dict(type="str", required=False), + promosmsSenderName=dict(type="str", required=False), + ), + NotificationType.PUSHBULLET: dict( + pushbulletAccessToken=dict(type="str", required=False), + ), + NotificationType.PUSHDEER: dict( + pushdeerKey=dict(type="str", required=False), + ), + NotificationType.PUSHOVER: dict( + pushoveruserkey=dict(type="str", required=False), + pushoverapptoken=dict(type="str", required=False), + pushoversounds=dict(type="str", required=False), + pushoverpriority=dict(type="str", required=False), + pushovertitle=dict(type="str", required=False), + pushoverdevice=dict(type="str", required=False), + ), + NotificationType.PUSHY: dict( + pushyAPIKey=dict(type="str", required=False), + pushyToken=dict(type="str", required=False), + ), + NotificationType.ROCKET_CHAT: dict( + rocketchannel=dict(type="str", required=False), + rocketusername=dict(type="str", required=False), + rocketiconemo=dict(type="str", required=False), + rocketwebhookURL=dict(type="str", required=True), + ), + NotificationType.SERVERCHAN: dict( + serverChanSendKey=dict(type="str", required=False), + ), + NotificationType.SERWERSMS: dict( + serwersmsUsername=dict(type="str", required=True), + serwersmsPassword=dict(type="str", required=False), + serwersmsPhoneNumber=dict(type="str", required=True), + serwersmsSenderName=dict(type="str", required=False), + ), + NotificationType.SIGNAL: dict( + signalNumber=dict(type="str", required=True), + signalRecipients=dict(type="str", required=True), + signalURL=dict(type="str", required=True), + ), + NotificationType.SLACK: dict( + slackchannel=dict(type="str", required=False), + slackusername=dict(type="str", required=False), + slackiconemo=dict(type="str", required=False), + slackwebhookURL=dict(type="str", required=True), + ), + NotificationType.SMSEAGLE: dict( + smseagleEncoding=dict(type="bool", required=False), + smseaglePriority=dict(type="int", required=False), + smseagleRecipientType=dict(type="str", required=False), + smseagleToken=dict(type="str", required=False), + smseagleRecipient=dict(type="str", required=True), + smseagleUrl=dict(type="str", required=True), + ), + NotificationType.SMSMANAGER: dict( + smsmanagerApiKey=dict(type="str", required=False), + numbers=dict(type="str", required=False), + messageType=dict(type="str", required=False), + ), + NotificationType.SMTP: dict( + smtpHost=dict(type="str", required=True), + smtpPort=dict(type="int", required=True), + smtpSecure=dict(type="str", required=False), + smtpIgnoreTLSError=dict(type="bool", required=False), + smtpDkimDomain=dict(type="str", required=False), + smtpDkimKeySelector=dict(type="str", required=False), + smtpDkimPrivateKey=dict(type="str", required=False), + smtpDkimHashAlgo=dict(type="str", required=False), + smtpDkimheaderFieldNames=dict(type="str", required=False), + smtpDkimskipFields=dict(type="str", required=False), + smtpUsername=dict(type="str", required=False), + smtpPassword=dict(type="str", required=False), + customSubject=dict(type="str", required=False), + smtpFrom=dict(type="str", required=True), + smtpCC=dict(type="str", required=False), + smtpBCC=dict(type="str", required=False), + smtpTo=dict(type="str", required=False), + ), + NotificationType.SPLUNK: dict( + splunkAutoResolve=dict(type="str", required=False), + splunkSeverity=dict(type="str", required=False), + splunkRestURL=dict(type="str", required=False), + ), + NotificationType.SQUADCAST: dict( + squadcastWebhookURL=dict(type="str", required=True), + ), + NotificationType.STACKFIELD: dict( + stackfieldwebhookURL=dict(type="str", required=True), + ), + NotificationType.TEAMS: dict( + webhookUrl=dict(type="str", required=True), + ), + NotificationType.PUSHBYTECHULUS: dict( + pushAPIKey=dict(type="str", required=False), + ), + NotificationType.TELEGRAM: dict( + telegramChatID=dict(type="str", required=True), + telegramSendSilently=dict(type="bool", required=False), + telegramProtectContent=dict(type="bool", required=False), + telegramMessageThreadID=dict(type="str", required=False), + telegramBotToken=dict(type="str", required=False), ), NotificationType.TWILIO: dict( - twilioAccountSID=dict(type="str"), - twilioAuthToken=dict(type="str"), - twilioToNumber=dict(type="str"), - twilioFromNumber=dict(type="str") - ) + twilioAccountSID=dict(type="str", required=True), + twilioAuthToken=dict(type="str", required=True), + twilioToNumber=dict(type="str", required=True), + twilioFromNumber=dict(type="str", required=True), + ), + NotificationType.WEBHOOK: dict( + webhookContentType=dict(type="str", required=True), + webhookAdditionalHeaders=dict(type="str", required=False), + webhookURL=dict(type="str", required=True), + ), + NotificationType.WECOM: dict( + weComBotKey=dict(type="str", required=True), + ), + NotificationType.ZOHOCLIQ: dict( + webhookUrl=dict(type="str", required=True), + ), } notification_provider_conditions = dict( gotifyPriority=dict( min=0, - max=10 - ), - smtpPort=dict( - min=0, - max=65535 + max=10, ), ntfyPriority=dict( min=1, - max=5 - ), - smseaglePriority=dict( - min=0, - max=9 + max=5, ), opsgeniePriority=dict( min=1, - max=5 - ) + max=5, + ), + smseaglePriority=dict( + min=0, + max=9, + ), + smtpPort=dict( + min=0, + max=65535, + ), ) -- 2.47.0 From f0c5f2ba9db363f1129e7a15f218737245bd4ec7 Mon Sep 17 00:00:00 2001 From: lucasheld Date: Sat, 20 May 2023 12:43:57 +0200 Subject: [PATCH 2/3] feat: drop support for Uptime Kuma versions < 1.21.3 BREAKING CHANGE: Uptime Kuma versions < 1.21.3 are not supported in uptime-kuma-api 1.x.x --- tests/test_api_key.py | 9 +---- tests/test_docker_host.py | 7 ---- tests/test_game_list.py | 8 ----- tests/test_maintenance.py | 19 ++--------- tests/test_monitor.py | 60 ++++++++-------------------------- tests/test_settings.py | 17 +++------- tests/test_status_page.py | 9 ++--- tests/test_tag.py | 17 ++++------ tests/uptime_kuma_test_case.py | 30 ++++++++--------- uptime_kuma_api/api.py | 58 ++++++++------------------------ 10 files changed, 57 insertions(+), 177 deletions(-) diff --git a/tests/test_api_key.py b/tests/test_api_key.py index a0fdbc6..48ea269 100644 --- a/tests/test_api_key.py +++ b/tests/test_api_key.py @@ -1,17 +1,10 @@ import unittest -from packaging.version import parse as parse_version -from uptime_kuma_api import DockerType, UptimeKumaException +from uptime_kuma_api import UptimeKumaException from uptime_kuma_test_case import UptimeKumaTestCase class TestApiKey(UptimeKumaTestCase): - def setUp(self): - super(TestApiKey, self).setUp() - if parse_version(self.api.version) < parse_version("1.21"): - super(TestApiKey, self).tearDown() - self.skipTest("Unsupported in this Uptime Kuma version") - def test_api_key(self): # get empty list to make sure that future accesses will also work self.api.get_api_keys() diff --git a/tests/test_docker_host.py b/tests/test_docker_host.py index 165cd26..2b264ab 100644 --- a/tests/test_docker_host.py +++ b/tests/test_docker_host.py @@ -1,17 +1,10 @@ import unittest -from packaging.version import parse as parse_version from uptime_kuma_api import DockerType, UptimeKumaException from uptime_kuma_test_case import UptimeKumaTestCase class TestDockerHost(UptimeKumaTestCase): - def setUp(self): - super(TestDockerHost, self).setUp() - if parse_version(self.api.version) < parse_version("1.18"): - super(TestDockerHost, self).tearDown() - self.skipTest("Unsupported in this Uptime Kuma version") - def test_docker_host(self): # get empty list to make sure that future accesses will also work self.api.get_docker_hosts() diff --git a/tests/test_game_list.py b/tests/test_game_list.py index a76e318..c875cc3 100644 --- a/tests/test_game_list.py +++ b/tests/test_game_list.py @@ -1,17 +1,9 @@ import unittest -from packaging.version import parse as parse_version - from uptime_kuma_test_case import UptimeKumaTestCase class TestGameList(UptimeKumaTestCase): - def setUp(self): - super(TestGameList, self).setUp() - if parse_version(self.api.version) < parse_version("1.20"): - super(TestGameList, self).tearDown() - self.skipTest("Unsupported in this Uptime Kuma version") - def test_game_list(self): game_list = self.api.get_game_list() self.assertTrue("keys" in game_list[0]) diff --git a/tests/test_maintenance.py b/tests/test_maintenance.py index cb443e3..122026e 100644 --- a/tests/test_maintenance.py +++ b/tests/test_maintenance.py @@ -1,18 +1,10 @@ import unittest -from packaging.version import parse as parse_version - from uptime_kuma_api import UptimeKumaException, MaintenanceStrategy from uptime_kuma_test_case import UptimeKumaTestCase class TestMaintenance(UptimeKumaTestCase): - def setUp(self): - super(TestMaintenance, self).setUp() - if parse_version(self.api.version) < parse_version("1.19"): - super(TestMaintenance, self).tearDown() - self.skipTest("Unsupported in this Uptime Kuma version") - def test_maintenance(self): expected_maintenance = { "title": "maintenance 1", @@ -25,14 +17,10 @@ class TestMaintenance(UptimeKumaTestCase): "2022-12-29 22:36:00" ], "weekdays": [], - "daysOfMonth": [] + "daysOfMonth": [], + "timezoneOption": "Europe/Berlin" } - if parse_version(self.api.version) >= parse_version("1.21.2"): - expected_maintenance.update({ - "timezoneOption": "Europe/Berlin" - }) - # add maintenance r = self.api.add_maintenance(**expected_maintenance) self.assertEqual(r["msg"], "Added Successfully.") @@ -225,9 +213,6 @@ class TestMaintenance(UptimeKumaTestCase): self.do_test_maintenance_strategy(expected_maintenance) def test_maintenance_strategy_cron(self): - if parse_version(self.api.version) < parse_version("1.21.2"): - self.skipTest("Unsupported in this Uptime Kuma version") - expected_maintenance = { "title": "test", "description": "test", diff --git a/tests/test_monitor.py b/tests/test_monitor.py index 30964ab..516256f 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -1,5 +1,4 @@ import unittest -from packaging.version import parse as parse_version from uptime_kuma_api import UptimeKumaException, MonitorType, AuthMethod from uptime_kuma_test_case import UptimeKumaTestCase @@ -21,12 +20,9 @@ class TestMonitor(UptimeKumaTestCase): "maxretries": 0, "notificationIDList": [notification_id_1, notification_id_2], "upsideDown": False, - "url": "http://127.0.0.1" + "url": "http://127.0.0.1", + "resendInterval": 0 } - if parse_version(self.api.version) >= parse_version("1.18"): - expected_monitor.update({ - "resendInterval": 0 - }) # add monitor r = self.api.add_monitor(**expected_monitor) @@ -132,17 +128,16 @@ class TestMonitor(UptimeKumaTestCase): } self.do_test_monitor_type(expected_monitor) - if parse_version(self.api.version) >= parse_version("1.21"): - expected_monitor = { - "type": MonitorType.HTTP, - "name": "monitor 1", - "url": "http://127.0.0.1", - "authMethod": AuthMethod.MTLS, - "tlsCert": "cert", - "tlsKey": "key", - "tlsCa": "ca", - } - self.do_test_monitor_type(expected_monitor) + expected_monitor = { + "type": MonitorType.HTTP, + "name": "monitor 1", + "url": "http://127.0.0.1", + "authMethod": AuthMethod.MTLS, + "tlsCert": "cert", + "tlsKey": "key", + "tlsCa": "ca", + } + self.do_test_monitor_type(expected_monitor) def test_monitor_type_port(self): expected_monitor = { @@ -157,12 +152,9 @@ class TestMonitor(UptimeKumaTestCase): expected_monitor = { "type": MonitorType.PING, "name": "monitor 1", - "hostname": "127.0.0.1" + "hostname": "127.0.0.1", + "packetSize": 56 } - if parse_version(self.api.version) >= parse_version("1.20"): - expected_monitor.update({ - "packetSize": 56 - }) self.do_test_monitor_type(expected_monitor) def test_monitor_type_keyword(self): @@ -175,9 +167,6 @@ class TestMonitor(UptimeKumaTestCase): self.do_test_monitor_type(expected_monitor) def test_monitor_type_grpc_keyword(self): - if parse_version(self.api.version) < parse_version("1.19"): - self.skipTest("Unsupported in this Uptime Kuma version") - expected_monitor = { "type": MonitorType.GRPC_KEYWORD, "name": "monitor 1", @@ -200,9 +189,6 @@ class TestMonitor(UptimeKumaTestCase): self.do_test_monitor_type(expected_monitor) def test_monitor_type_docker(self): - if parse_version(self.api.version) < parse_version("1.18"): - self.skipTest("Unsupported in this Uptime Kuma version") - docker_host_id = self.add_docker_host() expected_monitor = { "type": MonitorType.DOCKER, @@ -232,9 +218,6 @@ class TestMonitor(UptimeKumaTestCase): self.do_test_monitor_type(expected_monitor) def test_monitor_type_gamedig(self): - if parse_version(self.api.version) < parse_version("1.20"): - self.skipTest("Unsupported in this Uptime Kuma version") - game_list = self.api.get_game_list() game = game_list[0]["keys"][0] expected_monitor = { @@ -270,9 +253,6 @@ class TestMonitor(UptimeKumaTestCase): self.do_test_monitor_type(expected_monitor) def test_monitor_type_postgres(self): - if parse_version(self.api.version) < parse_version("1.18"): - self.skipTest("Unsupported in this Uptime Kuma version") - expected_monitor = { "type": MonitorType.POSTGRES, "name": "monitor 1", @@ -282,9 +262,6 @@ class TestMonitor(UptimeKumaTestCase): self.do_test_monitor_type(expected_monitor) def test_monitor_type_mysql(self): - if parse_version(self.api.version) < parse_version("1.19"): - self.skipTest("Unsupported in this Uptime Kuma version") - expected_monitor = { "type": MonitorType.MYSQL, "name": "monitor 1", @@ -294,9 +271,6 @@ class TestMonitor(UptimeKumaTestCase): self.do_test_monitor_type(expected_monitor) def test_monitor_type_mongodb(self): - if parse_version(self.api.version) < parse_version("1.20"): - self.skipTest("Unsupported in this Uptime Kuma version") - expected_monitor = { "type": MonitorType.MONGODB, "name": "monitor 1", @@ -305,9 +279,6 @@ class TestMonitor(UptimeKumaTestCase): self.do_test_monitor_type(expected_monitor) def test_monitor_type_radius(self): - if parse_version(self.api.version) < parse_version("1.18"): - self.skipTest("Unsupported in this Uptime Kuma version") - expected_monitor = { "type": MonitorType.RADIUS, "name": "monitor 1", @@ -320,9 +291,6 @@ class TestMonitor(UptimeKumaTestCase): self.do_test_monitor_type(expected_monitor) def test_monitor_type_redis(self): - if parse_version(self.api.version) < parse_version("1.20"): - self.skipTest("Unsupported in this Uptime Kuma version") - expected_monitor = { "type": MonitorType.REDIS, "name": "monitor 1", diff --git a/tests/test_settings.py b/tests/test_settings.py index c586702..9903048 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,6 +1,5 @@ import json import unittest -from packaging.version import parse as parse_version from uptime_kuma_test_case import UptimeKumaTestCase @@ -16,20 +15,12 @@ class TestSettings(UptimeKumaTestCase): "primaryBaseURL": "", "steamAPIKey": "", "tlsExpiryNotifyDays": [7, 14, 21], - "disableAuth": False + "disableAuth": False, + "trustProxy": False, + "serverTimezone": "Europe/Berlin", + "dnsCache": True } - if parse_version(self.api.version) >= parse_version("1.18"): - expected_settings.update({ - "trustProxy": False - }) - - if parse_version(self.api.version) >= parse_version("1.19"): - expected_settings.update({ - "serverTimezone": "Europe/Berlin", - "dnsCache": True, - }) - # set settings r = self.api.set_settings(self.password, **expected_settings) self.assertEqual(r["msg"], "Saved") diff --git a/tests/test_status_page.py b/tests/test_status_page.py index 305a6a8..1464942 100644 --- a/tests/test_status_page.py +++ b/tests/test_status_page.py @@ -1,7 +1,5 @@ import unittest -from packaging.version import parse as parse_version - from uptime_kuma_api import UptimeKumaException, IncidentStyle from uptime_kuma_test_case import UptimeKumaTestCase @@ -36,12 +34,9 @@ class TestStatusPage(UptimeKumaTestCase): } ] } - ] + ], + "googleAnalyticsId": "" } - if parse_version(self.api.version) >= parse_version("1.20"): - expected_status_page.update({ - "googleAnalyticsId": "" - }) # add status page r = self.api.add_status_page(slug, expected_status_page["title"]) diff --git a/tests/test_tag.py b/tests/test_tag.py index 1a93ea7..5b6b8bf 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -1,7 +1,5 @@ import unittest -from packaging.version import parse as parse_version - from uptime_kuma_api import UptimeKumaException from uptime_kuma_test_case import UptimeKumaTestCase @@ -28,14 +26,13 @@ class TestTag(UptimeKumaTestCase): self.assertIsNotNone(tag) self.compare(tag, expected_tag) - if parse_version(self.api.version) >= parse_version("1.20"): - # edit tag - expected_tag["name"] = "tag 1 new" - expected_tag["color"] = "#000000" - r = self.api.edit_tag(tag_id, **expected_tag) - self.assertEqual(r["msg"], "Saved") - tag = self.api.get_tag(tag_id) - self.compare(tag, expected_tag) + # edit tag + expected_tag["name"] = "tag 1 new" + expected_tag["color"] = "#000000" + r = self.api.edit_tag(tag_id, **expected_tag) + self.assertEqual(r["msg"], "Saved") + tag = self.api.get_tag(tag_id) + self.compare(tag, expected_tag) # delete tag r = self.api.delete_tag(tag_id) diff --git a/tests/uptime_kuma_test_case.py b/tests/uptime_kuma_test_case.py index 430ec05..6b005cb 100644 --- a/tests/uptime_kuma_test_case.py +++ b/tests/uptime_kuma_test_case.py @@ -1,8 +1,7 @@ import unittest import warnings -from packaging.version import parse as parse_version -from uptime_kuma_api import UptimeKumaApi, MonitorType, DockerType, UptimeKumaException +from uptime_kuma_api import UptimeKumaApi, MonitorType, DockerType token = None @@ -74,23 +73,20 @@ class UptimeKumaTestCase(unittest.TestCase): for status_page in status_pages: self.api.delete_status_page(status_page["slug"]) - if parse_version(self.api.version) >= parse_version("1.18"): - # delete docker hosts - docker_hosts = self.api.get_docker_hosts() - for docker_host in docker_hosts: - self.api.delete_docker_host(docker_host["id"]) + # delete docker hosts + docker_hosts = self.api.get_docker_hosts() + for docker_host in docker_hosts: + self.api.delete_docker_host(docker_host["id"]) - if parse_version(self.api.version) >= parse_version("1.19"): - # delete maintenances - maintenances = self.api.get_maintenances() - for maintenance in maintenances: - self.api.delete_maintenance(maintenance["id"]) + # delete maintenances + maintenances = self.api.get_maintenances() + for maintenance in maintenances: + self.api.delete_maintenance(maintenance["id"]) - if parse_version(self.api.version) >= parse_version("1.21"): - # delete api keys - api_keys = self.api.get_api_keys() - for api_key in api_keys: - self.api.delete_api_key(api_key["id"]) + # delete api keys + api_keys = self.api.get_api_keys() + for api_key in api_keys: + self.api.delete_api_key(api_key["id"]) # login again to receive initial messages self.api.disconnect() diff --git a/uptime_kuma_api/api.py b/uptime_kuma_api/api.py index 45ecfba..c2bbcbc 100644 --- a/uptime_kuma_api/api.py +++ b/uptime_kuma_api/api.py @@ -11,7 +11,6 @@ from typing import Any import requests import socketio -from packaging.version import parse as parse_version from . import (AuthMethod, DockerType, @@ -718,10 +717,6 @@ class UptimeKumaApi(object): # GAMEDIG game: str = None ) -> dict: - # https://github.com/louislam/uptime-kuma/compare/1.21.1...1.21.2#diff-f672603317047f3e6f27b0d7a44f6f244b7dbb5d0d0a85f1059a6b0bc2cb9aa0L910 - if parse_version(self.version) < parse_version("1.21.2"): - maxretries = 0 - data = { "type": type, "name": name, @@ -730,19 +725,11 @@ class UptimeKumaApi(object): "maxretries": maxretries, "notificationIDList": notificationIDList, "upsideDown": upsideDown, + "resendInterval": resendInterval, + "description": description, + "httpBodyEncoding": httpBodyEncoding } - if parse_version(self.version) >= parse_version("1.18"): - data.update({ - "resendInterval": resendInterval - }) - - if parse_version(self.version) >= parse_version("1.21"): - data.update({ - "description": description, - "httpBodyEncoding": httpBodyEncoding - }) - if type in [MonitorType.KEYWORD, MonitorType.GRPC_KEYWORD]: data.update({ "keyword": keyword, @@ -799,10 +786,9 @@ class UptimeKumaApi(object): }) # PING - if parse_version(self.version) >= parse_version("1.20"): - data.update({ - "packetSize": packetSize, - }) + data.update({ + "packetSize": packetSize, + }) # PORT, DNS, STEAM, MQTT, RADIUS if not port: @@ -906,14 +892,11 @@ class UptimeKumaApi(object): "strategy": strategy, "weekdays": weekdays, "daysOfMonth": daysOfMonth, - "timeRange": timeRange + "timeRange": timeRange, + "cron": cron, + "durationMinutes": durationMinutes, + "timezoneOption": timezoneOption } - if parse_version(self.version) >= parse_version("1.21.2"): - data.update({ - "cron": cron, - "durationMinutes": durationMinutes, - "timezoneOption": timezoneOption, - }) return data # monitor @@ -1211,11 +1194,6 @@ class UptimeKumaApi(object): ] """ r = self._call('getGameList') - # Workaround, gamelist is not available on first call. - # Fixed in https://github.com/louislam/uptime-kuma/commit/7b8ed01f272fc4c6b69ff6299185e936a5e63735 - # Exists in 1.20.0 - 1.21.0 - if not r: - r = self._call('getGameList') return r.get("gameList") @append_docstring(monitor_docstring("add")) @@ -1769,11 +1747,8 @@ class UptimeKumaApi(object): **config, "incident": r2["incident"], "publicGroupList": r2["publicGroupList"], + "maintenanceList": r2["maintenanceList"] } - if parse_version(self.version) >= parse_version("1.19"): - data.update({ - "maintenanceList": r2["maintenanceList"] - }) return data def add_status_page(self, slug: str, title: str) -> dict: @@ -1878,8 +1853,7 @@ class UptimeKumaApi(object): """ status_page = self.get_status_page(slug) status_page.pop("incident") - if parse_version(self.version) >= parse_version("1.19"): - status_page.pop("maintenanceList") + status_page.pop("maintenanceList") status_page.update(kwargs) data = _build_status_page_data(**status_page) r = self._call('saveStatusPage', data) @@ -2237,7 +2211,6 @@ class UptimeKumaApi(object): } } """ - # TODO: endless call if only ping monitors used return self._get_event_data(Event.CERT_INFO) # uptime @@ -2576,12 +2549,9 @@ class UptimeKumaApi(object): "steamAPIKey": steamAPIKey, "dnsCache": dnsCache, "tlsExpiryNotifyDays": tlsExpiryNotifyDays, - "disableAuth": disableAuth + "disableAuth": disableAuth, + "trustProxy": trustProxy } - if parse_version(self.version) >= parse_version("1.18"): - data.update({ - "trustProxy": trustProxy - }) return self._call('setSettings', (data, password)) def change_password(self, old_password: str, new_password: str) -> dict: -- 2.47.0 From 86e80a0ae4a422ba1373d78098f0ad18dac0dd13 Mon Sep 17 00:00:00 2001 From: lucasheld Date: Sat, 20 May 2023 13:07:38 +0200 Subject: [PATCH 3/3] add more required params and enable check --- scripts/build_notifications.py | 8 +++-- uptime_kuma_api/api.py | 7 ++-- uptime_kuma_api/notification_providers.py | 44 +++++++++++------------ 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/scripts/build_notifications.py b/scripts/build_notifications.py index 665cbd4..38e796a 100644 --- a/scripts/build_notifications.py +++ b/scripts/build_notifications.py @@ -118,6 +118,7 @@ def build_notification_providers(root): attrs = input_.attrs v_model = attrs.get("v-model") param_name = re.match(r'\$parent.notification.(.*)$', v_model).group(1) + type_ = attrs.get("type") if type_ == "number": type_ = "int" @@ -125,14 +126,17 @@ def build_notification_providers(root): type_ = "bool" else: type_ = "str" - required = attrs.get("required") - if required in ['', 'true']: + + 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 + min_ = attrs.get("min") if min_: conditions["min"] = int(min_) + max_ = attrs.get("max") if max_: conditions["max"] = int(max_) diff --git a/uptime_kuma_api/api.py b/uptime_kuma_api/api.py index 45ecfba..9d4f31d 100644 --- a/uptime_kuma_api/api.py +++ b/uptime_kuma_api/api.py @@ -305,10 +305,9 @@ def _check_arguments_notification(kwargs) -> None: required_args = ["type", "name"] _check_missing_arguments(required_args, kwargs) - # TODO: collect required notification args from /src/components/notifications/* - # type_ = kwargs["type"] - # required_args = notification_provider_options[type_] - # _check_missing_arguments(required_args, kwargs) + type_ = kwargs["type"] + required_args = notification_provider_options[type_] + _check_missing_arguments(required_args, kwargs) _check_argument_conditions(notification_provider_conditions, kwargs) diff --git a/uptime_kuma_api/notification_providers.py b/uptime_kuma_api/notification_providers.py index df288cd..7a48edf 100644 --- a/uptime_kuma_api/notification_providers.py +++ b/uptime_kuma_api/notification_providers.py @@ -184,7 +184,7 @@ notification_provider_options = { ), NotificationType.CLICKSENDSMS: dict( clicksendsmsLogin=dict(type="str", required=True), - clicksendsmsPassword=dict(type="str", required=False), + clicksendsmsPassword=dict(type="str", required=True), clicksendsmsToNumber=dict(type="str", required=True), clicksendsmsSenderName=dict(type="str", required=False), ), @@ -206,7 +206,7 @@ notification_provider_options = { ), NotificationType.GOALERT: dict( goAlertBaseURL=dict(type="str", required=True), - goAlertToken=dict(type="str", required=False), + goAlertToken=dict(type="str", required=True), ), NotificationType.GOOGLECHAT: dict( googleChatWebhookURL=dict(type="str", required=True), @@ -222,7 +222,7 @@ notification_provider_options = { ), NotificationType.GOTIFY: dict( gotifyserverurl=dict(type="str", required=True), - gotifyapplicationToken=dict(type="str", required=False), + gotifyapplicationToken=dict(type="str", required=True), gotifyPriority=dict(type="int", required=True), ), NotificationType.HOMEASSISTANT: dict( @@ -232,14 +232,14 @@ notification_provider_options = { ), NotificationType.KOOK: dict( kookGuildID=dict(type="str", required=True), - kookBotToken=dict(type="str", required=False), + kookBotToken=dict(type="str", required=True), ), NotificationType.LINE: dict( - lineChannelAccessToken=dict(type="str", required=False), + lineChannelAccessToken=dict(type="str", required=True), lineUserID=dict(type="str", required=True), ), NotificationType.LINENOTIFY: dict( - lineNotifyAccessToken=dict(type="str", required=False), + lineNotifyAccessToken=dict(type="str", required=True), ), NotificationType.LUNASEA: dict( lunaseaTarget=dict(type="str", required=True), @@ -249,7 +249,7 @@ notification_provider_options = { NotificationType.MATRIX: dict( internalRoomId=dict(type="str", required=True), accessToken=dict(type="str", required=True), - homeserverUrl=dict(type="str", required=False), + homeserverUrl=dict(type="str", required=True), ), NotificationType.MATTERMOST: dict( mattermostusername=dict(type="str", required=False), @@ -268,7 +268,7 @@ notification_provider_options = { ), NotificationType.OCTOPUSH: dict( octopushVersion=dict(type="str", required=False), - octopushAPIKey=dict(type="str", required=False), + octopushAPIKey=dict(type="str", required=True), octopushLogin=dict(type="str", required=True), octopushPhoneNumber=dict(type="str", required=True), octopushSMSType=dict(type="str", required=False), @@ -289,7 +289,7 @@ notification_provider_options = { pagerdutyAutoResolve=dict(type="str", required=False), pagerdutyIntegrationUrl=dict(type="str", required=False), pagerdutyPriority=dict(type="str", required=False), - pagerdutyIntegrationKey=dict(type="str", required=False), + pagerdutyIntegrationKey=dict(type="str", required=True), ), NotificationType.PAGERTREE: dict( pagertreeAutoResolve=dict(type="str", required=False), @@ -299,28 +299,28 @@ notification_provider_options = { NotificationType.PROMOSMS: dict( promosmsAllowLongSMS=dict(type="bool", required=False), promosmsLogin=dict(type="str", required=True), - promosmsPassword=dict(type="str", required=False), + promosmsPassword=dict(type="str", required=True), promosmsPhoneNumber=dict(type="str", required=True), promosmsSMSType=dict(type="str", required=False), promosmsSenderName=dict(type="str", required=False), ), NotificationType.PUSHBULLET: dict( - pushbulletAccessToken=dict(type="str", required=False), + pushbulletAccessToken=dict(type="str", required=True), ), NotificationType.PUSHDEER: dict( - pushdeerKey=dict(type="str", required=False), + pushdeerKey=dict(type="str", required=True), ), NotificationType.PUSHOVER: dict( - pushoveruserkey=dict(type="str", required=False), - pushoverapptoken=dict(type="str", required=False), + pushoveruserkey=dict(type="str", required=True), + pushoverapptoken=dict(type="str", required=True), pushoversounds=dict(type="str", required=False), pushoverpriority=dict(type="str", required=False), pushovertitle=dict(type="str", required=False), pushoverdevice=dict(type="str", required=False), ), NotificationType.PUSHY: dict( - pushyAPIKey=dict(type="str", required=False), - pushyToken=dict(type="str", required=False), + pushyAPIKey=dict(type="str", required=True), + pushyToken=dict(type="str", required=True), ), NotificationType.ROCKET_CHAT: dict( rocketchannel=dict(type="str", required=False), @@ -329,11 +329,11 @@ notification_provider_options = { rocketwebhookURL=dict(type="str", required=True), ), NotificationType.SERVERCHAN: dict( - serverChanSendKey=dict(type="str", required=False), + serverChanSendKey=dict(type="str", required=True), ), NotificationType.SERWERSMS: dict( serwersmsUsername=dict(type="str", required=True), - serwersmsPassword=dict(type="str", required=False), + serwersmsPassword=dict(type="str", required=True), serwersmsPhoneNumber=dict(type="str", required=True), serwersmsSenderName=dict(type="str", required=False), ), @@ -352,7 +352,7 @@ notification_provider_options = { smseagleEncoding=dict(type="bool", required=False), smseaglePriority=dict(type="int", required=False), smseagleRecipientType=dict(type="str", required=False), - smseagleToken=dict(type="str", required=False), + smseagleToken=dict(type="str", required=True), smseagleRecipient=dict(type="str", required=True), smseagleUrl=dict(type="str", required=True), ), @@ -383,7 +383,7 @@ notification_provider_options = { NotificationType.SPLUNK: dict( splunkAutoResolve=dict(type="str", required=False), splunkSeverity=dict(type="str", required=False), - splunkRestURL=dict(type="str", required=False), + splunkRestURL=dict(type="str", required=True), ), NotificationType.SQUADCAST: dict( squadcastWebhookURL=dict(type="str", required=True), @@ -395,14 +395,14 @@ notification_provider_options = { webhookUrl=dict(type="str", required=True), ), NotificationType.PUSHBYTECHULUS: dict( - pushAPIKey=dict(type="str", required=False), + pushAPIKey=dict(type="str", required=True), ), NotificationType.TELEGRAM: dict( telegramChatID=dict(type="str", required=True), telegramSendSilently=dict(type="bool", required=False), telegramProtectContent=dict(type="bool", required=False), telegramMessageThreadID=dict(type="str", required=False), - telegramBotToken=dict(type="str", required=False), + telegramBotToken=dict(type="str", required=True), ), NotificationType.TWILIO: dict( twilioAccountSID=dict(type="str", required=True), -- 2.47.0