Skip to content

Commit 17e888d

Browse files
committed
Parse and store version from metrics
1 parent 81762b8 commit 17e888d

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

pythonkuma/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
UptimeKumaConnectionException,
66
UptimeKumaException,
77
)
8-
from .models import MonitorStatus, MonitorType, UptimeKumaMonitor
8+
from .models import MonitorStatus, MonitorType, UptimeKumaMonitor, UptimeKumaVersion
99
from .uptimekuma import UptimeKuma
1010

1111
__version__ = "0.1.0"
@@ -18,4 +18,5 @@
1818
"UptimeKumaConnectionException",
1919
"UptimeKumaException",
2020
"UptimeKumaMonitor",
21+
"UptimeKumaVersion",
2122
]

pythonkuma/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,13 @@ class UptimeKumaMonitor(UptimeKumaBaseModel):
7575
monitor_url: str | None = field(
7676
metadata={"deserialize": lambda v: None if v == "null" else v}
7777
)
78+
79+
80+
@dataclass
81+
class UptimeKumaVersion(UptimeKumaBaseModel):
82+
"""Uptime Kuma version."""
83+
84+
version: str = ""
85+
major: str = ""
86+
minor: str = ""
87+
patch: str = ""

pythonkuma/uptimekuma.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from yarl import URL
1515

1616
from .exceptions import UptimeKumaAuthenticationException, UptimeKumaConnectionException
17-
from .models import UptimeKumaMonitor
17+
from .models import UptimeKumaMonitor, UptimeKumaVersion
1818

1919

2020
class UptimeKuma:
@@ -47,6 +47,8 @@ def __init__(
4747
self._timeout = ClientTimeout(total=timeout or 10)
4848
self._session = session
4949

50+
self.version = UptimeKumaVersion()
51+
5052
async def metrics(self) -> dict[str, UptimeKumaMonitor]:
5153
"""Retrieve metrics from Uptime Kuma.
5254
@@ -89,6 +91,8 @@ async def metrics(self) -> dict[str, UptimeKumaMonitor]:
8991
raise UptimeKumaConnectionException from e
9092
else:
9193
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)
9296
if not metric.name.startswith("monitor"):
9397
continue
9498
for sample in metric.samples:

ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ indent-style = "space"
88

99
[lint]
1010
select = ["ALL"]
11-
ignore = ["TRY003", "COM812", "N818"]
11+
ignore = ["TRY003", "COM812", "N818", "C901"]
1212

1313
[lint.per-file-ignores]
1414
"**/scripts/*" = [

0 commit comments

Comments
 (0)