Dependencies beyond servers, web push, inventory auto-fill with QR labels, Windows agent health
- Dependencies: servers and integrations can depend on each other; alerts are folded under the root cause, and a failure explained by something down isn't announced - Web push: hand-written VAPID and RFC 8291 encryption, per-device subscriptions, a fifth notification channel, service worker handlers - Inventory: maker/model/serial from the agents fill blank fields, "Refresh from agent", QR label printing and ?asset= deep links - Windows agent (v4) reports failed services, disk health, Storage Spaces pools and hardware identity; Linux agent (v5) reports hardware identity Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5cc51c57de
commit
ec9c2f73f0
55 files changed
+12553
-65
No files matched your search
@@ -102,6 +102,9 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
|
||||
const [params, setParams] = useSearchParams();
|
||||
const kind = (KINDS as string[]).includes(params.get("kind") ?? "") ? (params.get("kind") as AssetKind) : "";
|
||||
// A scanned label comes here with ?asset=ID: that one piece of hardware is shown first.
|
||||
const focusId = /^\d+$/.test(params.get("asset") ?? "") ? Number(params.get("asset")) : null;
|
||||
const focused = focusId === null ? null : (assets ?? []).find((a) => a.id === focusId) ?? null;
|
||||
|
||||
function load() {
|
||||
api.inventory
|
||||
@@ -158,6 +161,19 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshFromAgent(a: Asset) {
|
||||
const d = a.agent?.differs ?? {};
|
||||
const lines = (Object.keys(d) as (keyof typeof d)[]).map((k) => `${k}: "${a[k] ?? ""}" becomes "${d[k]}"`);
|
||||
if (!(await confirmDialog({ title: "Take over what the agent says", message: `${a.name}: ${lines.join("; ")}.`, confirmLabel: "Replace" }))) return;
|
||||
try {
|
||||
await api.inventory.refreshFromAgent(a.id);
|
||||
toast.success("Updated from the agent.");
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function saveConfig(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
@@ -180,6 +196,13 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
);
|
||||
}
|
||||
|
||||
// A name that is a server's name (or holds it) is probably that server.
|
||||
const suggestion = (() => {
|
||||
const n = draft?.name.trim().toLowerCase();
|
||||
if (!n) return null;
|
||||
return servers.find((s) => s.name.toLowerCase() === n) ?? servers.find((s) => s.name.length >= 3 && n.includes(s.name.toLowerCase())) ?? null;
|
||||
})();
|
||||
|
||||
const set = <K extends keyof Draft>(key: K, value: Draft[K]) => setDraft((d) => (d ? { ...d, [key]: value } : d));
|
||||
|
||||
const cards: { label: string; value: string; note?: string; color: string }[] = [
|
||||
@@ -198,14 +221,60 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<h2 className="page-title mb-0">Inventory</h2>
|
||||
{canEdit && !draft && (
|
||||
<button className="btn btn-primary ms-auto" onClick={() => setDraft({ ...EMPTY })}>
|
||||
Add hardware
|
||||
</button>
|
||||
)}
|
||||
<div className="ms-auto d-flex gap-2">
|
||||
<Link to="/inventory/labels" className="btn">
|
||||
Print labels
|
||||
</Link>
|
||||
{canEdit && !draft && (
|
||||
<button className="btn btn-primary" onClick={() => setDraft({ ...EMPTY })}>
|
||||
Add hardware
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
{focused && (
|
||||
<div className="card mb-3 border-primary">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{focused.name}</h3>
|
||||
<div className="card-actions">
|
||||
<button className="btn btn-sm" onClick={() => setParams((p) => { const n = new URLSearchParams(p); n.delete("asset"); return n; }, { replace: true })}>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<dl className="row mb-0">
|
||||
{([
|
||||
["Kind", KIND_LABELS[focused.kind]],
|
||||
["Maker and model", [focused.manufacturer, focused.model].filter(Boolean).join(" ") || null],
|
||||
["Serial number", focused.serial],
|
||||
["Where", [focused.location, focused.rackUnit].filter(Boolean).join(" · ") || null],
|
||||
["Bought", focused.purchaseDate],
|
||||
["Warranty until", focused.warrantyUntil],
|
||||
["Power draw", focused.powerWatts === null ? null : `${focused.powerWatts} W`],
|
||||
["Notes", focused.notes],
|
||||
] as [string, string | null][]).map(([label, value]) => (
|
||||
<div className="col-md-6 d-flex" key={label}>
|
||||
<dt className="col-5 text-secondary fw-normal">{label}</dt>
|
||||
<dd className="col-7">{value ?? "—"}</dd>
|
||||
</div>
|
||||
))}
|
||||
{focused.server && (
|
||||
<div className="col-md-6 d-flex">
|
||||
<dt className="col-5 text-secondary fw-normal">Is the server</dt>
|
||||
<dd className="col-7">
|
||||
<Link to={`/servers/${focused.server.id}`}>{focused.server.name}</Link>
|
||||
</dd>
|
||||
</div>
|
||||
)}
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{focusId !== null && assets !== null && !focused && <div className="alert alert-warning">That piece of hardware isn't in the inventory any more.</div>}
|
||||
|
||||
<div className="row row-cards mb-3">
|
||||
{cards.map((c) => (
|
||||
<div className="col-6 col-lg-3" key={c.label}>
|
||||
@@ -256,6 +325,15 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{draft.serverId === "" && suggestion && (
|
||||
<div className="form-hint small mt-1">
|
||||
Looks like <strong>{suggestion.name}</strong>.{" "}
|
||||
<button type="button" className="btn btn-link btn-sm p-0 align-baseline" onClick={() => set("serverId", String(suggestion.id))}>
|
||||
Link it
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{draft.serverId !== "" && <div className="form-hint text-secondary small mt-1">Blank maker, model and serial number are filled in from the server's agent when you save.</div>}
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="inv-maker">
|
||||
@@ -398,6 +476,14 @@ export default function Inventory({ user }: { user: CurrentUser }) {
|
||||
is <Link to={`/servers/${a.server.id}`}>{a.server.name}</Link>
|
||||
</div>
|
||||
)}
|
||||
{canEdit && a.agent && Object.keys(a.agent.differs).length > 0 && (
|
||||
<div className="small text-secondary">
|
||||
The agent says {Object.entries(a.agent.differs).map(([k, v]) => `${k === "manufacturer" ? "maker" : k === "serial" ? "serial number" : k} ${v}`).join(", ")}.{" "}
|
||||
<button type="button" className="btn btn-link btn-sm p-0 align-baseline" onClick={() => void refreshFromAgent(a)}>
|
||||
Refresh from agent
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
<td>{KIND_LABELS[a.kind]}</td>
|
||||
<td>
|
||||
|
||||
Reference in new issue
Block a user