Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pythonkuma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
UptimeKumaConnectionException,
UptimeKumaException,
)
from .models import MonitorStatus, MonitorType, UptimeKumaMonitor
from .models import MonitorStatus, MonitorType, UptimeKumaMonitor, UptimeKumaVersion
from .uptimekuma import UptimeKuma

__version__ = "0.1.0"
Expand All @@ -18,4 +18,5 @@
"UptimeKumaConnectionException",
"UptimeKumaException",
"UptimeKumaMonitor",
"UptimeKumaVersion",
]
10 changes: 10 additions & 0 deletions pythonkuma/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,13 @@ class UptimeKumaMonitor(UptimeKumaBaseModel):
monitor_url: str | None = field(
metadata={"deserialize": lambda v: None if v == "null" else v}
)


@dataclass
class UptimeKumaVersion(UptimeKumaBaseModel):
"""Uptime Kuma version."""

version: str = ""
major: str = ""
minor: str = ""
patch: str = ""
6 changes: 5 additions & 1 deletion pythonkuma/uptimekuma.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from yarl import URL

from .exceptions import UptimeKumaAuthenticationException, UptimeKumaConnectionException
from .models import UptimeKumaMonitor
from .models import UptimeKumaMonitor, UptimeKumaVersion


class UptimeKuma:
Expand Down Expand Up @@ -47,6 +47,8 @@ def __init__(
self._timeout = ClientTimeout(total=timeout or 10)
self._session = session

self.version = UptimeKumaVersion()

async def metrics(self) -> dict[str, UptimeKumaMonitor]:
"""Retrieve metrics from Uptime Kuma.

Expand Down Expand Up @@ -89,6 +91,8 @@ async def metrics(self) -> dict[str, UptimeKumaMonitor]:
raise UptimeKumaConnectionException from e
else:
for metric in text_string_to_metric_families(await request.text()):
if metric.name == "app_version" and metric.samples:
self.version = UptimeKumaVersion.from_dict(metric.samples[0].labels)
if not metric.name.startswith("monitor"):
continue
for sample in metric.samples:
Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ indent-style = "space"

[lint]
select = ["ALL"]
ignore = ["TRY003", "COM812", "N818"]
ignore = ["TRY003", "COM812", "N818", "C901"]

[lint.per-file-ignores]
"**/scripts/*" = [
Expand Down
Loading