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>
115 lines
6.2 KiB
TypeScript
115 lines
6.2 KiB
TypeScript
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>
|
||
</>;
|
||
}
|