Add initial Restic backup telemetry collector
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -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)
|
||||||
|
}
|
||||||
Executable
+22
@@ -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()
|
||||||
Reference in New Issue
Block a user