fix: align with v13 OpenAPI spec — jobTypeFilter, protection groups, alarms resiliency
- fetch_backups(): typeFilter → jobTypeFilter (spec parameter name fix) - fetch_protection_groups(): new method via /api/v1/agents/protectionGroups (spec-recommended replacement for deprecated protectedComputers) - fetch_alarms(): wrap in try/except — endpoint not in v13 spec, may 404 - _collect_instance(): fetch and expose protection_groups in response
This commit is contained in:
8
main.py
8
main.py
@@ -189,6 +189,12 @@ async def _collect_instance(inst) -> dict | None:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
errors.append(f"agents: {e}")
|
errors.append(f"agents: {e}")
|
||||||
|
|
||||||
|
protection_groups = []
|
||||||
|
try:
|
||||||
|
protection_groups = await client.fetch_protection_groups()
|
||||||
|
except Exception as e:
|
||||||
|
errors.append(f"protection groups: {e}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
agent_policies = await client.fetch_agent_policies()
|
agent_policies = await client.fetch_agent_policies()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -297,6 +303,7 @@ async def _collect_instance(inst) -> dict | None:
|
|||||||
"alarms": alarms_data,
|
"alarms": alarms_data,
|
||||||
"agents": agents_data,
|
"agents": agents_data,
|
||||||
"agent_policies": agent_policies,
|
"agent_policies": agent_policies,
|
||||||
|
"protection_groups": protection_groups,
|
||||||
"restore_points": restore_points[:50] if restore_points else [],
|
"restore_points": restore_points[:50] if restore_points else [],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,6 +328,7 @@ async def _collect_instance(inst) -> dict | None:
|
|||||||
"alarms": [],
|
"alarms": [],
|
||||||
"agents": [],
|
"agents": [],
|
||||||
"agent_policies": [],
|
"agent_policies": [],
|
||||||
|
"protection_groups": [],
|
||||||
"restore_points": [],
|
"restore_points": [],
|
||||||
}
|
}
|
||||||
return error_result
|
return error_result
|
||||||
|
|||||||
@@ -278,7 +278,10 @@ class VeeamClient:
|
|||||||
|
|
||||||
async def fetch_alarms(self) -> list[dict]:
|
async def fetch_alarms(self) -> list[dict]:
|
||||||
if self._is_v12():
|
if self._is_v12():
|
||||||
return await self._fetch_json_list("/api/v1/alarms")
|
try:
|
||||||
|
return await self._fetch_json_list("/api/v1/alarms")
|
||||||
|
except Exception:
|
||||||
|
return []
|
||||||
return []
|
return []
|
||||||
|
|
||||||
async def fetch_backup_servers(self) -> list[dict]:
|
async def fetch_backup_servers(self) -> list[dict]:
|
||||||
@@ -291,6 +294,11 @@ class VeeamClient:
|
|||||||
return await self._fetch_json_list("/api/v1/agents/protectedComputers")
|
return await self._fetch_json_list("/api/v1/agents/protectedComputers")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
async def fetch_protection_groups(self) -> list[dict]:
|
||||||
|
if self._is_v12():
|
||||||
|
return await self._fetch_json_list("/api/v1/agents/protectionGroups")
|
||||||
|
return []
|
||||||
|
|
||||||
async def fetch_agent_policies(self) -> list[dict]:
|
async def fetch_agent_policies(self) -> list[dict]:
|
||||||
if self._is_v12():
|
if self._is_v12():
|
||||||
seen: set[str] = set()
|
seen: set[str] = set()
|
||||||
@@ -336,7 +344,7 @@ class VeeamClient:
|
|||||||
]
|
]
|
||||||
for t in backup_types:
|
for t in backup_types:
|
||||||
try:
|
try:
|
||||||
items = await self._fetch_json_list(f"/api/v1/backups?typeFilter={t}")
|
items = await self._fetch_json_list(f"/api/v1/backups?jobTypeFilter={t}")
|
||||||
for b in items:
|
for b in items:
|
||||||
bid = b.get("id") or b.get("Id") or ""
|
bid = b.get("id") or b.get("Id") or ""
|
||||||
if bid and bid not in seen:
|
if bid and bid not in seen:
|
||||||
|
|||||||
Reference in New Issue
Block a user