diff --git a/collectors/__init__.py b/collectors/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/collectors/__pycache__/__init__.cpython-313.pyc b/collectors/__pycache__/__init__.cpython-313.pyc new file mode 100644 index 0000000..cfdbacd Binary files /dev/null and b/collectors/__pycache__/__init__.cpython-313.pyc differ diff --git a/collectors/__pycache__/backup.cpython-313.pyc b/collectors/__pycache__/backup.cpython-313.pyc new file mode 100644 index 0000000..b354092 Binary files /dev/null and b/collectors/__pycache__/backup.cpython-313.pyc differ diff --git a/collectors/backup.py b/collectors/backup.py new file mode 100644 index 0000000..67d777d --- /dev/null +++ b/collectors/backup.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import subprocess +import json + +RESTIC_ENV = "/etc/restic/edge01.env" + + +def collect(): + cmd = f'. "{RESTIC_ENV}" && restic snapshots --json' + + result = subprocess.run( + ["bash", "-c", cmd], + capture_output=True, + text=True, + ) + + if result.returncode != 0: + return { + "state": "offline", + "summary": "Restic error", + "detail": result.stderr.strip() + } + + snapshots = json.loads(result.stdout) + + return { + "state": "online", + "summary": "Healthy", + "detail": f"{len(snapshots)} snapshots", + "snapshot_count": len(snapshots) + } diff --git a/telemetry/collector.py b/telemetry/collector.py new file mode 100755 index 0000000..7e113bc --- /dev/null +++ b/telemetry/collector.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +from pathlib import Path + +from .common import write_json +from collectors.backup import collect + +OUTPUT = Path("/opt/docker/caddy/site/voyager/data/status.json") + + +def main(): + payload = { + "systems": { + "backup": collect() + } + } + + write_json(OUTPUT, payload) + + +if __name__ == "__main__": + main()