forked from DGNum/uptime-kuma-api
add readme
This commit is contained in:
parent
a08d3b4613
commit
963adf8617
6 changed files with 36 additions and 1 deletions
1
scripts/.gitignore
vendored
Normal file
1
scripts/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
uptime-kuma
|
78
scripts/build_notifications.py
Normal file
78
scripts/build_notifications.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
import glob
|
||||
import re
|
||||
from pprint import pprint
|
||||
|
||||
import jinja2
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from uptime_kuma_api import convert_from_socket, params_map_notification_provider
|
||||
|
||||
|
||||
def deduplicate_list(l):
|
||||
out = []
|
||||
for i in l:
|
||||
if i not in out:
|
||||
out.append(i)
|
||||
return out
|
||||
|
||||
|
||||
def build_notification_providers():
|
||||
providers = []
|
||||
for path in glob.glob('uptime-kuma/server/notification-providers/*'):
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
|
||||
def build_notification_provider_conditions():
|
||||
conditions = {}
|
||||
for path in glob.glob('uptime-kuma/src/components/notifications/*'):
|
||||
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")
|
||||
inputs = soup.find_all("input")
|
||||
for input in inputs:
|
||||
condition = {}
|
||||
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
|
||||
conditions = convert_from_socket(params_map_notification_provider, conditions)
|
||||
return conditions
|
||||
|
||||
|
||||
def write_to_file(template, destination, **kwargs):
|
||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader("./"))
|
||||
template = env.get_template(template)
|
||||
rendered = template.render(**kwargs)
|
||||
with open(destination, "w") as f:
|
||||
f.write(rendered)
|
||||
|
||||
conditions = build_notification_provider_conditions()
|
||||
pprint(conditions)
|
||||
# notification_providers = build_notification_providers()
|
||||
# write_to_file("notification_providers.py.j2", "./../uptimekumaapi/notification_providers.py", notification_providers=notification_providers)
|
28
scripts/build_params_map_notification_provider.py
Normal file
28
scripts/build_params_map_notification_provider.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import re
|
||||
import os
|
||||
|
||||
from uptime_kuma_api import notification_provider_options
|
||||
|
||||
|
||||
def build_notification_provider_map():
|
||||
params_map_notification_providers = {}
|
||||
|
||||
for notification_provider in notification_provider_options:
|
||||
options = notification_provider_options[notification_provider]
|
||||
provider_name = notification_provider.__dict__["_value_"].lower().replace(".", "")
|
||||
for option in options:
|
||||
option_orig = option
|
||||
|
||||
prefix = os.path.commonprefix([o.lower() for o in options] + [provider_name])
|
||||
option = option[len(prefix):]
|
||||
|
||||
option = re.sub('([A-Z]+)', r'_\1', option).lower()
|
||||
option = provider_name + "_" + option
|
||||
option = option.replace("__", "_")
|
||||
|
||||
params_map_notification_providers[option_orig] = option
|
||||
return params_map_notification_providers
|
||||
|
||||
|
||||
notification_provider_map = build_notification_provider_map()
|
||||
print("params_map_notification_provider =", notification_provider_map)
|
21
scripts/notification_providers.py.j2
Normal file
21
scripts/notification_providers.py.j2
Normal file
|
@ -0,0 +1,21 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class NotificationType(str, Enum):
|
||||
{%- for notification_provider in notification_providers %}
|
||||
{%- set name = notification_provider["name"] %}
|
||||
{{ name.upper().replace(".", "_") }} = "{{ name }}"
|
||||
{%- 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 }}",
|
||||
{%- endfor %}
|
||||
],
|
||||
{%- endfor %}
|
||||
}
|
||||
|
1
scripts/requirenents.txt
Normal file
1
scripts/requirenents.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Jinja2==3.1.2
|
Loading…
Add table
Add a link
Reference in a new issue