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 = { 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 = { 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 {title}; } 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 {text(link.hostname)}; } /** 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

Proxmox VE

{reason}

; } 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 <>

Virtuelle Maschinen und Container

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' : ''}

{guests.length === 0 ?

Keine Gäste auf diesem Node.

:
{guests.map(g => )}
VMIDNameTypStatusvCPURAMDiskGerät im BestandLetzte Sicherung
{String(g.vmid)} {text(g.name)}{g.template === true && · Vorlage} {g.kind === 'lxc' ? 'Container' : 'VM'} {GUEST_STATUS[String(g.status)] ?? text(g.status)} {typeof g.cpus === 'number' ? g.cpus : '–'} {size(g.memory_bytes)} {size(g.disk_bytes)} {deviceLink(device.tenant_id, links.get(g.vmid)) ?? nicht zugeordnet} {epoch(lastSuccess[String(g.vmid)])}
}

Geplante Backups

{allRan === true ? <> Alle geplanten Backups sind gelaufen. : allRan === false ? <> Nicht alle geplanten Backups sind gelaufen. : 'Keine aktiven Backupjobs für diesen Node.'}

{jobs.length > 0 &&
{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 ; })}
JobZeitplanStorageGästeZuletzt fälligErgebnisNächster Lauf
{text(job.id)} {text(job.schedule)} {text(job.storage)} {covered.length ? covered.map(guestName).join(', ') : keine lokalen Gäste} {job.selection === 'all' && (alle)} {epoch(job.last_expected_run)} {problems.length > 0 &&
    {problems.map(g =>
  • {guestName(g.vmid)}: {JOB_STATUS[String(g.status)]?.[0] ?? text(g.status)}
  • )}
}
{epoch(job.next_run)}
} {notBackedUp.length > 0 && <>

Ohne Backupjob

{notBackedUp.map(guestName).join(', ')}

}
; }