Add a Technitium DNS widget to the dashboard

A card in the Network section replaces the generic tile: whether DNS answers
and how fast, the last day's queries and the share blocked, a bar of how they
were answered, blocking left off, a stale reading, and what is wrong (the
first two alerts). It follows the other cards: a status badge that colours the
edge and puts it first when it has a problem, hide and move under Customise,
refreshed every minute from the same data as the Technitium page.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-01 22:00:20 +01:00
1 parent a2ff0f7daa
commit f73704e6ca
3 files changed
+99 -2

No files matched your search

+96 -1
View File
@@ -20,6 +20,7 @@ import {
type SecretRecord,
type ServerSummary,
type TailscaleDevicesResponse,
type TechnitiumInstance,
} from "../api/client";
import { formatAgo } from "../utils/duration";
import StatusStrip from "../components/StatusStrip";
@@ -241,6 +242,73 @@ function WidgetCard({ label, badge, hide, children }: { label: string; badge?: R
);
}
/** The status badge of a Technitium DNS Server widget: switched off, not read yet, can't be read, or what its alerts say (red for a critical one, yellow for the rest). */
function technitiumBadge(enabled: boolean, t: TechnitiumInstance | null): ReactNode {
if (!enabled) return <span className="badge bg-secondary-lt text-secondary">Disabled</span>;
if (!t || !t.state) return <span className="badge bg-secondary-lt text-secondary">Not read yet</span>;
if (!t.fresh) return <span className="badge bg-yellow-lt text-yellow">Can&rsquo;t be read</span>;
if (t.problems.some((p) => p.severity === "critical")) return <span className="badge bg-red-lt text-red">Needs a look</span>;
if (t.problems.length > 0) return <span className="badge bg-yellow-lt text-yellow">Needs a look</span>;
return <span className="badge bg-green-lt text-green">In order</span>;
}
const TECHNITIUM_HOW_COLORS: Record<string, string> = { "from cache": "#60a5fa", resolved: "#22d3ee", "own zones": "#4ade80", blocked: "#fb923c", dropped: "#f87171" };
/** What the Technitium DNS Server widget says: whether DNS answers and how fast, the last day's queries and how many were blocked, how they were answered, and what is wrong. The page has the rest. */
function TechnitiumBody({ enabled, instance, loading }: { enabled: boolean; instance: TechnitiumInstance | null; loading: boolean }) {
if (!enabled) return <div className="text-secondary">Switched off under Integrations.</div>;
if (loading) return <WidgetSkeleton />;
const s = instance?.state ?? null;
const open = (
<div className="mt-2">
<Link to="/technitium">Open Technitium DNS</Link>
</div>
);
if (!instance || !s) {
return (
<>
<div className="text-secondary">Not read yet.</div>
{open}
</>
);
}
const st = s.stats;
const how = st
? [
{ label: "from cache", count: st.cached },
{ label: "resolved", count: st.recursive },
{ label: "own zones", count: st.authoritative },
{ label: "blocked", count: st.blocked },
{ label: "dropped", count: st.dropped },
].filter((d) => d.count > 0)
: [];
return (
<>
<div className="row g-2 mb-3">
<div className="col-4">
<MiniStat label="DNS answers" value={s.probe === null ? "—" : s.probe.ok ? `${s.probe.ms ?? "?"} ms` : "No"} accent={s.probe && !s.probe.ok ? "#f87171" : undefined} />
</div>
<div className="col-4">
<MiniStat label="Queries, 24 h" value={st ? st.queries.toLocaleString() : "—"} />
</div>
<div className="col-4">
<MiniStat label="Blocked" value={st?.blockedPercent != null ? `${st.blockedPercent}%` : "—"} accent={!s.blockingEnabled && s.settings.blockLists.count > 0 ? "#f59e0b" : undefined} />
</div>
</div>
{how.length > 0 && <BreakdownBar data={how} colors={TECHNITIUM_HOW_COLORS} compact />}
{!s.blockingEnabled && s.settings.blockLists.count > 0 && <div className="small text-yellow mt-2">Blocking is switched off.</div>}
{!instance.fresh && <div className="small text-yellow mt-2">The last read is old, so this may be out of date.</div>}
{instance.problems.slice(0, 2).map((p) => (
<div key={p.key} className={`small mt-1 ${p.severity === "critical" ? "text-red" : "text-yellow"}`}>
{p.message}
</div>
))}
{instance.problems.length > 2 && <div className="small text-secondary mt-1">and {instance.problems.length - 2} more</div>}
{open}
</>
);
}
/** What each group of integrations is, in a line — the groups are the sidebar's. */
const GROUP_HINTS: Record<string, string> = {
infrastructure: "The systems your servers and containers run on.",
@@ -367,6 +435,8 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
const [integrations, setIntegrations] = useState<IntegrationSummary[] | null>(null);
// How many alerts each integration has open that nobody has put aside, for the tiles of the integrations that have no widget of their own.
const [integrationAlerts, setIntegrationAlerts] = useState<Map<number, { count: number; critical: boolean }>>(new Map());
// What each Technitium DNS Server says (the same as its page), read once there is one and then every minute.
const [technitium, setTechnitium] = useState<TechnitiumInstance[] | null>(null);
const [tailscaleSummary, setTailscaleSummary] = useState<TailscaleDevicesResponse["summary"] | null>(null);
const [tailscaleExtra, setTailscaleExtra] = useState<TailscaleExtra | null>(null);
const [giteaSummary, setGiteaSummary] = useState<GiteaSummary | null>(null);
@@ -457,6 +527,19 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
.catch(() => {});
}, []);
const hasTechnitium = integrations?.some((i) => i.type === "technitium") ?? false;
useEffect(() => {
if (!hasTechnitium) return;
const load = () =>
api.technitium
.list()
.then((r) => setTechnitium(r.instances))
.catch(() => setTechnitium((current) => current ?? []));
void load();
const t = setInterval(load, 60_000);
return () => clearInterval(t);
}, [hasTechnitium]);
useEffect(() => {
const tailscale = integrations?.find((i) => i.type === "tailscale" && i.enabled);
if (!tailscale) {
@@ -1435,7 +1518,7 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
})}
{/* The integrations with no widget of their own get a small tile: whether they work, how many alerts are open, and where to look. */}
{(integrations ?? [])
.filter((i) => group.types.includes(i.type) && !WIDGETS.some((w) => w.type === i.type))
.filter((i) => group.types.includes(i.type) && !WIDGETS.some((w) => w.type === i.type) && i.type !== "technitium")
.sort((a, b) => a.name.localeCompare(b.name))
.map((i) => {
const alerts = integrationAlerts.get(i.id);
@@ -1470,6 +1553,18 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
</WidgetCard>
);
})}
{/* Technitium DNS Server has a widget of its own: the DNS test, the last day's queries and how they were answered, and what is wrong. */}
{(integrations ?? [])
.filter((i) => group.types.includes(i.type) && i.type === "technitium")
.sort((a, b) => a.name.localeCompare(b.name))
.map((i) => {
const instance = technitium?.find((x) => x.id === i.id) ?? null;
return (
<WidgetCard key={i.id} label={i.name === TYPE_LABELS[i.type] ? i.name : `${TYPE_LABELS[i.type]}: ${i.name}`} badge={technitiumBadge(i.enabled, instance)}>
<TechnitiumBody enabled={i.enabled} instance={instance} loading={technitium === null} />
</WidgetCard>
);
})}
</div>
</Fragment>
))}