fix: adjust monitor status
type to allow all used values
BREAKING CHANGE: monitor `status` type changed from `bool` to `MonitorStatus`
This commit is contained in:
parent
7ef61f8ce1
commit
b87eed2597
3 changed files with 49 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
from .__version__ import __title__, __version__, __author__, __copyright__
|
||||
from .auth_method import AuthMethod
|
||||
from .monitor_status import MonitorStatus
|
||||
from .monitor_type import MonitorType
|
||||
from .notification_providers import NotificationType, notification_provider_options, notification_provider_conditions
|
||||
from .proxy_protocol import ProxyProtocol
|
||||
|
|
|
@ -18,6 +18,7 @@ from . import (AuthMethod,
|
|||
Event,
|
||||
IncidentStyle,
|
||||
MaintenanceStrategy,
|
||||
MonitorStatus,
|
||||
MonitorType,
|
||||
NotificationType,
|
||||
ProxyProtocol,
|
||||
|
@ -33,6 +34,7 @@ from .docstrings import (append_docstring,
|
|||
proxy_docstring,
|
||||
tag_docstring)
|
||||
|
||||
|
||||
def int_to_bool(data, keys) -> None:
|
||||
if isinstance(data, list):
|
||||
for d in data:
|
||||
|
@ -43,6 +45,20 @@ def int_to_bool(data, keys) -> None:
|
|||
data[key] = True if data[key] == 1 else False
|
||||
|
||||
|
||||
def parse_value(data, func) -> None:
|
||||
if isinstance(data, list):
|
||||
for d in data:
|
||||
parse_value(d, func)
|
||||
else:
|
||||
func(data)
|
||||
|
||||
|
||||
def parse_monitor_status(data) -> None:
|
||||
def parse(x):
|
||||
x["status"] = MonitorStatus(x["status"])
|
||||
parse_value(data, parse)
|
||||
|
||||
|
||||
def gen_secret(length: int) -> str:
|
||||
chars = string.ascii_uppercase + string.ascii_lowercase + string.digits
|
||||
return ''.join(random.choice(chars) for _ in range(length))
|
||||
|
@ -1123,7 +1139,7 @@ class UptimeKumaApi(object):
|
|||
'monitor_id': 1,
|
||||
'msg': '200 - OK',
|
||||
'ping': 201,
|
||||
'status': True,
|
||||
'status': <MonitorStatus.UP: 1>,
|
||||
'time': '2022-12-15 12:38:42.661'
|
||||
},
|
||||
{
|
||||
|
@ -1134,14 +1150,15 @@ class UptimeKumaApi(object):
|
|||
'monitor_id': 1,
|
||||
'msg': '200 - OK',
|
||||
'ping': 193,
|
||||
'status': True,
|
||||
'status': <MonitorStatus.UP: 1>,
|
||||
'time': '2022-12-15 12:39:42.878'
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
r = self._call('getMonitorBeats', (id_, hours))["data"]
|
||||
int_to_bool(r, ["important", "status"])
|
||||
int_to_bool(r, ["important"])
|
||||
parse_monitor_status(r)
|
||||
return r
|
||||
|
||||
def get_game_list(self) -> list[dict]:
|
||||
|
@ -1945,7 +1962,7 @@ class UptimeKumaApi(object):
|
|||
'monitor_id': 1,
|
||||
'msg': 'connect ECONNREFUSED 127.0.0.1:80',
|
||||
'ping': None,
|
||||
'status': False,
|
||||
'status': <MonitorStatus.DOWN: 0>,
|
||||
'time': '2022-12-15 16:51:41.782'
|
||||
},
|
||||
{
|
||||
|
@ -1956,7 +1973,7 @@ class UptimeKumaApi(object):
|
|||
'monitor_id': 1,
|
||||
'msg': 'connect ECONNREFUSED 127.0.0.1:80',
|
||||
'ping': None,
|
||||
'status': False,
|
||||
'status': <MonitorStatus.DOWN: 0>,
|
||||
'time': '2022-12-15 16:52:41.799'
|
||||
},
|
||||
...
|
||||
|
@ -1967,7 +1984,8 @@ class UptimeKumaApi(object):
|
|||
"""
|
||||
r = self._get_event_data(Event.HEARTBEAT_LIST)
|
||||
for i in r:
|
||||
int_to_bool(i["data"], ["important", "status"])
|
||||
int_to_bool(i["data"], ["important"])
|
||||
parse_monitor_status(i["data"])
|
||||
return r
|
||||
|
||||
def get_important_heartbeats(self) -> list[dict]:
|
||||
|
@ -1990,7 +2008,7 @@ class UptimeKumaApi(object):
|
|||
'monitorID': 1,
|
||||
'msg': 'connect ECONNREFUSED 127.0.0.1:80',
|
||||
'ping': None,
|
||||
'status': False,
|
||||
'status': <MonitorStatus.DOWN: 0>,
|
||||
'time': '2022-12-15 16:51:41.782'
|
||||
}
|
||||
],
|
||||
|
@ -2000,7 +2018,8 @@ class UptimeKumaApi(object):
|
|||
"""
|
||||
r = self._get_event_data(Event.IMPORTANT_HEARTBEAT_LIST)
|
||||
for i in r:
|
||||
int_to_bool(i["data"], ["important", "status"])
|
||||
int_to_bool(i["data"], ["important"])
|
||||
parse_monitor_status(i["data"])
|
||||
return r
|
||||
|
||||
def get_heartbeat(self) -> list[dict]:
|
||||
|
@ -2019,13 +2038,14 @@ class UptimeKumaApi(object):
|
|||
'important': False,
|
||||
'monitorID': 1,
|
||||
'msg': 'connect ECONNREFUSED 127.0.0.1:80',
|
||||
'status': False,
|
||||
'status': <MonitorStatus.DOWN: 0>,
|
||||
'time': '2022-12-15 17:17:42.099'
|
||||
}
|
||||
]
|
||||
"""
|
||||
r = self._get_event_data(Event.HEARTBEAT)
|
||||
int_to_bool(r, ["important", "status"])
|
||||
int_to_bool(r, ["important"])
|
||||
parse_monitor_status(r)
|
||||
return r
|
||||
|
||||
# avg ping
|
||||
|
|
17
uptime_kuma_api/monitor_status.py
Normal file
17
uptime_kuma_api/monitor_status.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class MonitorStatus(int, Enum):
|
||||
"""Enumerate monitor statuses."""
|
||||
|
||||
DOWN = 0
|
||||
"""DOWN"""
|
||||
|
||||
UP = 1
|
||||
"""UP"""
|
||||
|
||||
PENDING = 2
|
||||
"""PENDING"""
|
||||
|
||||
MAINTENANCE = 3
|
||||
"""MAINTENANCE"""
|
Loading…
Reference in a new issue