Expand the passive inventory shown in device details
Rust development slice / linux (push) Failing after 9s
Rust development slice / linux (push) Failing after 9s
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, it } from 'vitest';
|
||||
import { DeviceInventoryPanels, systemDetails } from './device-inventory';
|
||||
|
||||
const report = (scope: string, data: unknown, truncated = false, quality = 'valid') =>
|
||||
({ scope, data, truncated, quality, observed_at: '2026-11-18T08:00:00Z' });
|
||||
|
||||
it('reads current and older Linux snapshots, and labels approximate installation time', () => {
|
||||
const device = { inventory: { observations: [
|
||||
report('linux.os', { installed_at: '2025-03-12T10:00:00Z', install_date_source: 'root_filesystem', uptime_seconds: 60 }),
|
||||
report('linux.hardware', { readable_dmi: { sys_vendor: 'Vendor' } }),
|
||||
report('linux.interfaces', [{ name: 'eth0', addresses: ['192.0.2.1', '2001:db8::1%0'] }]),
|
||||
report('linux.users', ['alice']),
|
||||
report('linux.software', [{ name: 'openssh-server', version: '1.2', architecture: 'arm64' }], true)
|
||||
] } };
|
||||
expect(systemDetails(device, value => typeof value === 'string' ? value : 'Nicht gemeldet')).toEqual([
|
||||
['OS installiert am', '2025-03-12T10:00:00Z · geschätzt (Root-Dateisystem)'],
|
||||
['Letzter Neustart', '2026-11-18T07:59:00.000Z'],
|
||||
['Hersteller', 'Vendor'],
|
||||
['BIOS-Seriennummer', 'Nicht gemeldet'],
|
||||
['Garantie bis', 'Nicht gemeldet']
|
||||
]);
|
||||
const view = renderToStaticMarkup(<DeviceInventoryPanels device={device} />);
|
||||
expect(view).toContain('192.0.2.1, 2001:db8::1');
|
||||
expect(view).toContain('alice');
|
||||
expect(view).toContain('openssh-server');
|
||||
expect(view).toContain('einen Teil der gefundenen Einträge');
|
||||
});
|
||||
|
||||
it('shows Windows adapters, serial and registry software, with unknown distinct from empty sessions', () => {
|
||||
const device = { inventory: { observations: [
|
||||
report('windows.os', { booted_at: '2026-11-18T08:00:00Z' }),
|
||||
report('windows.hardware', { manufacturer: 'Vendor', bios_serial_number: 'ABC123' }),
|
||||
report('windows.interfaces', { entries: [{ name: 'Ethernet', addresses: ['192.0.2.2'] }] }),
|
||||
report('windows.users', null, false, 'permission_denied'),
|
||||
report('windows.software', { entries: [{ display_name: 'Produkt', publisher: 'Hersteller' }] })
|
||||
] } };
|
||||
const view = renderToStaticMarkup(<DeviceInventoryPanels device={device} />);
|
||||
expect(view).toContain('Ethernet');
|
||||
expect(view).toContain('Produkt');
|
||||
expect(view).toContain('Nicht gemeldet');
|
||||
expect(view).not.toContain('Keine Benutzer angemeldet');
|
||||
expect(systemDetails(device, String)).toContainEqual(['BIOS-Seriennummer', 'ABC123']);
|
||||
device.inventory.observations[3] = report('windows.users', { entries: [] });
|
||||
expect(renderToStaticMarkup(<DeviceInventoryPanels device={device} />)).toContain('Keine Benutzer angemeldet');
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import type { RecordValue } from './api';
|
||||
|
||||
const unreported = 'Nicht gemeldet';
|
||||
const pageSize = 25;
|
||||
|
||||
function object(value: unknown): RecordValue {
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? value as RecordValue : {};
|
||||
}
|
||||
function text(value: unknown): string | undefined {
|
||||
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
||||
}
|
||||
function values(value: unknown) {
|
||||
return Array.isArray(value) ? value.flatMap(value => text(value) ?? []) : [];
|
||||
}
|
||||
|
||||
function observation(device: RecordValue, name: string) {
|
||||
const observations = object(device.inventory).observations;
|
||||
return Array.isArray(observations) ? observations.map(object).find(item =>
|
||||
item.quality === 'valid' && (item.scope === 'linux.' + name || item.scope === 'windows.' + name)
|
||||
) : undefined;
|
||||
}
|
||||
|
||||
export function systemDetails(device: RecordValue, formatTime: (value: unknown) => string) {
|
||||
const os = observation(device, 'os');
|
||||
const system = object(os?.data);
|
||||
const hardware = object(observation(device, 'hardware')?.data);
|
||||
const installed = formatTime(system.installed_at);
|
||||
const source = system.install_date_source === 'root_filesystem' ? 'Root-Dateisystem'
|
||||
: system.install_date_source === 'installer_directory' ? 'Installer-Verzeichnis' : null;
|
||||
let booted = formatTime(system.booted_at);
|
||||
if (booted === unreported && os?.scope === 'linux.os' && typeof system.uptime_seconds === 'number') {
|
||||
const captured = Date.parse(text(os.observed_at) ?? '');
|
||||
const estimated = captured - system.uptime_seconds * 1000;
|
||||
if (system.uptime_seconds >= 0 && Number.isFinite(estimated) && estimated >= 0) {
|
||||
booted = formatTime(new Date(estimated).toISOString());
|
||||
}
|
||||
}
|
||||
return [
|
||||
['OS installiert am', source && installed !== unreported ? installed + ' · geschätzt (' + source + ')' : installed],
|
||||
['Letzter Neustart', booted],
|
||||
['Hersteller', text(hardware.manufacturer) ?? text(object(hardware.readable_dmi).sys_vendor) ?? unreported],
|
||||
['BIOS-Seriennummer', text(hardware.bios_serial_number) ?? unreported],
|
||||
['Garantie bis', formatTime(hardware.warranty_expires_at)]
|
||||
];
|
||||
}
|
||||
|
||||
function entries(report: RecordValue | undefined): unknown[] | null {
|
||||
const rows = Array.isArray(report?.data) ? report.data : object(report?.data).entries;
|
||||
return Array.isArray(rows) ? rows : null;
|
||||
}
|
||||
|
||||
function note(report: RecordValue | undefined) {
|
||||
const readErrors = object(report?.data).read_errors;
|
||||
return report?.truncated === true || (typeof readErrors === 'number' && readErrors > 0);
|
||||
}
|
||||
|
||||
function InventoryTable({ headings, children }: { headings: string[]; children: ReactNode }) {
|
||||
return <div className="table"><table>
|
||||
<thead><tr>{headings.map(label => <th scope="col" key={label}>{label}</th>)}</tr></thead>
|
||||
<tbody>{children}</tbody>
|
||||
</table></div>;
|
||||
}
|
||||
|
||||
function Software({ report }: { report: RecordValue | undefined }) {
|
||||
const [query, setQuery] = useState('');
|
||||
const [page, setPage] = useState(0);
|
||||
const rows = entries(report)?.flatMap(entry => {
|
||||
const row = object(entry);
|
||||
const name = text(row.name) ?? text(row.display_name);
|
||||
if (!name) return [];
|
||||
return [{ name, version: text(row.version), publisher: text(row.publisher), architecture: text(row.architecture) }];
|
||||
}).sort((left, right) => left.name.localeCompare(right.name, 'de'));
|
||||
const matching = (rows ?? []).filter(row => Object.values(row).some(value =>
|
||||
value?.toLocaleLowerCase('de').includes(query.trim().toLocaleLowerCase('de'))
|
||||
));
|
||||
const lastPage = Math.max(0, Math.ceil(matching.length / pageSize) - 1);
|
||||
const current = Math.min(page, lastPage);
|
||||
|
||||
return <details>
|
||||
<summary>Installierte Software{rows ? ' (' + rows.length + ')' : ''}</summary>
|
||||
{note(report) && <p className="muted">Die Meldung enthält einen Teil der gefundenen Einträge.</p>}
|
||||
{rows === undefined ? <p>{unreported}</p> : rows.length === 0 ? <p>Keine Softwareeinträge gemeldet.</p> : <>
|
||||
<label>Software suchen
|
||||
<input type="search" value={query} maxLength={120} onChange={e => { setQuery(e.target.value); setPage(0); }} />
|
||||
</label>
|
||||
{matching.length ? <InventoryTable headings={['Name', 'Version', 'Herausgeber', 'Architektur']}>
|
||||
{matching.slice(current * pageSize, (current + 1) * pageSize).map((row, index) => <tr key={index}>
|
||||
<td>{row.name}</td>
|
||||
<td>{row.version ?? '–'}</td>
|
||||
<td>{row.publisher ?? '–'}</td>
|
||||
<td>{row.architecture ?? '–'}</td>
|
||||
</tr>)}
|
||||
</InventoryTable> : <p>Keine Treffer.</p>}
|
||||
{lastPage > 0 && <div className="list-footer">
|
||||
<span>Seite {current + 1} von {lastPage + 1}</span>
|
||||
<div>
|
||||
<button className="quiet" disabled={current === 0} onClick={() => setPage(current - 1)}>Zurück</button>
|
||||
<button className="quiet" disabled={current === lastPage} onClick={() => setPage(current + 1)}>Weiter</button>
|
||||
</div>
|
||||
</div>}
|
||||
</>}
|
||||
</details>;
|
||||
}
|
||||
|
||||
export function DeviceInventoryPanels({ device }: { device: RecordValue }) {
|
||||
const network = observation(device, 'interfaces');
|
||||
const interfaces = entries(network)?.map(object).filter(row => text(row.name));
|
||||
const sessions = observation(device, 'users');
|
||||
const users = values(entries(sessions)).sort((a, b) => a.localeCompare(b, 'de'));
|
||||
return <>
|
||||
<section>
|
||||
<h2>Netzwerkkarten und IP-Adressen</h2>
|
||||
{note(network) && <p className="muted">Die Meldung enthält einen Teil der Netzwerkkarten oder Adressen.</p>}
|
||||
{interfaces === undefined ? <p>{unreported}</p> : interfaces.length === 0 ? <p>Keine Netzwerkkarten gemeldet.</p> :
|
||||
<InventoryTable headings={['Netzwerkkarte', 'MAC-Adresse', 'IP-Adressen']}>
|
||||
{interfaces.map((row, index) => <tr key={index}>
|
||||
<td>{text(row.name)}</td>
|
||||
<td>{text(row.mac) ?? '–'}</td>
|
||||
<td>{values(row.addresses).map(address => address.replace(/%0$/, '')).join(', ') || 'Keine Adresse gemeldet'}</td>
|
||||
</tr>)}
|
||||
</InventoryTable>}
|
||||
</section>
|
||||
<section>
|
||||
<h2>Angemeldete Benutzer</h2>
|
||||
{note(sessions) && <p className="muted">Die Meldung enthält einen Teil der Sitzungen.</p>}
|
||||
{users.length ? <ul>{users.map(name => <li key={name}>{name}</li>)}</ul>
|
||||
: <p>{entries(sessions) && !note(sessions) ? 'Keine Benutzer angemeldet.' : unreported}</p>}
|
||||
</section>
|
||||
<section><Software report={observation(device, 'software')} /></section>
|
||||
</>;
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import { AdminControl } from './management';
|
||||
import { allowed } from './safety';
|
||||
import { CatalogCheckNotice } from './catalog-check';
|
||||
import { devicePlatform } from './script-catalog';
|
||||
import { DeviceInventoryPanels, systemDetails } from './device-inventory';
|
||||
import { ErrorBox, errorText, useResource } from './resource';
|
||||
import { NavIcon, orderDetailRoute } from './navigation';
|
||||
import { orderTitle, Status } from './order-presentation';
|
||||
@@ -179,6 +180,7 @@ function DeviceDetail({
|
||||
['Kunde', label(d.customer_name)],
|
||||
['Type', label(d.device_type)],
|
||||
['Betriebssystem', label(d.os)],
|
||||
...systemDetails(d, time),
|
||||
['RAM frei / gesamt', capacity(d.ram_available_bytes, d.ram_total_bytes)],
|
||||
['CPU', [cpu(d).primary, cpu(d).secondary].filter(Boolean).join(' · ')],
|
||||
['CPU-Auslastung', [cpuUsage(d.cpu_usage_percent), measuredAt(d.cpu_usage_observed_at)].filter(Boolean).join(' · ')],
|
||||
@@ -214,6 +216,7 @@ function DeviceDetail({
|
||||
))}
|
||||
</dl>
|
||||
</section>
|
||||
<DeviceInventoryPanels device={d} />
|
||||
{volumes.length > 0 && (
|
||||
<section>
|
||||
<h2>Laufwerke</h2>
|
||||
|
||||
Reference in New Issue
Block a user