import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { api, type DockhandVulnerabilitiesResponse, type DockhandVulnerabilityEnvironment } from "../api/client"; import TimeAgo from "../components/TimeAgo"; import { readableError } from "../utils/errors"; const count = (v: number | null) => (v === null ? "—" : v.toLocaleString()); const ageText = (days: number) => (days >= 730 ? `${Math.floor(days / 365)} years` : days >= 60 ? `${Math.floor(days / 30)} months` : `${days} days`); function Host({ env, imageAgeDays }: { env: DockhandVulnerabilityEnvironment; imageAgeDays: number }) { const [open, setOpen] = useState(false); const unscanned = env.totalImages !== null && env.imagesScanned !== null ? env.totalImages - env.imagesScanned : null; return (
{env.environmentName} {env.critical === null ? ( Not read ) : env.critical > 0 ? ( {env.critical} critical ) : ( No critical )} {count(env.high)} high · {count(env.medium)} medium · {count(env.low)} low {env.imagesScanned === null ? "" : `${env.imagesScanned} of ${env.totalImages ?? "?"} images scanned`} {unscanned !== null && unscanned > 0 ? ` — ${unscanned} not scanned yet` : ""}
{env.images && env.images.oldest.length > 0 && (
Oldest running images: {env.images.oldest.slice(0, 3).map((i) => `${i.image} (${ageText(i.ageDays)})`).join(", ")} {imageAgeDays > 0 && env.images.over !== null ? (env.images.over > 0 ? ` — ${env.images.over} built more than ${imageAgeDays} days ago (an alert)` : ` — none older than ${imageAgeDays} days`) : ""} {env.images.undated > 0 ? ` · ${env.images.undated} with no build date` : ""}
)} {env.findings.length > 0 && ( <> {open && (
{env.findings.map((f, i) => ( ))}
CVE Package Installed Fixed in Image Used by
{f.cve} {f.package} {f.installedVersion || "—"} {f.fixedVersion ? {f.fixedVersion} : no fix yet} {f.imageName} {f.containers.length > 0 ? f.containers.join(", ") : "—"}
)} )}
); } /** What Dockhand's own vulnerability scans found, per Docker host. Read from what was stored; nothing is asked of Dockhand here, and nothing is scanned. */ export default function DockerVulnerabilities({ integrationId }: { integrationId: number }) { const [data, setData] = useState(null); const [error, setError] = useState(null); useEffect(() => { setData(null); const load = () => api.integrations.dockhand .vulnerabilities(integrationId) .then((r) => { setData(r); setError(null); }) .catch((err) => setError(readableError(err))); void load(); const t = setInterval(load, 120_000); return () => clearInterval(t); }, [integrationId]); const critical = (data?.environments ?? []).reduce((sum, e) => sum + (e.critical ?? 0), 0); return (

Vulnerabilities {data && data.environments.length > 0 && (critical > 0 ? {critical} critical : none critical)}

{data?.status && (
read
)}
{error &&
{error}
} {!data && !error &&
Reading…
} {data && ( <>

From the scans Dockhand has already run on its images (it scans when it is told to — nothing is scanned from here). An image that was never scanned is not known to be clean.{" "} {data.alerts ? ( <> Critical findings are an alert — see Alerts;{" "} {data.highThreshold > 0 ? ( <> so is a host with {data.highThreshold} or more high ones (Settings → Notifications); medium and low are only shown here. ) : ( <>high, medium and low are only shown here (high ones can be alerted from a number you choose under Settings → Notifications). )} ) : ( <> The alert for critical findings is switched off (Settings → Notifications). )}

{data.status && !data.status.ok &&
The last attempt to read them failed: {data.status.error ?? "no answer"}.
} {data.environments.length === 0 && !data.status &&
Not read yet — it is read a few minutes after Dockhand is added, then every quarter of an hour.
} {data.environments.length === 0 && data.status?.ok &&
Dockhand lists no Docker hosts.
} {data.environments.map((e) => ( ))} )}
); }