improve status page
This commit is contained in:
parent
27cf6bea97
commit
cead17df9d
3 changed files with 82 additions and 50 deletions
|
@ -3,5 +3,6 @@ from .monitor_type import MonitorType
|
||||||
from .notification_providers import NotificationType, notification_provider_options
|
from .notification_providers import NotificationType, notification_provider_options
|
||||||
from .proxy_protocol import ProxyProtocol
|
from .proxy_protocol import ProxyProtocol
|
||||||
from .incident_style import IncidentStyle
|
from .incident_style import IncidentStyle
|
||||||
from .converter import convert_from_socket, convert_to_socket, params_map_monitor, params_map_notification, params_map_proxy
|
from .converter import convert_from_socket, convert_to_socket, params_map_monitor, params_map_notification, \
|
||||||
|
params_map_proxy, params_map_status_page
|
||||||
from .api import UptimeKumaApi
|
from .api import UptimeKumaApi
|
||||||
|
|
|
@ -8,7 +8,7 @@ from . import MonitorType
|
||||||
from . import NotificationType, notification_provider_options
|
from . import NotificationType, notification_provider_options
|
||||||
from . import ProxyProtocol
|
from . import ProxyProtocol
|
||||||
from . import IncidentStyle
|
from . import IncidentStyle
|
||||||
from . import convert_from_socket, convert_to_socket, params_map_monitor, params_map_notification, params_map_proxy
|
from . import convert_from_socket, convert_to_socket, params_map_monitor, params_map_notification, params_map_proxy, params_map_status_page
|
||||||
|
|
||||||
|
|
||||||
def int_to_bool(data: list[dict] | dict, keys):
|
def int_to_bool(data: list[dict] | dict, keys):
|
||||||
|
@ -197,6 +197,49 @@ def _build_proxy_data(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _build_status_page_data(
|
||||||
|
slug: str,
|
||||||
|
|
||||||
|
# config
|
||||||
|
id_: int,
|
||||||
|
title: str,
|
||||||
|
description: str = None,
|
||||||
|
dark_theme: bool = False,
|
||||||
|
published: bool = True,
|
||||||
|
show_tags: bool = False,
|
||||||
|
domain_name_list: list[str] = None,
|
||||||
|
custom_css: str = "",
|
||||||
|
footer_text: str = None,
|
||||||
|
show_powered_by: bool = True,
|
||||||
|
|
||||||
|
img_data_url: str = "/icon.svg",
|
||||||
|
monitors: list = None
|
||||||
|
):
|
||||||
|
if not domain_name_list:
|
||||||
|
domain_name_list = []
|
||||||
|
public_group_list = []
|
||||||
|
if monitors:
|
||||||
|
public_group_list.append({
|
||||||
|
"name": "Services",
|
||||||
|
"monitorList": monitors
|
||||||
|
})
|
||||||
|
config = {
|
||||||
|
"id": id_,
|
||||||
|
"slug": slug,
|
||||||
|
"title": title,
|
||||||
|
"description": description,
|
||||||
|
"icon": img_data_url,
|
||||||
|
"theme": "dark" if dark_theme else "light",
|
||||||
|
"published": published,
|
||||||
|
"showTags": show_tags,
|
||||||
|
"domainNameList": domain_name_list,
|
||||||
|
"customCSS": custom_css,
|
||||||
|
"footerText": footer_text,
|
||||||
|
"showPoweredBy": show_powered_by
|
||||||
|
}
|
||||||
|
return slug, config, img_data_url, public_group_list
|
||||||
|
|
||||||
|
|
||||||
class UptimeKumaApi(object):
|
class UptimeKumaApi(object):
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
self.sio = socketio.Client()
|
self.sio = socketio.Client()
|
||||||
|
@ -430,62 +473,31 @@ class UptimeKumaApi(object):
|
||||||
return list(self._get_event_data("statusPageList").values())
|
return list(self._get_event_data("statusPageList").values())
|
||||||
|
|
||||||
def get_status_page(self, slug: str):
|
def get_status_page(self, slug: str):
|
||||||
return self.sio.call('getStatusPage', slug)
|
r = self.sio.call('getStatusPage', slug)
|
||||||
|
if r["ok"]:
|
||||||
|
config = r["config"]
|
||||||
|
del r["config"]
|
||||||
|
r.update(config)
|
||||||
|
return r
|
||||||
|
|
||||||
def add_status_page(self, title: str, slug: str):
|
def add_status_page(self, slug: str, title: str):
|
||||||
return self.sio.call('addStatusPage', (title, slug))
|
return self.sio.call('addStatusPage', (title, slug))
|
||||||
|
|
||||||
def delete_status_page(self, slug: str):
|
def delete_status_page(self, slug: str):
|
||||||
return self.sio.call('deleteStatusPage', slug)
|
return self.sio.call('deleteStatusPage', slug)
|
||||||
|
|
||||||
def save_status_page(
|
def save_status_page(self, slug: str, **kwargs):
|
||||||
self,
|
status_page = self.get_status_page(slug)
|
||||||
slug: str,
|
status_page.pop("ok")
|
||||||
|
kwargs_sock = convert_to_socket(params_map_status_page, kwargs)
|
||||||
# config
|
status_page.update(kwargs_sock)
|
||||||
id_: int,
|
status_page = convert_from_socket(params_map_status_page, status_page)
|
||||||
title: str,
|
data = _build_status_page_data(**status_page)
|
||||||
description: str = None,
|
return self.sio.call('saveStatusPage', data)
|
||||||
dark_theme: bool = False,
|
|
||||||
published: bool = True,
|
|
||||||
show_tags: bool = False,
|
|
||||||
domain_name_list: list[str] = None,
|
|
||||||
custom_css: str = "",
|
|
||||||
footer_text: str = None,
|
|
||||||
show_powered_by: bool = True,
|
|
||||||
|
|
||||||
img_data_url: str = "/icon.svg",
|
|
||||||
monitors: list = None
|
|
||||||
):
|
|
||||||
if not domain_name_list:
|
|
||||||
domain_name_list = []
|
|
||||||
public_group_list = []
|
|
||||||
if monitors:
|
|
||||||
public_group_list.append({
|
|
||||||
"name": "Services",
|
|
||||||
"monitorList": monitors
|
|
||||||
})
|
|
||||||
config = {
|
|
||||||
"id": id_,
|
|
||||||
"slug": slug,
|
|
||||||
"title": title,
|
|
||||||
"description": description,
|
|
||||||
"icon": img_data_url,
|
|
||||||
"theme": "dark" if dark_theme else "light",
|
|
||||||
"published": published,
|
|
||||||
"showTags": show_tags,
|
|
||||||
"domainNameList": domain_name_list,
|
|
||||||
"customCSS": custom_css,
|
|
||||||
"footerText": footer_text,
|
|
||||||
"showPoweredBy": show_powered_by
|
|
||||||
}
|
|
||||||
return self.sio.call('saveStatusPage', (slug, config, img_data_url, public_group_list))
|
|
||||||
|
|
||||||
def post_incident(
|
def post_incident(
|
||||||
self,
|
self,
|
||||||
slug: str,
|
slug: str,
|
||||||
|
|
||||||
# incident
|
|
||||||
title: str,
|
title: str,
|
||||||
content: str,
|
content: str,
|
||||||
style: IncidentStyle = IncidentStyle.PRIMARY
|
style: IncidentStyle = IncidentStyle.PRIMARY
|
||||||
|
@ -495,10 +507,14 @@ class UptimeKumaApi(object):
|
||||||
"content": content,
|
"content": content,
|
||||||
"style": style
|
"style": style
|
||||||
}
|
}
|
||||||
return self.sio.call('postIncident', (slug, incident))
|
r = self.sio.call('postIncident', (slug, incident))
|
||||||
|
self.save_status_page(slug)
|
||||||
|
return r
|
||||||
|
|
||||||
def unpin_incident(self, slug: str):
|
def unpin_incident(self, slug: str):
|
||||||
return self.sio.call('unpinIncident', slug)
|
r = self.sio.call('unpinIncident', slug)
|
||||||
|
self.save_status_page(slug)
|
||||||
|
return r
|
||||||
|
|
||||||
# heartbeat
|
# heartbeat
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,21 @@ params_map_proxy = {
|
||||||
"applyExisting": "apply_existing"
|
"applyExisting": "apply_existing"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params_map_status_page = {
|
||||||
|
"id": "id_",
|
||||||
|
"slug": "slug",
|
||||||
|
"title": "title",
|
||||||
|
"description": "description",
|
||||||
|
"icon": "img_data_url",
|
||||||
|
"theme": "dark_theme",
|
||||||
|
"published": "published",
|
||||||
|
"showTags": "show_tags",
|
||||||
|
"domainNameList": "domain_name_list",
|
||||||
|
"customCSS": "custom_css",
|
||||||
|
"footerText": "footer_text",
|
||||||
|
"showPoweredBy": "show_powered_by"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _convert_to_from_socket(params_map: dict[str, str], params: list[dict] | dict, to_socket=False):
|
def _convert_to_from_socket(params_map: dict[str, str], params: list[dict] | dict, to_socket=False):
|
||||||
if type(params) == list:
|
if type(params) == list:
|
||||||
|
|
Loading…
Reference in a new issue