pythonkuma 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pythonkuma-0.1.0 → pythonkuma-0.2.0}/PKG-INFO +4 -1
- {pythonkuma-0.1.0 → pythonkuma-0.2.0}/pyproject.toml +8 -1
- {pythonkuma-0.1.0 → pythonkuma-0.2.0}/pythonkuma/__init__.py +3 -2
- {pythonkuma-0.1.0 → pythonkuma-0.2.0}/pythonkuma/models.py +16 -2
- {pythonkuma-0.1.0 → pythonkuma-0.2.0}/pythonkuma/uptimekuma.py +47 -11
- {pythonkuma-0.1.0 → pythonkuma-0.2.0}/.gitignore +0 -0
- {pythonkuma-0.1.0 → pythonkuma-0.2.0}/LICENSE +0 -0
- {pythonkuma-0.1.0 → pythonkuma-0.2.0}/README.md +0 -0
- {pythonkuma-0.1.0 → pythonkuma-0.2.0}/pythonkuma/exceptions.py +0 -0
- {pythonkuma-0.1.0 → pythonkuma-0.2.0}/pythonkuma/py.typed +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pythonkuma
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Simple Python wrapper for Uptime Kuma
|
|
5
5
|
Project-URL: Source, https://github.com/tr4nt0r/pythonkuma
|
|
6
|
+
Project-URL: Documentation, https://tr4nt0r.github.io/pythonkuma
|
|
6
7
|
Author-email: Manfred Dennerlein Rodelo <manfred@dennerlein.name>, Jayakorn Karikan <jayakornk@gmail.com>
|
|
7
8
|
License-Expression: MIT
|
|
8
9
|
License-File: LICENSE
|
|
@@ -15,6 +16,8 @@ Requires-Dist: prometheus-client>=0.21.0
|
|
|
15
16
|
Provides-Extra: dev
|
|
16
17
|
Requires-Dist: aiohttp==3.12.12; extra == 'dev'
|
|
17
18
|
Requires-Dist: mashumaro==3.16; extra == 'dev'
|
|
19
|
+
Requires-Dist: mkdocs-material==9.6.14; extra == 'dev'
|
|
20
|
+
Requires-Dist: mkdocstrings[python]==0.29.1; extra == 'dev'
|
|
18
21
|
Requires-Dist: prometheus-client==0.22.1; extra == 'dev'
|
|
19
22
|
Requires-Dist: ruff==0.11.13; extra == 'dev'
|
|
20
23
|
Description-Content-Type: text/markdown
|
|
@@ -29,10 +29,13 @@ dev = [
|
|
|
29
29
|
"aiohttp==3.12.12",
|
|
30
30
|
"prometheus-client==0.22.1",
|
|
31
31
|
"mashumaro==3.16",
|
|
32
|
+
"mkdocs-material==9.6.14",
|
|
33
|
+
"mkdocstrings[python]==0.29.1",
|
|
32
34
|
]
|
|
33
35
|
|
|
34
36
|
[project.urls]
|
|
35
37
|
Source = "https://github.com/tr4nt0r/pythonkuma"
|
|
38
|
+
Documentation = "https://tr4nt0r.github.io/pythonkuma"
|
|
36
39
|
|
|
37
40
|
[tool.hatch.version]
|
|
38
41
|
source = "regex_commit"
|
|
@@ -66,4 +69,8 @@ pythonpath = ["pythonkuma"]
|
|
|
66
69
|
extra-dependencies = [
|
|
67
70
|
"pythonkuma[dev]",
|
|
68
71
|
"pytest-cov==6.1.1",
|
|
69
|
-
]
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[tool.hatch.envs.default.scripts]
|
|
75
|
+
docs-serve = "mkdocs serve"
|
|
76
|
+
docs-build = "mkdocs build"
|
|
@@ -5,10 +5,10 @@ from .exceptions import (
|
|
|
5
5
|
UptimeKumaConnectionException,
|
|
6
6
|
UptimeKumaException,
|
|
7
7
|
)
|
|
8
|
-
from .models import MonitorStatus, MonitorType, UptimeKumaMonitor
|
|
8
|
+
from .models import MonitorStatus, MonitorType, UptimeKumaMonitor, UptimeKumaVersion
|
|
9
9
|
from .uptimekuma import UptimeKuma
|
|
10
10
|
|
|
11
|
-
__version__ = "0.
|
|
11
|
+
__version__ = "0.2.0"
|
|
12
12
|
|
|
13
13
|
__all__ = [
|
|
14
14
|
"MonitorStatus",
|
|
@@ -18,4 +18,5 @@ __all__ = [
|
|
|
18
18
|
"UptimeKumaConnectionException",
|
|
19
19
|
"UptimeKumaException",
|
|
20
20
|
"UptimeKumaMonitor",
|
|
21
|
+
"UptimeKumaVersion",
|
|
21
22
|
]
|
|
@@ -43,6 +43,9 @@ class MonitorType(StrEnum):
|
|
|
43
43
|
RADIUS = "radius"
|
|
44
44
|
REDIS = "redis"
|
|
45
45
|
TAILSCALE_PING = "tailscale-ping"
|
|
46
|
+
SMTP = "smtp"
|
|
47
|
+
SNMP = "snmp"
|
|
48
|
+
RABBIT_MQ = "rabbitmq"
|
|
46
49
|
UNKNOWN = "unknown"
|
|
47
50
|
|
|
48
51
|
@classmethod
|
|
@@ -60,8 +63,9 @@ class UptimeKumaBaseModel(DataClassDictMixin):
|
|
|
60
63
|
class UptimeKumaMonitor(UptimeKumaBaseModel):
|
|
61
64
|
"""Monitor model for Uptime Kuma."""
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
monitor_id: int | None = None
|
|
67
|
+
monitor_cert_days_remaining: int | None = None
|
|
68
|
+
monitor_cert_is_valid: bool | None = None
|
|
65
69
|
monitor_hostname: str | None = field(
|
|
66
70
|
metadata={"deserialize": lambda v: None if v == "null" else v}
|
|
67
71
|
)
|
|
@@ -75,3 +79,13 @@ class UptimeKumaMonitor(UptimeKumaBaseModel):
|
|
|
75
79
|
monitor_url: str | None = field(
|
|
76
80
|
metadata={"deserialize": lambda v: None if v == "null" else v}
|
|
77
81
|
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@dataclass
|
|
85
|
+
class UptimeKumaVersion(UptimeKumaBaseModel):
|
|
86
|
+
"""Uptime Kuma version."""
|
|
87
|
+
|
|
88
|
+
version: str = ""
|
|
89
|
+
major: str = ""
|
|
90
|
+
minor: str = ""
|
|
91
|
+
patch: str = ""
|
|
@@ -14,7 +14,7 @@ from prometheus_client.parser import text_string_to_metric_families
|
|
|
14
14
|
from yarl import URL
|
|
15
15
|
|
|
16
16
|
from .exceptions import UptimeKumaAuthenticationException, UptimeKumaConnectionException
|
|
17
|
-
from .models import UptimeKumaMonitor
|
|
17
|
+
from .models import UptimeKumaMonitor, UptimeKumaVersion
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class UptimeKuma:
|
|
@@ -27,7 +27,19 @@ class UptimeKuma:
|
|
|
27
27
|
api_key: str | None = None,
|
|
28
28
|
timeout: float | None = None,
|
|
29
29
|
) -> None:
|
|
30
|
-
"""Initialize the Uptime Kuma client.
|
|
30
|
+
"""Initialize the Uptime Kuma client.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
session : ClientSession
|
|
35
|
+
An aiohttp ClientSession instance
|
|
36
|
+
base_url : URL or str
|
|
37
|
+
The base URL of the Uptime Kuma server
|
|
38
|
+
api_key : str or None, optional
|
|
39
|
+
API key for authentication (default is None).
|
|
40
|
+
timeout : float or None, optional
|
|
41
|
+
Request timeout in seconds (default is 10 seconds if not specified).
|
|
42
|
+
"""
|
|
31
43
|
self._base_url = base_url if isinstance(base_url, URL) else URL(base_url)
|
|
32
44
|
|
|
33
45
|
self._auth = BasicAuth("", api_key) if api_key else None
|
|
@@ -35,8 +47,30 @@ class UptimeKuma:
|
|
|
35
47
|
self._timeout = ClientTimeout(total=timeout or 10)
|
|
36
48
|
self._session = session
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
self.version = UptimeKumaVersion()
|
|
51
|
+
|
|
52
|
+
async def metrics(self) -> dict[str | int, UptimeKumaMonitor]:
|
|
53
|
+
"""Retrieve metrics from Uptime Kuma.
|
|
54
|
+
|
|
55
|
+
Fetches and parses Prometheus-style metrics from the Uptime Kuma API endpoint,
|
|
56
|
+
extracting monitor-related metrics and returning them as a dictionary of
|
|
57
|
+
UptimeKumaMonitor objects keyed by monitor name.
|
|
58
|
+
|
|
59
|
+
Returns
|
|
60
|
+
-------
|
|
61
|
+
dict[str, UptimeKumaMonitor]
|
|
62
|
+
A dictionary mapping monitor names to their corresponding UptimeKumaMonitor
|
|
63
|
+
objects.
|
|
64
|
+
|
|
65
|
+
Raises
|
|
66
|
+
------
|
|
67
|
+
UptimeKumaAuthenticationException
|
|
68
|
+
If authentication with the Uptime Kuma API fails.
|
|
69
|
+
UptimeKumaConnectionException
|
|
70
|
+
If there is a connection error, timeout, or other client error during the
|
|
71
|
+
request.
|
|
72
|
+
"""
|
|
73
|
+
monitors: dict[str | int, dict[str, Any]] = {}
|
|
40
74
|
url = self._base_url / "metrics"
|
|
41
75
|
|
|
42
76
|
try:
|
|
@@ -56,17 +90,19 @@ class UptimeKuma:
|
|
|
56
90
|
except ClientError as e:
|
|
57
91
|
raise UptimeKumaConnectionException from e
|
|
58
92
|
else:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
for metric in parsed:
|
|
93
|
+
for metric in text_string_to_metric_families(await request.text()):
|
|
94
|
+
if metric.name == "app_version" and metric.samples:
|
|
95
|
+
self.version = UptimeKumaVersion.from_dict(metric.samples[0].labels)
|
|
63
96
|
if not metric.name.startswith("monitor"):
|
|
64
97
|
continue
|
|
65
98
|
for sample in metric.samples:
|
|
66
|
-
|
|
67
|
-
|
|
99
|
+
key = (
|
|
100
|
+
int(monitor_id)
|
|
101
|
+
if (monitor_id := sample.labels.get("monitor_id"))
|
|
102
|
+
else sample.labels["monitor_name"]
|
|
103
|
+
)
|
|
68
104
|
|
|
69
|
-
monitors.setdefault(
|
|
105
|
+
monitors.setdefault(key, sample.labels).update(
|
|
70
106
|
{sample.name: sample.value}
|
|
71
107
|
)
|
|
72
108
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|