fix: replace agent policies endpoint with jobs API query per v13 docs

This commit is contained in:
2026-06-10 09:19:48 +07:00
parent f2194cc0fd
commit d15be6c0d3
3 changed files with 45 additions and 10 deletions

View File

@@ -187,6 +187,12 @@ async def _collect_instance(inst) -> dict | None:
except Exception as e:
errors.append(f"agents: {e}")
try:
agent_policies = await client.fetch_agent_policies()
except Exception as e:
errors.append(f"agent policies: {e}")
agent_policies = []
for s in sessions_data:
if isinstance(s.get("result"), dict):
s["result"] = s["result"].get("result") or s["result"].get("Result") or "unknown"
@@ -255,6 +261,7 @@ async def _collect_instance(inst) -> dict | None:
"repository_states": repo_states,
"alarms": alarms_data,
"agents": agents_data,
"agent_policies": agent_policies,
}
await set_cache(inst.id, "dashboard", result)
@@ -277,6 +284,7 @@ async def _collect_instance(inst) -> dict | None:
"repository_states": [],
"alarms": [],
"agents": [],
"agent_policies": [],
}
return error_result
finally:

View File

@@ -483,7 +483,7 @@ function renderJobsTable(inst) {
if (!jobs.length) return '<div class="empty-state">Нет данных о политиках</div>';
const enabled = (js.total || 0) - (js.disabled || 0);
let header = '<div class="jobs-summary"><span>Всего: <strong>' + (js.total || 0) + '</strong></span> <span>Включено: <strong style="color:var(--green)">' + enabled + '</strong></span> <span>Выключено: <strong style="color:var(--red)">' + (js.disabled || 0) + '</strong></span>';
if (js.disabled > 0) header += ' <span class="badge danger">⚠ ВНИМАНИЕ! ЕСТЬ ВЫКЛЮЧЕННЫЕ ПОЛИТИКИ!</span>';
if (js.disabled > 0) header += ' <span class="badge danger">⚠ ВНИМАНИЕ! ЕСТЬ ВЫКЛЮЧЕННЫЕ!</span>';
header += '</div>';
let rows = '';
for (const j of jobs) {
@@ -497,7 +497,22 @@ function renderJobsTable(inst) {
rows += '<td>' + (isDisabled ? '<span class="badge danger">выключена</span>' : '<span class="badge success">включена</span>') + '</td>';
rows += '</tr>';
}
return header + '<div class="table-wrap"><table><thead><tr><th>Имя</th><th>Тип</th><th>Точки восст.</th><th>Последний бэкап</th><th>Расписание</th></tr></thead><tbody>' + rows + '</tbody></table></div>';
let html = header + '<div class="table-wrap"><table><thead><tr><th>Имя</th><th>Тип</th><th>Точки восст.</th><th>Последний бэкап</th><th>Расписание</th></tr></thead><tbody>' + rows + '</tbody></table></div>';
const policies = inst.agent_policies || [];
if (policies.length) {
html += '<h4 style="margin:16px 0 8px;font-size:13px;color:var(--text-muted)">Агентские политики</h4>';
html += '<div class="table-wrap"><table><thead><tr><th>Имя</th><th>Тип</th><th>Расписание</th></tr></thead><tbody>';
for (const p of policies) {
const isDisabled = p.schedule_enabled === false || (p.state || '').toLowerCase() === 'disabled';
html += '<tr class="' + (isDisabled ? 'job-disabled' : '') + '">';
html += '<td>' + esc(p.name || p.Name || '—') + '</td>';
html += '<td>' + esc(p.type || p.jobType || '—') + '</td>';
html += '<td>' + (isDisabled ? '<span class="badge danger">выключена</span>' : '<span class="badge success">включена</span>') + '</td>';
html += '</tr>';
}
html += '</tbody></table></div>';
}
return html;
}
function renderSessionsTable(inst) {

View File

@@ -297,14 +297,26 @@ class VeeamClient:
async def fetch_agent_policies(self) -> list[dict]:
if self._is_v12():
for path in (
"/api/v1/agents/policies/states",
"/api/v1/agents/policies",
):
try:
return await self._fetch_json_list(path)
except Exception:
continue
seen: set[str] = set()
all_policies: list[dict] = []
policy_types = [
"WindowsAgentBackupWorkstationPolicy",
"LinuxAgentBackupWorkstationPolicy",
"WindowsAgentBackupServerPolicy",
"LinuxAgentBackupServerPolicy",
]
for t in policy_types:
for base in ("/api/v1/jobs/states", "/api/v1/jobs"):
try:
items = await self._fetch_json_list(f"{base}?typeFilter={t}")
for p in items:
pid = p.get("id") or p.get("Id") or ""
if pid and pid not in seen:
seen.add(pid)
all_policies.append(p)
except Exception:
continue
return all_policies
return []
async def _fetch_json_list(self, path: str) -> list[dict]: