mirror of
https://github.com/hansjone/netx.git
synced 2026-10-09 04:20:45 +08:00
Show UME sync delete counts in API and UME UI
Parse UmeSyncJob.details_json in GET /v1/ume/sync/status for deleted_inventory_ne, deleted_inventory_holders, deleted_stale_current_alarms. Add table columns on UmePage and types. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
340fc8ee7d
commit
a025245c8f
3 changed files with 43 additions and 1 deletions
|
|
@ -496,6 +496,33 @@ def ume_sync(payload: dict[str, Any] | None = None, db: Session = Depends(get_db
|
|||
return out
|
||||
|
||||
|
||||
def _ume_sync_job_details_counts(row: UmeSyncJob) -> dict[str, int]:
|
||||
"""Parse ``details_json`` from sync jobs (inventory / alarms) for delete-reconcile stats."""
|
||||
out = {"deleted_inventory_ne": 0, "deleted_inventory_holders": 0, "deleted_current_alarms": 0}
|
||||
raw = str(getattr(row, "details_json", "") or "").strip()
|
||||
if not raw:
|
||||
return out
|
||||
try:
|
||||
obj = json.loads(raw)
|
||||
except Exception:
|
||||
return out
|
||||
if not isinstance(obj, dict):
|
||||
return out
|
||||
try:
|
||||
out["deleted_inventory_ne"] = max(0, int(obj.get("deleted_inventory_ne") or 0))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
out["deleted_inventory_holders"] = max(0, int(obj.get("deleted_inventory_holders") or 0))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
out["deleted_current_alarms"] = max(0, int(obj.get("deleted_stale_current_alarms") or 0))
|
||||
except Exception:
|
||||
pass
|
||||
return out
|
||||
|
||||
|
||||
@app.get("/v1/ume/sync/status")
|
||||
def ume_sync_status(
|
||||
page: int = Query(default=1, ge=1),
|
||||
|
|
@ -513,6 +540,7 @@ def ume_sync_status(
|
|||
items = []
|
||||
latest_by_domain: dict[str, dict[str, Any]] = {}
|
||||
for r in rows:
|
||||
del_counts = _ume_sync_job_details_counts(r)
|
||||
item = {
|
||||
"id": int(r.id),
|
||||
"domain": str(r.domain or ""),
|
||||
|
|
@ -521,6 +549,9 @@ def ume_sync_status(
|
|||
"pulled_count": int(r.pulled_count or 0),
|
||||
"inserted_count": int(r.inserted_count or 0),
|
||||
"updated_count": int(r.updated_count or 0),
|
||||
"deleted_inventory_ne": int(del_counts["deleted_inventory_ne"]),
|
||||
"deleted_inventory_holders": int(del_counts["deleted_inventory_holders"]),
|
||||
"deleted_current_alarms": int(del_counts["deleted_current_alarms"]),
|
||||
"error_message": str(r.error_message or ""),
|
||||
"started_at": (_ensure_utc(r.started_at) or datetime.now(timezone.utc)).isoformat(),
|
||||
"ended_at": (_ensure_utc(r.ended_at).isoformat() if r.ended_at else None),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue