From ce356f0de75f9bafb7f913c3d92eadca2ff4f2f9 Mon Sep 17 00:00:00 2001 From: Kevin Janssen Date: Fri, 20 Nov 2026 12:12:54 +0100 Subject: [PATCH] Show Proxmox guests and scheduled backup status in device details The host detail lists VMs and containers with linked inventory devices and last successful backup, each vzdump job with its due time and result, an overall 'all scheduled backups ran' answer and guests without a job. VM hosts detected from a Proxmox guest list are labelled and the assignment form can hand the decision back to automatic detection. Co-Authored-By: Claude Opus 5.5 --- tests/browser/customer-management.spec.ts | 22 ++++- web/src/device-hypervisor.tsx | 16 ++- web/src/devices.tsx | 2 + web/src/proxmox.test.tsx | 40 ++++++++ web/src/proxmox.tsx | 114 ++++++++++++++++++++++ web/src/style.css | 2 + 6 files changed, 190 insertions(+), 6 deletions(-) create mode 100644 web/src/proxmox.test.tsx create mode 100644 web/src/proxmox.tsx diff --git a/tests/browser/customer-management.spec.ts b/tests/browser/customer-management.spec.ts index 8dafce8..c26dce8 100644 --- a/tests/browser/customer-management.spec.ts +++ b/tests/browser/customer-management.spec.ts @@ -386,10 +386,25 @@ test('shows real VM hosts and the Hetzner placeholder without adding a device', lifecycle: 'current', status: 'online', recent_jobs: [], volumes: [] }; const vm = { ...base, hostname: 'Test-VM', asset_id: 'vm-asset', agent_id: 'vm-agent', device_type: 'virtual' }; const pve = { ...base, hostname: 'pve-01', asset_id: 'pve-asset', agent_id: 'pve-agent', - device_type: 'hypervisor', os: 'Proxmox VE' }; + device_type: 'hypervisor', os: 'Proxmox VE', tenant_id: tenant, + proxmox: { quality: 'valid', error_code: null, observed_at: new Date().toISOString(), truncated: false, + data: { node: 'pve-01', cluster: null, version: '9.2.2', not_backed_up: [101], + guests: [ + { vmid: 100, name: 'Test-VM', kind: 'qemu', status: 'running', template: false, cpus: 2, + memory_bytes: 2 ** 31, disk_bytes: 2 ** 33, macs: ['bc:24:11:00:00:01'] }, + { vmid: 101, name: 'alpine-ct', kind: 'lxc', status: 'stopped', template: false, cpus: 1, + memory_bytes: 2 ** 27, disk_bytes: 2 ** 30, macs: [] }], + backup_jobs: [{ id: 'backup-nightly', enabled: true, schedule: '21:00', storage: 'local', + selection: 'vmid', covered_vmids: [100], last_expected_run: 1795118400, next_run: 1795204800 }], + backup_runs: [] }, + backup_status: { all_scheduled_backups_ran: false, enabled_jobs: 1, problem_jobs: 1, + last_success_at: {}, jobs: [{ id: 'backup-nightly', status: 'missed', + guests: [{ vmid: 100, status: 'missed', last_success_at: null }] }] }, + guest_devices: [{ vmid: 100, asset_id: 'vm-asset', agent_id: 'vm-agent', hostname: 'Test-VM', source: 'proxmox' }] } }; const placeholder = { kind: 'placeholder', provider: 'hetzner', hostname: 'Hetzner Cloud' }; let assigned = false; const guest = () => ({ ...vm, assigned_hypervisor_asset_id: assigned ? pve.asset_id : null, + hypervisor_source: assigned ? 'manual' : null, hypervisor: assigned ? { kind: 'device', hostname: pve.hostname, asset_id: pve.asset_id, agent_id: pve.agent_id } : placeholder }); const listing = (items: unknown[]) => ({ items, next_cursor: null, truncated: false, completeness: 'complete', as_of: new Date().toISOString() }); @@ -445,6 +460,11 @@ test('shows real VM hosts and the Hetzner placeholder without adding a device', await expect(vmRow).not.toContainText('Hetzner Cloud'); await hostLink.click(); await expect(page.getByRole('heading', { name: pve.hostname })).toBeVisible(); + await expect(page.getByRole('heading', { name: 'Virtuelle Maschinen und Container' })).toBeVisible(); + await expect(page.getByRole('row').filter({ hasText: 'alpine-ct' })).toContainText('Container'); + await expect(page.getByRole('row').filter({ hasText: 'backup-nightly' })).toContainText('Verpasst'); + await expect(page.getByText('Nicht alle geplanten Backups sind gelaufen.')).toBeVisible(); + await expect(page.getByRole('link', { name: 'Test-VM' })).toBeVisible(); await page.getByRole('button', { name: 'Zur Geräteliste' }).click(); await page.getByRole('button', { name: vm.hostname }).click(); await page.getByText('Gerät verwalten', { exact: true }).click(); diff --git a/web/src/device-hypervisor.tsx b/web/src/device-hypervisor.tsx index d1e1898..7956036 100644 --- a/web/src/device-hypervisor.tsx +++ b/web/src/device-hypervisor.tsx @@ -4,6 +4,8 @@ import { NavIcon } from './navigation'; import { ErrorBox, errorText, useResource } from './resource'; type Host = { asset_id: string; agent_id: string; hostname: string }; +/** Select value that hands the decision back to automatic Proxmox detection. */ +const AUTO = 'automatic'; function host(value: unknown): Host | null { if (!value || typeof value !== 'object' || Array.isArray(value)) return null; @@ -24,7 +26,7 @@ export function HypervisorLabel({ device }: { device: RecordValue }) { return Hypervisor event.stopPropagation()}> {target.hostname} - + {info.source === 'proxmox' && · automatisch über Proxmox erkannt} ; } return info.kind === 'placeholder' && info.provider === 'hetzner' ? ( @@ -53,7 +55,8 @@ export function HypervisorAssignment({ device, customer, asset, agent, auth }: { const [busy, setBusy] = useState(false); const [notice, setNotice] = useState(''); const [error, setError] = useState(null); - const assigned = typeof device.assigned_hypervisor_asset_id === 'string' ? device.assigned_hypervisor_asset_id : ''; + const automatic = device.hypervisor_source !== 'manual'; + const assigned = automatic ? AUTO : typeof device.assigned_hypervisor_asset_id === 'string' ? device.assigned_hypervisor_asset_id : ''; const value = draft ?? assigned; useEffect(() => { @@ -70,7 +73,7 @@ export function HypervisorAssignment({ device, customer, asset, agent, auth }: { }, [customer, open, query]); const assignedHost = host(device.hypervisor); const hosts = options.data?.hosts ?? []; - const selectedMissing = !!value && !hosts.some(item => item.asset_id === value); + const selectedMissing = !!value && value !== AUTO && !hosts.some(item => item.asset_id === value); const canSave = value !== assigned && (!value || !selectedMissing); return
{ @@ -91,9 +94,11 @@ export function HypervisorAssignment({ device, customer, asset, agent, auth }: { setNotice(''); try { await request(tenantPath(customer, '/devices/' + encodeURIComponent(asset) + '/hypervisor?agent_id=' + encodeURIComponent(agent)), { - tenantId: customer, csrf: auth.csrf_token, body: { hypervisor_asset_id: value || null } + tenantId: customer, csrf: auth.csrf_token, + body: value === AUTO ? { hypervisor_asset_id: null, automatic: true } : { hypervisor_asset_id: value || null } }); - setNotice(value ? 'Hypervisor zugeordnet.' : 'Hostzuordnung entfernt.'); + setNotice(value === AUTO ? 'Automatische Zuordnung über Proxmox aktiviert.' + : value ? 'Hypervisor zugeordnet.' : 'Hostzuordnung entfernt.'); } catch (e) { setError(assignmentError(e)); } finally { @@ -106,6 +111,7 @@ export function HypervisorAssignment({ device, customer, asset, agent, auth }: { {options.data?.truncated &&

Weitere Hypervisoren lassen sich über die Suche finden.

}