apps/dashboard/backend/app/clients/backrest_client.py aktualisiert
This commit is contained in:
@@ -7,7 +7,6 @@ from app.clients.base import BaseHTTPClient
|
|||||||
from app.config import Settings
|
from app.config import Settings
|
||||||
from app.models.sources import BackrestSnapshot
|
from app.models.sources import BackrestSnapshot
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -21,10 +20,11 @@ class BackrestClient(BaseHTTPClient):
|
|||||||
logger.info("backrest skipped: base URL missing")
|
logger.info("backrest skipped: base URL missing")
|
||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
|
# Backrest uses Connect-RPC: POST /v1.Backrest/{Method}
|
||||||
try:
|
try:
|
||||||
data = await self._request_json("GET", "/v1/config")
|
data = await self._request_json("POST", "/v1.Backrest/GetConfig", json={})
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning("backrest fetch_status /v1/config failed: %s", exc)
|
logger.warning("backrest fetch_status GetConfig failed: %s", exc)
|
||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
if not isinstance(data, dict):
|
if not isinstance(data, dict):
|
||||||
@@ -33,20 +33,22 @@ class BackrestClient(BaseHTTPClient):
|
|||||||
repos = data.get("repos") or []
|
repos = data.get("repos") or []
|
||||||
repo_count = len(repos) if isinstance(repos, list) else 0
|
repo_count = len(repos) if isinstance(repos, list) else 0
|
||||||
|
|
||||||
# Fetch operation log for recent backup status
|
# Fetch recent operations for backup status
|
||||||
last_backup_age_hours: float | None = None
|
last_backup_age_hours: float | None = None
|
||||||
error_count = 0
|
error_count = 0
|
||||||
last_backup_status = "unknown"
|
last_backup_status = "unknown"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ops_data = await self._request_json(
|
ops_data = await self._request_json(
|
||||||
"POST", "/v1/operations",
|
"POST",
|
||||||
json={"last_n": 20},
|
"/v1.Backrest/GetOperations",
|
||||||
|
json={"lastN": 20},
|
||||||
)
|
)
|
||||||
ops = ops_data.get("operations") or [] if isinstance(ops_data, dict) else []
|
ops = ops_data.get("operations") or [] if isinstance(ops_data, dict) else []
|
||||||
|
# backupOp is a oneof field serialised directly at the operation level in proto3 JSON
|
||||||
backup_ops = [
|
backup_ops = [
|
||||||
op for op in ops
|
op for op in ops
|
||||||
if isinstance(op, dict) and op.get("op", {}).get("backupOp") is not None
|
if isinstance(op, dict) and op.get("backupOp") is not None
|
||||||
]
|
]
|
||||||
error_ops = [op for op in backup_ops if op.get("status") == "STATUS_ERROR"]
|
error_ops = [op for op in backup_ops if op.get("status") == "STATUS_ERROR"]
|
||||||
error_count = len(error_ops)
|
error_count = len(error_ops)
|
||||||
@@ -59,10 +61,13 @@ class BackrestClient(BaseHTTPClient):
|
|||||||
now = datetime.now(timezone.utc)
|
now = datetime.now(timezone.utc)
|
||||||
last_backup_age_hours = round((now - ended).total_seconds() / 3600, 1)
|
last_backup_age_hours = round((now - ended).total_seconds() / 3600, 1)
|
||||||
status_str = latest.get("status", "")
|
status_str = latest.get("status", "")
|
||||||
last_backup_status = "ok" if status_str == "STATUS_SUCCESS" else "error" if status_str == "STATUS_ERROR" else "unknown"
|
last_backup_status = (
|
||||||
|
"ok" if status_str == "STATUS_SUCCESS"
|
||||||
|
else "error" if status_str == "STATUS_ERROR"
|
||||||
|
else "unknown"
|
||||||
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning("backrest fetch_status /v1/operations failed: %s", exc)
|
logger.warning("backrest fetch_status GetOperations failed: %s", exc)
|
||||||
|
|
||||||
return BackrestSnapshot(
|
return BackrestSnapshot(
|
||||||
source_status="online",
|
source_status="online",
|
||||||
|
|||||||
Reference in New Issue
Block a user