diff --git a/pythonkuma/__init__.py b/pythonkuma/__init__.py index 1a8826f..ab3a319 100644 --- a/pythonkuma/__init__.py +++ b/pythonkuma/__init__.py @@ -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" @@ -18,4 +18,5 @@ "UptimeKumaConnectionException", "UptimeKumaException", "UptimeKumaMonitor", + "UptimeKumaVersion", ] diff --git a/pythonkuma/models.py b/pythonkuma/models.py index e335c8e..3e15cb0 100644 --- a/pythonkuma/models.py +++ b/pythonkuma/models.py @@ -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 = "" diff --git a/pythonkuma/uptimekuma.py b/pythonkuma/uptimekuma.py index 9d99dc7..1464170 100644 --- a/pythonkuma/uptimekuma.py +++ b/pythonkuma/uptimekuma.py @@ -14,7 +14,7 @@ from yarl import URL from .exceptions import UptimeKumaAuthenticationException, UptimeKumaConnectionException -from .models import UptimeKumaMonitor +from .models import UptimeKumaMonitor, UptimeKumaVersion class UptimeKuma: @@ -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. @@ -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: diff --git a/ruff.toml b/ruff.toml index 6519b7c..a5f315f 100644 --- a/ruff.toml +++ b/ruff.toml @@ -8,7 +8,7 @@ indent-style = "space" [lint] select = ["ALL"] -ignore = ["TRY003", "COM812", "N818"] +ignore = ["TRY003", "COM812", "N818", "C901"] [lint.per-file-ignores] "**/scripts/*" = [