Lidarr/Readarr, integration inspector, app versions, grouped alerts

Lidarr and Readarr join the shared *arr reader. Integrations get an Inspect button that
runs the reader once and shows what each request returned as shapes (never values) and
where the result is empty. Operations -> App versions compares each application's version
with its newest GitHub release (lookup off until an admin switches it on; optional alert).
The Alerts page can group by source, kind of problem or type of alert. The shared HTTP
helper no longer reuses connections (stale-socket resets). Migration 0078; docs and tests
included.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-29 20:07:36 +01:00
1 parent 551eb1597a
commit 93aaf5476d
45 files changed
+10033 -65

No files matched your search

+36 -3
View File
@@ -14,6 +14,7 @@ import {
} from "../integrations/fieldSchemas.js";
import { createIntegrationAdapter } from "../integrations/registry.js";
import { loadIntegrationConfig } from "../integrations/loadIntegration.js";
import { emptyFields, inspectCalls, shapeOf } from "../integrations/inspector.js";
import { createTailscaleAdapter, isKeyExpiringSoon } from "../integrations/tailscale/adapter.js";
import { createGiteaAdapter } from "../integrations/gitea/adapter.js";
import { createDockhandAdapter } from "../integrations/dockhand/adapter.js";
@@ -40,6 +41,7 @@ import { forgetHetzner, syncHetzner } from "../services/hetznerSync.js";
import { forgetSpeedtest, syncSpeedtest } from "../services/speedtestSync.js";
import { forgetFragnet, syncFragnet } from "../services/fragnetSync.js";
import { forgetArr, syncArr } from "../services/arrSync.js";
import { ARR_KINDS } from "../integrations/arr/adapter.js";
import { forgetAdguard, syncAdguard } from "../services/adguardSync.js";
import { forgetGrafana, syncGrafana } from "../services/grafanaSync.js";
import { forgetNextcloud, syncNextcloud } from "../services/nextcloudSync.js";
@@ -156,7 +158,7 @@ integrationsRouter.post("/", requireRole("admin"), asyncHandler(async (req, res)
if (type === "hetzner") void syncHetzner(created.id).then(() => invalidateAlertsCache());
if (type === "speedtest") void syncSpeedtest(created.id).then(() => invalidateAlertsCache());
if (type === "fragnet") void syncFragnet(created.id).then(() => invalidateAlertsCache());
if (type === "sonarr" || type === "radarr" || type === "prowlarr") void syncArr(created.id).then(() => invalidateAlertsCache());
if ((ARR_KINDS as string[]).includes(type)) void syncArr(created.id).then(() => invalidateAlertsCache());
if (type === "adguard") void syncAdguard(created.id).then(() => invalidateAlertsCache());
if (type === "grafana") void syncGrafana(created.id).then(() => invalidateAlertsCache());
if (type === "nextcloud") void syncNextcloud(created.id).then(() => invalidateAlertsCache());
@@ -274,7 +276,7 @@ integrationsRouter.patch("/:id", requireRole("admin"), asyncHandler(async (req,
if (updated.type === "hetzner" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncHetzner(updated.id).then(() => invalidateAlertsCache());
if (updated.type === "speedtest" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncSpeedtest(updated.id).then(() => invalidateAlertsCache());
if (updated.type === "fragnet" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncFragnet(updated.id).then(() => invalidateAlertsCache());
if ((updated.type === "sonarr" || updated.type === "radarr" || updated.type === "prowlarr") && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncArr(updated.id).then(() => invalidateAlertsCache());
if ((ARR_KINDS as string[]).includes(updated.type) && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncArr(updated.id).then(() => invalidateAlertsCache());
if (updated.type === "adguard" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncAdguard(updated.id).then(() => invalidateAlertsCache());
if (updated.type === "grafana" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncGrafana(updated.id).then(() => invalidateAlertsCache());
if (updated.type === "nextcloud" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncNextcloud(updated.id).then(() => invalidateAlertsCache());
@@ -340,6 +342,37 @@ integrationsRouter.post("/:id/test", requireRole("admin"), asyncHandler(async (r
res.json(result);
}));
/** How long an inspection may take: a read makes a handful of requests, each with a timeout of its own. */
const INSPECT_LIMIT_MS = 90_000;
// Runs an integration's reader once, here and now, and says what it asked, what came back (the shape of each answer — names and kinds, never values) and where what the reader made of it is empty.
// Nothing is stored. It is how a reader written from documentation is checked against the real thing: an answer with a field the reader did not expect shows up as an empty field in the result.
integrationsRouter.post("/:id/inspect", requireRole("admin"), asyncHandler(async (req, res) => {
const id = Number(req.params.id);
if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" });
const loaded = await loadIntegrationConfig(id);
if (!loaded) return res.status(404).json({ error: "not_found" });
if (!loaded.integration.enabled) return res.status(400).json({ error: "integration_disabled", message: "It is switched off." });
const adapter = createIntegrationAdapter(loaded.integration.type, loaded.config) as unknown as { read?: () => Promise<unknown> };
if (typeof adapter.read !== "function") return res.status(400).json({ error: "not_inspectable", message: "This kind of integration has no reader to inspect." });
const read = adapter.read.bind(adapter);
const started = Date.now();
const timeout = new Promise<never>((_, reject) => setTimeout(() => reject(new Error(`took more than ${INSPECT_LIMIT_MS / 1000} s`)), INSPECT_LIMIT_MS).unref());
const { calls, value, error } = await inspectCalls(() => Promise.race([read(), timeout]));
await recordAudit({ actor: req.currentUser!, category: "integration", action: "inspect", targetType: "integration", targetId: id, detail: { type: loaded.integration.type, ok: error === null } });
res.json({
type: loaded.integration.type,
name: loaded.integration.name,
ok: error === null,
error,
ms: Date.now() - started,
calls,
/** What the reader made of the answers, as a shape. */
resultShape: value === undefined ? null : shapeOf(value),
empty: value === undefined ? [] : emptyFields(value),
});
}));
integrationsRouter.delete("/:id", requireRole("admin"), asyncHandler(async (req, res) => {
const id = Number(req.params.id);
const [existing] = await db.select().from(integrations).where(eq(integrations.id, id)).limit(1);
@@ -368,7 +401,7 @@ integrationsRouter.delete("/:id", requireRole("admin"), asyncHandler(async (req,
if (existing.type === "hetzner") await forgetHetzner(id);
if (existing.type === "speedtest") await forgetSpeedtest(id);
if (existing.type === "fragnet") await forgetFragnet(id);
if (existing.type === "sonarr" || existing.type === "radarr" || existing.type === "prowlarr") await forgetArr(id);
if ((ARR_KINDS as string[]).includes(existing.type)) await forgetArr(id);
if (existing.type === "adguard") await forgetAdguard(id);
if (existing.type === "grafana") await forgetGrafana(id);
if (existing.type === "nextcloud") await forgetNextcloud(id);