Add Git health collector
This commit is contained in:
@@ -3,3 +3,6 @@
|
|||||||
config/mail-status.json
|
config/mail-status.json
|
||||||
config/mail-status.json
|
config/mail-status.json
|
||||||
telemetry/__pycache__/
|
telemetry/__pycache__/
|
||||||
|
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
REPOSITORIES = {
|
||||||
|
"infrastructure": "/opt/git/infrastructure",
|
||||||
|
"voyager": "/opt/git/voyager",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def collect():
|
||||||
|
repos = []
|
||||||
|
dirty = False
|
||||||
|
|
||||||
|
for name, path in REPOSITORIES.items():
|
||||||
|
result = subprocess.run(
|
||||||
|
["git", "-C", path, "status", "--short", "--branch"],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if result.returncode != 0:
|
||||||
|
repos.append({
|
||||||
|
"name": name,
|
||||||
|
"state": "offline",
|
||||||
|
})
|
||||||
|
dirty = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
lines = result.stdout.splitlines()
|
||||||
|
branch = lines[0].replace("## ", "")
|
||||||
|
modified = sum(1 for l in lines[1:] if not l.startswith("??"))
|
||||||
|
untracked = sum(1 for l in lines[1:] if l.startswith("??"))
|
||||||
|
|
||||||
|
state = "clean" if modified == 0 and untracked == 0 else "dirty"
|
||||||
|
|
||||||
|
if state != "clean":
|
||||||
|
dirty = True
|
||||||
|
|
||||||
|
repos.append({
|
||||||
|
"name": name,
|
||||||
|
"state": state,
|
||||||
|
"branch": branch,
|
||||||
|
"modified": modified,
|
||||||
|
"untracked": untracked,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
"state": "warning" if dirty else "online",
|
||||||
|
"summary": f"{len(repos)} repositories",
|
||||||
|
"detail": "All clean" if not dirty else "Repositories require attention",
|
||||||
|
"repositories": repos,
|
||||||
|
}
|
||||||
@@ -3,7 +3,8 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from .common import write_json
|
from .common import write_json
|
||||||
from collectors.backup import collect
|
from collectors.backup import collect as backup_collect
|
||||||
|
from collectors.git import collect as git_collect
|
||||||
|
|
||||||
OUTPUT = Path("/opt/docker/caddy/site/voyager/data/status.json")
|
OUTPUT = Path("/opt/docker/caddy/site/voyager/data/status.json")
|
||||||
|
|
||||||
@@ -11,7 +12,8 @@ OUTPUT = Path("/opt/docker/caddy/site/voyager/data/status.json")
|
|||||||
def main():
|
def main():
|
||||||
payload = {
|
payload = {
|
||||||
"systems": {
|
"systems": {
|
||||||
"backup": collect()
|
"backup": backup_collect(),
|
||||||
|
"git": git_collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user