Show Proxmox guests and scheduled backup status in device details
Rust development slice / linux (push) Failing after 14s

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 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 12:12:54 +01:00
co-authored by Claude Opus 5.5
parent 70977df577
commit ce356f0de7
6 changed files with 190 additions and 6 deletions
+21 -1
View File
@@ -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();
+11 -5
View File
@@ -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 <span className="vm-hypervisor">
<NavIcon name="geraete" /><span>Hypervisor <a href={'#' + path} onClick={event => event.stopPropagation()}>
{target.hostname}
</a></span>
</a>{info.source === 'proxmox' && <span className="muted"> · automatisch über Proxmox erkannt</span>}</span>
</span>;
}
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<string | null>(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 <details onToggle={e => {
@@ -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 && <p className="muted">Weitere Hypervisoren lassen sich über die Suche finden.</p>}
<label>Hypervisor auswählen<select aria-label="Hypervisor auswählen" value={value}
onChange={e => { setDraft(e.target.value); setNotice(''); setError(null); }} disabled={busy}>
<option value={AUTO}>Automatisch (Proxmox-Gastliste)</option>
<option value="">Kein konkreter Hypervisor</option>
{selectedMissing && <option value={value} disabled>
{assignedHost?.asset_id === value ? assignedHost.hostname : 'Zugeordneter Host außerhalb der Treffer'}
+2
View File
@@ -18,6 +18,7 @@ import { CatalogCheckNotice } from './catalog-check';
import { devicePlatform } from './script-catalog';
import { DeviceInventoryPanels, systemDetails } from './device-inventory';
import { OPNsenseDetails } from './opnsense';
import { ProxmoxDetails } from './proxmox';
import { DeviceCustomerTransfer } from './device-customer-transfer';
import { HypervisorAssignment, HypervisorLabel } from './device-hypervisor';
import { ErrorBox, errorText, useResource } from './resource';
@@ -340,6 +341,7 @@ function DeviceDetail({
onSaved={() => { setPurposeSaved(true); detail.reload(); }}
/>
<OPNsenseDetails device={d} />
<ProxmoxDetails device={d} />
<DeviceInventoryPanels device={d} />
{volumes.length > 0 && (
<section>
+40
View File
@@ -0,0 +1,40 @@
import { renderToStaticMarkup } from 'react-dom/server';
import { expect, it } from 'vitest';
import { ProxmoxDetails } from './proxmox';
const data = { node: 'pve', cluster: null, version: '9.2.2', not_backed_up: [101],
guests: [
{ vmid: 100, name: 'debian-guest', kind: 'qemu', status: 'running', template: false, cpus: 1,
memory_bytes: 2 ** 30, disk_bytes: 2 ** 33, macs: ['bc:24:11:88:35:97'] },
{ vmid: 101, name: 'alpine-ct', kind: 'lxc', status: 'running', template: false, cpus: 1,
memory_bytes: 2 ** 27, disk_bytes: 2 ** 30, macs: [] }],
backup_jobs: [{ id: 'backup-debian', enabled: true, schedule: '*/2:00', storage: 'local',
selection: 'vmid', covered_vmids: [100], last_expected_run: 1795172400, next_run: 1795179600 }],
backup_runs: [] };
it('lists guests, linked devices and an overall backup answer', () => {
const view = renderToStaticMarkup(<ProxmoxDetails device={{ tenant_id: 't', proxmox: {
quality: 'valid', observed_at: '2026-11-20T12:00:00Z', data,
backup_status: { all_scheduled_backups_ran: true, last_success_at: { '100': 1795172488 },
jobs: [{ id: 'backup-debian', status: 'ok', guests: [{ vmid: 100, status: 'ok' }] }] },
guest_devices: [{ vmid: 100, asset_id: 'a', agent_id: 'b', hostname: 'debian-guest' }] } }} />);
expect(view).toContain('Alle geplanten Backups sind gelaufen.');
expect(view).toContain('href="#geraete/t/a/b"');
expect(view).toContain('Container');
expect(view).toMatch(/Ohne Backupjob<\/h3><p>101 alpine-ct/);
expect(view).toContain('Gelaufen');
});
it('names failed guests and explains a missing read token', () => {
const failed = renderToStaticMarkup(<ProxmoxDetails device={{ proxmox: { quality: 'valid', data,
backup_status: { all_scheduled_backups_ran: false, last_success_at: {},
jobs: [{ id: 'backup-debian', status: 'failed', guests: [{ vmid: 100, status: 'failed' }] }] },
guest_devices: [] } }} />);
expect(failed).toContain('Nicht alle geplanten Backups sind gelaufen.');
expect(failed).toContain('100 debian-guest: Fehlgeschlagen');
expect(failed).toContain('nicht zugeordnet');
const missing = renderToStaticMarkup(<ProxmoxDetails device={{ proxmox: {
quality: 'unsupported', error_code: 'PROXMOX_NOT_CONFIGURED', data: null } }} />);
expect(missing).toContain('kein Lesezugang');
expect(renderToStaticMarkup(<ProxmoxDetails device={{}} />)).toBe('');
});
+114
View File
@@ -0,0 +1,114 @@
import { record, type RecordValue } from './api';
const dateFormat = new Intl.DateTimeFormat('de-DE', { dateStyle: 'short', timeStyle: 'short' });
const gib = new Intl.NumberFormat('de-DE', { maximumFractionDigits: 1 });
const JOB_STATUS: Record<string, [string, string]> = {
ok: ['Gelaufen', 'online'],
failed: ['Fehlgeschlagen', 'failed'],
missed: ['Verpasst', 'failed'],
running: ['Läuft', 'historic'],
pending: ['Noch nicht fällig', ''],
disabled: ['Deaktiviert', ''],
unknown: ['Unbekannt', 'historic'],
};
const GUEST_STATUS: Record<string, string> = { running: 'Läuft', stopped: 'Gestoppt', paused: 'Pausiert' };
function list(value: unknown): RecordValue[] {
return Array.isArray(value) ? value.filter(v => v && typeof v === 'object' && !Array.isArray(v)).map(v => record(v)) : [];
}
function epoch(value: unknown) {
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? dateFormat.format(value * 1000) : '–';
}
function size(value: unknown) {
return typeof value === 'number' && value > 0 ? gib.format(value / 2 ** 30) + ' GiB' : '–';
}
function text(value: unknown) {
return typeof value === 'string' && value.trim() ? value : '–';
}
function Badge({ status }: { status: unknown }) {
const [title, tone] = JOB_STATUS[typeof status === 'string' ? status : 'unknown'] ?? ['Unbekannt', 'historic'];
return <span className={'presence ' + tone}><i />{title}</span>;
}
function deviceLink(tenant: unknown, link: RecordValue | undefined) {
if (!link || typeof tenant !== 'string' || typeof link.asset_id !== 'string' || typeof link.agent_id !== 'string') return null;
const path = ['geraete', tenant, link.asset_id, link.agent_id].map(encodeURIComponent).join('/');
return <a href={'#' + path}>{text(link.hostname)}</a>;
}
/** Hosted guests and scheduled vzdump backups reported by a Proxmox VE host. */
export function ProxmoxDetails({ device }: { device: RecordValue }) {
if (!device.proxmox || typeof device.proxmox !== 'object') return null;
const report = record(device.proxmox);
if (report.quality !== 'valid' || !report.data) {
const reason = report.error_code === 'PROXMOX_NOT_CONFIGURED'
? 'Für diesen Proxmox-Host ist kein Lesezugang eingerichtet. Der HTTPS-Installer richtet ihn bei der Aufnahme ein.'
: 'Nicht ermittelbar' + (typeof report.error_code === 'string' ? ` (${report.error_code})` : '') + '.';
return <section><h2>Proxmox VE</h2><p>{reason}</p></section>;
}
const data = record(report.data);
const status = report.backup_status ? record(report.backup_status) : {};
const jobStatus = new Map(list(status.jobs).map(j => [j.id, j]));
const lastSuccess = status.last_success_at ? record(status.last_success_at) : {};
const links = new Map(list(report.guest_devices).map(l => [l.vmid, l]));
const guests = list(data.guests);
const names = new Map(guests.map(g => [g.vmid, text(g.name)]));
const jobs = list(data.backup_jobs);
const notBackedUp = Array.isArray(data.not_backed_up) ? data.not_backed_up : [];
const allRan = status.all_scheduled_backups_ran;
const guestName = (id: unknown) => `${String(id)} ${names.get(id) ?? ''}`.trim();
return <>
<section>
<h2>Virtuelle Maschinen und Container</h2>
<p className="muted">Node {text(data.node)}{typeof data.cluster === 'string' ? ` · Cluster ${data.cluster}` : ''}
{typeof data.version === 'string' ? ` · Proxmox VE ${data.version}` : ''} · erhoben {typeof report.observed_at === 'string' ? dateFormat.format(Date.parse(report.observed_at)) : '–'}
{report.truncated === true ? ' · Auszug – unvollständige Liste' : ''}</p>
{guests.length === 0 ? <p>Keine Gäste auf diesem Node.</p> : <div className="table"><table>
<thead><tr><th>VMID</th><th>Name</th><th>Typ</th><th>Status</th><th>vCPU</th><th>RAM</th><th>Disk</th><th>Gerät im Bestand</th><th>Letzte Sicherung</th></tr></thead>
<tbody>{guests.map(g => <tr key={String(g.vmid)}>
<td>{String(g.vmid)}</td>
<td>{text(g.name)}{g.template === true && <span className="muted"> · Vorlage</span>}</td>
<td>{g.kind === 'lxc' ? 'Container' : 'VM'}</td>
<td>{GUEST_STATUS[String(g.status)] ?? text(g.status)}</td>
<td>{typeof g.cpus === 'number' ? g.cpus : '–'}</td>
<td>{size(g.memory_bytes)}</td>
<td>{size(g.disk_bytes)}</td>
<td>{deviceLink(device.tenant_id, links.get(g.vmid)) ?? <span className="muted">nicht zugeordnet</span>}</td>
<td>{epoch(lastSuccess[String(g.vmid)])}</td>
</tr>)}</tbody>
</table></div>}
</section>
<section>
<h2>Geplante Backups</h2>
<p role="status">{allRan === true ? <><Badge status="ok" /> Alle geplanten Backups sind gelaufen.</>
: allRan === false ? <><Badge status="failed" /> Nicht alle geplanten Backups sind gelaufen.</>
: 'Keine aktiven Backupjobs für diesen Node.'}</p>
{jobs.length > 0 && <div className="table"><table>
<thead><tr><th>Job</th><th>Zeitplan</th><th>Storage</th><th>Gäste</th><th>Zuletzt fällig</th><th>Ergebnis</th><th>Nächster Lauf</th></tr></thead>
<tbody>{jobs.map(job => {
const evaluated = jobStatus.get(job.id);
const problems = list(evaluated?.guests).filter(g => g.status !== 'ok');
const covered = Array.isArray(job.covered_vmids) ? job.covered_vmids : [];
return <tr key={String(job.id)}>
<td>{text(job.id)}</td>
<td><code>{text(job.schedule)}</code></td>
<td>{text(job.storage)}</td>
<td>{covered.length ? covered.map(guestName).join(', ') : <span className="muted">keine lokalen Gäste</span>}
{job.selection === 'all' && <span className="muted"> (alle)</span>}</td>
<td>{epoch(job.last_expected_run)}</td>
<td><Badge status={evaluated?.status} />
{problems.length > 0 && <ul className="compact">{problems.map(g =>
<li key={String(g.vmid)}>{guestName(g.vmid)}: {JOB_STATUS[String(g.status)]?.[0] ?? text(g.status)}</li>)}</ul>}</td>
<td>{epoch(job.next_run)}</td>
</tr>;
})}</tbody>
</table></div>}
{notBackedUp.length > 0 && <>
<h3>Ohne Backupjob</h3>
<p>{notBackedUp.map(guestName).join(', ')}</p>
</>}
</section>
</>;
}
+2
View File
@@ -116,6 +116,8 @@ section.fleet { padding:0; overflow:hidden; }
.presence i { width:6px; height:6px; border-radius:50%; background:currentColor; }
.presence.online { color:#236343; background:#e6f4e9; }
.presence.historic { color:#80581c; background:#faf1df; }
.presence.failed { color:#7b3029; background:#fdf1ee; }
ul.compact { margin:4px 0 0; padding-left:18px; font-size:.85rem; }
.fleet small { font-size:.75rem; margin-top:3px; }
.list-message,.history-hint,.empty-list,.fleet > .error { margin:14px 20px; }
.history-hint,.list-footer { color:var(--subtle); font-size:.83rem; }