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

+2
View File
@@ -73,6 +73,7 @@ import { arrRouter } from "./routes/arr.js";
import { wallRouter } from "./routes/wall.js";
import { adguardRouter } from "./routes/adguard.js";
import { grafanaRouter } from "./routes/grafana.js";
import { versionsRouter } from "./routes/versions.js";
import { costsRouter } from "./routes/costs.js";
import { nextcloudRouter } from "./routes/nextcloud.js";
import { serviceLevelsRouter } from "./routes/serviceLevels.js";
@@ -224,6 +225,7 @@ export function createApp() {
app.use("/api/wall", wallRouter);
app.use("/api/adguard", adguardRouter);
app.use("/api/grafana", grafanaRouter);
app.use("/api/versions", versionsRouter);
app.use("/api/costs", costsRouter);
app.use("/api/nextcloud", nextcloudRouter);
app.use("/api/service-levels", serviceLevelsRouter);
+15
View File
@@ -572,6 +572,8 @@ export const integrationTypes = [
"prowlarr",
"adguard",
"grafana",
"lidarr",
"readarr",
] as const;
export type IntegrationType = (typeof integrationTypes)[number];
@@ -1364,6 +1366,19 @@ export const grafanaState = sqliteTable("grafana_state", {
updatedAt: text("updated_at").notNull(), // ISO
});
// ─── The newest releases ────────────────────────────────────────────────────
// The newest release of each application there is a connected integration for, as GitHub last said (only while Operations → Versions is switched on): one row for each repository. A lookup that
// failed keeps the tag it had and says why in `error`. Read by services/appVersions.ts.
export const releaseCache = sqliteTable("release_cache", {
repo: text("repo").primaryKey(), // "owner/name"
tag: text("tag").notNull(), // the release's tag, as published ("v4.0.9.2244"); empty when none has been found
publishedAt: text("published_at"), // ISO
url: text("url"), // the release's page
checkedAt: text("checked_at").notNull(), // ISO: when it was last looked up
error: text("error"), // why the last lookup failed; null when it worked
});
// ─── NetBox ─────────────────────────────────────────────────────────────────
// How a NetBox (an integration of type "netbox") is right now, one row each, replaced at every read: its version, how many background workers are running, the counts and the IP
+2
View File
@@ -44,6 +44,7 @@ import { initFragnetSync } from "./services/fragnetSync.js";
import { initArrSync } from "./services/arrSync.js";
import { initAdguardSync } from "./services/adguardSync.js";
import { initGrafanaSync } from "./services/grafanaSync.js";
import { initVersionCheck } from "./services/appVersions.js";
import { backfillMetricRollups } from "./services/serverMetrics.js";
import { backfillEndpointHourly } from "./services/endpointChecks.js";
import { initSelfBackupScheduler } from "./services/selfBackupScheduler.js";
@@ -109,6 +110,7 @@ initFragnetSync();
initArrSync();
initAdguardSync();
initGrafanaSync();
initVersionCheck();
// The hourly and daily figures are built from what is already kept, once, the first time after they were added (in the background: nothing waits for it).
void Promise.all([backfillMetricRollups(), backfillEndpointHourly()]).catch((err) => console.error("[history] couldn't build the hourly and daily figures:", err));
+12 -8
View File
@@ -1,20 +1,24 @@
/**
* Sonarr, Radarr and Prowlarr adapter — the three speak the same API (the "*arr" family), so one adapter serves all of them, told which it is. Config: url, apiKey (the application's own: Settings →
* Sonarr, Radarr, Prowlarr, Lidarr and Readarr adapter — they speak the same API (the "*arr" family), so one adapter serves all of them, told which it is. Config: url, apiKey (the application's own: Settings →
* General → Security → API Key; sent as `X-Api-Key`) and optionally insecure.
*
* Reading only: what the application says is wrong with itself (`/health`), its download queue (`/queue`: what is downloading, what is stuck or failed and why), the disks it uses
* (`/diskspace`), how many wanted items are missing (`/wanted/missing`, Sonarr and Radarr) and — for Prowlarr — its indexers and which of them it has switched off after failures (`/indexer`,
* (`/diskspace`), how many wanted items are missing (`/wanted/missing`, all but Prowlarr) and — for Prowlarr — its indexers and which of them it has switched off after failures (`/indexer`,
* `/indexerstatus`). Nothing is sent but GET requests: no search is started, nothing is grabbed, removed or changed.
*
* Sonarr and Radarr answer under `/api/v3`, Prowlarr under `/api/v1`. Endpoints and field names are from their published OpenAPI files and source (HealthResource, QueueResource,
* Sonarr and Radarr answer under `/api/v3`; Prowlarr, Lidarr and Readarr under `/api/v1`. Endpoints and field names are from their published OpenAPI files and source (HealthResource, QueueResource,
* DiskSpaceResource, IndexerStatusResource) and have not been checked against live installs here; every field is read defensively.
*/
import { requestJson } from "../httpJson.js";
import { withDiagLogging } from "../../services/diagLog.js";
export type ArrKind = "sonarr" | "radarr" | "prowlarr";
export const ARR_KINDS: ArrKind[] = ["sonarr", "radarr", "prowlarr"];
export const ARR_NAMES: Record<ArrKind, string> = { sonarr: "Sonarr", radarr: "Radarr", prowlarr: "Prowlarr" };
export type ArrKind = "sonarr" | "radarr" | "prowlarr" | "lidarr" | "readarr";
export const ARR_KINDS: ArrKind[] = ["sonarr", "radarr", "prowlarr", "lidarr", "readarr"];
export const ARR_NAMES: Record<ArrKind, string> = { sonarr: "Sonarr", radarr: "Radarr", prowlarr: "Prowlarr", lidarr: "Lidarr", readarr: "Readarr" };
/** The version of the API each answers under. */
const API_VERSION: Record<ArrKind, string> = { sonarr: "v3", radarr: "v3", prowlarr: "v1", lidarr: "v1", readarr: "v1" };
/** What each calls the items in its queue that it cannot match to anything it manages (asked for, so the queue is whole). */
const QUEUE_UNKNOWN: Record<ArrKind, string> = { sonarr: "&includeUnknownSeriesItems=true", radarr: "&includeUnknownMovieItems=true", prowlarr: "", lidarr: "&includeUnknownArtistItems=true", readarr: "&includeUnknownAuthorItems=true" };
export interface ArrConfig {
url: string;
@@ -181,7 +185,7 @@ export function parseIndexers(indexers: unknown, status: unknown): ArrIndexer[]
}
export function createArrAdapter(kind: ArrKind, config: ArrConfig): ArrAdapter {
const base = `${String(config.url ?? "").trim().replace(/\/+$/, "")}/api/${kind === "prowlarr" ? "v1" : "v3"}`;
const base = `${String(config.url ?? "").trim().replace(/\/+$/, "")}/api/${API_VERSION[kind]}`;
const insecure = config.insecure === true;
const headers = { "X-Api-Key": String(config.apiKey ?? "").trim(), Accept: "application/json" };
const name = ARR_NAMES[kind];
@@ -207,7 +211,7 @@ export function createArrAdapter(kind: ArrKind, config: ArrConfig): ArrAdapter {
// The status and the health must work: they are what says it is there and what is wrong.
const status = obj(await get("/system/status"));
const health = parseHealth(await get("/health"));
const include = kind === "sonarr" ? "&includeUnknownSeriesItems=true" : kind === "radarr" ? "&includeUnknownMovieItems=true" : "";
const include = QUEUE_UNKNOWN[kind];
const [queue, disks, missing, indexers, indexerStatus] = await Promise.all([
kind === "prowlarr" ? Promise.resolve(null) : soft(async () => parseQueue(await get(`/queue?page=1&pageSize=${QUEUE_PAGE}${include}`))),
soft(async () => parseDisks(await get("/diskspace"))),
+10
View File
@@ -124,6 +124,16 @@ export const INTEGRATION_FIELDS: Partial<Record<IntegrationType, IntegrationFiel
{ key: "apiKey", label: "API key", secret: true, type: "password", placeholder: "Settings → General → Security → API Key" },
{ key: "insecure", label: "Allow self-signed certificate", secret: false, type: "checkbox" },
],
lidarr: [
{ key: "url", label: "Lidarr URL", secret: false, placeholder: "http://lidarr.example.lan:8686" },
{ key: "apiKey", label: "API key", secret: true, type: "password", placeholder: "Settings → General → Security → API Key" },
{ key: "insecure", label: "Allow self-signed certificate", secret: false, type: "checkbox" },
],
readarr: [
{ key: "url", label: "Readarr URL", secret: false, placeholder: "http://readarr.example.lan:8787" },
{ key: "apiKey", label: "API key", secret: true, type: "password", placeholder: "Settings → General → Security → API Key" },
{ key: "insecure", label: "Allow self-signed certificate", secret: false, type: "checkbox" },
],
prowlarr: [
{ key: "url", label: "Prowlarr URL", secret: false, placeholder: "http://prowlarr.example.lan:9696" },
{ key: "apiKey", label: "API key", secret: true, type: "password", placeholder: "Settings → General → Security → API Key" },
+11 -1
View File
@@ -4,6 +4,7 @@
*/
import * as http from "node:http";
import * as https from "node:https";
import { isInspecting, pathForReport, recordCall, shapeOf } from "./inspector.js";
export interface JsonResponse {
status: number;
@@ -27,6 +28,8 @@ export function requestJson(url: string, opts: { method?: "GET" | "POST"; header
const lib = isHttps ? https : http;
const payload = opts.body === undefined ? null : JSON.stringify(opts.body);
const limit = opts.timeoutMs ?? TIMEOUT_MS;
const started = Date.now();
const method = opts.method ?? "GET";
const req = lib.request(
{
hostname: parsed.hostname,
@@ -35,6 +38,8 @@ export function requestJson(url: string, opts: { method?: "GET" | "POST"; header
method: opts.method ?? "GET",
headers: { Accept: "application/json", ...(payload ? { "Content-Type": "application/json", "Content-Length": String(Buffer.byteLength(payload)) } : {}), ...opts.headers },
timeout: limit,
// A new connection for each request, not one kept from the last: a system that has closed an idle connection (most do, within seconds) would otherwise answer the next read, minutes later, with a reset.
agent: false,
...(isHttps ? { rejectUnauthorized: !opts.insecure } : {}),
},
(res) => {
@@ -50,12 +55,17 @@ export function requestJson(url: string, opts: { method?: "GET" | "POST"; header
} catch {
// not JSON: the text is still there
}
// While the inspector runs a read, what was asked and the shape of the answer (never its values) are written down.
if (isInspecting()) recordCall({ method, path: pathForReport(parsed), status: res.statusCode ?? 0, ms: Date.now() - started, bytes: Buffer.byteLength(text), shape: json === null ? null : shapeOf(json) });
resolve({ status: res.statusCode ?? 0, json, text, headers: res.headers });
});
},
);
req.on("timeout", () => req.destroy(new Error(`timed out after ${limit / 1000}s`)));
req.on("error", reject);
req.on("error", (err) => {
if (isInspecting()) recordCall({ method, path: pathForReport(parsed), status: 0, ms: Date.now() - started, bytes: 0, shape: null, error: err.message });
reject(err);
});
if (payload) req.write(payload);
req.end();
});
+123
View File
@@ -0,0 +1,123 @@
/**
* What lets an integration be inspected: while a read is run for the inspector, every request the shared HTTP helper (httpJson.ts) makes is written down — what was asked, what came back, how long
* it took, and the *shape* of the answer — so that what an integration's reader makes of an answer can be put beside what the answer was. Only shapes are kept: the names and kinds of the values
* (`{ id: number, name: string, tags: array(3) of string }`), never the values themselves, so a report can be copied into a message without giving away what the system holds.
*/
import { AsyncLocalStorage } from "node:async_hooks";
export interface InspectedCall {
method: string;
/** The path, with the names of the query parameters but not their values. */
path: string;
/** 0 when there was no answer (a refused connection, a timeout). */
status: number;
ms: number;
bytes: number;
/** What the answer looked like; null when it was not JSON or there was none. */
shape: string | null;
error?: string;
}
const store = new AsyncLocalStorage<InspectedCall[]>();
export const isInspecting = (): boolean => store.getStore() !== undefined;
export function recordCall(call: InspectedCall): void {
store.getStore()?.push(call);
}
/** Runs something and returns every request the helper made while it ran, whatever happened to it. */
export async function inspectCalls<T>(run: () => Promise<T>): Promise<{ calls: InspectedCall[]; value: T | undefined; error: string | null }> {
const calls: InspectedCall[] = [];
return store.run(calls, async () => {
try {
return { calls, value: await run(), error: null };
} catch (err) {
return { calls, value: undefined, error: err instanceof Error ? err.message : String(err) };
}
});
}
/** Pure: a path for a report — the query's parameter names, not what they were set to. */
export function pathForReport(url: URL): string {
const names = [...new Set([...url.searchParams.keys()])];
return url.pathname + (names.length > 0 ? `?${names.join("&")}` : "");
}
const MAX_SHAPE = 1800;
const MAX_KEYS = 30;
const MAX_DEPTH = 3;
const SAMPLE = 20;
const kindOf = (v: unknown): string => (v === null ? "null" : Array.isArray(v) ? "array" : typeof v);
function describe(value: unknown, depth: number): string {
if (Array.isArray(value)) {
if (value.length === 0) return "array(0)";
const sample = value.slice(0, SAMPLE);
const objects = sample.filter((x) => x !== null && typeof x === "object" && !Array.isArray(x)) as Record<string, unknown>[];
if (objects.length === sample.length && depth < MAX_DEPTH) {
// Objects: the keys of all of them, marked with ? where some of them lack it.
const keys = new Map<string, { count: number; first: unknown }>();
for (const o of objects) for (const [k, v] of Object.entries(o)) keys.set(k, { count: (keys.get(k)?.count ?? 0) + 1, first: keys.get(k)?.first ?? v });
const parts = [...keys.entries()].slice(0, MAX_KEYS).map(([k, { count, first }]) => `${k}${count < objects.length ? "?" : ""}: ${describe(first, depth + 1)}`);
return `array(${value.length}) of { ${parts.join(", ")}${keys.size > MAX_KEYS ? ", …" : ""} }`;
}
const kinds = [...new Set(sample.map(kindOf))];
return `array(${value.length}) of ${kinds.join(" | ")}`;
}
if (value !== null && typeof value === "object") {
if (depth >= MAX_DEPTH) return "object";
const entries = Object.entries(value as Record<string, unknown>);
if (entries.length === 0) return "{}";
return `{ ${entries
.slice(0, MAX_KEYS)
.map(([k, v]) => `${k}: ${describe(v, depth + 1)}`)
.join(", ")}${entries.length > MAX_KEYS ? ", …" : ""} }`;
}
return kindOf(value);
}
/** Pure: what a JSON value looks like — its keys and the kinds of what they hold, to three levels, never the values. */
export function shapeOf(value: unknown): string {
const text = describe(value, 0);
return text.length > MAX_SHAPE ? `${text.slice(0, MAX_SHAPE)} …` : text;
}
export interface EmptyField {
path: string;
/** null: the field is null; text: it is an empty string; list: an empty list; every-item: null in every item of a list. */
what: "null" | "text" | "list" | "every-item";
}
/**
* Pure: the places in what a reader made of an answer where there is nothing — a field that is null, an empty text, an empty list, or a field that is null in *every* item of a list. A reader
* that expects a field the system names differently ends up here: it is where a mismatch shows. (Something being empty is often right — no containers, nothing wrong — which is why this is
* a list to look at, not a verdict.)
*/
export function emptyFields(value: unknown, limit = 40): EmptyField[] {
const out: EmptyField[] = [];
const add = (path: string, what: EmptyField["what"]) => {
if (out.length < limit) out.push({ path: path || "(the result)", what });
};
const walk = (v: unknown, path: string, depth: number) => {
if (out.length >= limit || depth > MAX_DEPTH) return;
if (v === null || v === undefined) return add(path, "null");
if (typeof v === "string") return v.trim() === "" ? add(path, "text") : undefined;
if (Array.isArray(v)) {
if (v.length === 0) return add(path, "list");
const items = v.slice(0, 50).filter((x) => x !== null && typeof x === "object" && !Array.isArray(x)) as Record<string, unknown>[];
if (items.length === 0 || depth >= MAX_DEPTH) return;
const keys = new Set(items.flatMap((o) => Object.keys(o)));
for (const k of keys) {
const values = items.map((o) => o[k]);
if (values.every((x) => x === null || x === undefined)) add(`${path}[].${k}`, "every-item");
else if (values.some((x) => x !== null && typeof x === "object")) walk(values.find((x) => x !== null && typeof x === "object"), `${path}[].${k}`, depth + 1);
}
return;
}
if (typeof v === "object") for (const [k, x] of Object.entries(v as Record<string, unknown>)) walk(x, path ? `${path}.${k}` : k, depth + 1);
};
walk(value, "", 0);
return out;
}
+2
View File
@@ -91,6 +91,8 @@ export function createIntegrationAdapter(type: IntegrationType, config: Integrat
case "sonarr":
case "radarr":
case "prowlarr":
case "lidarr":
case "readarr":
return createArrAdapter(type, config as any);
case "adguard":
return createAdguardAdapter(config as any);
+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);
+45
View File
@@ -0,0 +1,45 @@
import { Router } from "express";
import { z } from "zod";
import { requireAuth, requireRole } from "../auth/middleware.js";
import { recordAudit } from "../services/audit.js";
import { invalidateAlertsCache } from "../services/alerts.js";
import { refreshReleases, versionRows } from "../services/appVersions.js";
import { getSettings, updateSettings } from "../services/settingsStore.js";
import { asyncHandler } from "../utils/asyncHandler.js";
export const versionsRouter = Router();
versionsRouter.use(requireAuth);
async function payload() {
const { versionChecks } = await getSettings();
const rows = await versionRows();
const checked = rows.map((r) => r.checkedAt).filter((c): c is string => c !== null).sort();
return { enabled: versionChecks.enabled, alertAfterDays: versionChecks.alertAfterDays, lastCheckedAt: checked.length > 0 ? checked[checked.length - 1] : null, rows };
}
/** What each connected application runs against the newest release kept for it. Everyone signed in can see it; nothing is asked of GitHub by looking. */
versionsRouter.get("/", asyncHandler(async (_req, res) => {
res.json(await payload());
}));
const settingsSchema = z.object({ enabled: z.boolean(), alertAfterDays: z.number().int().min(0).max(365) });
/** Switches the lookup of newest releases on or off, and says after how many days a newer release is a warning (0: never). Switching it on looks them up at once. */
versionsRouter.put("/settings", requireRole("admin"), asyncHandler(async (req, res) => {
const parsed = settingsSchema.safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "Say whether to look up the newest releases, and after how many days a newer one is a warning.", details: parsed.error.flatten() });
const before = (await getSettings()).versionChecks;
await updateSettings({ versionChecks: parsed.data });
await recordAudit({ actor: req.currentUser!, category: "settings", action: "update", targetType: "versionChecks", detail: { enabled: parsed.data.enabled, alertAfterDays: parsed.data.alertAfterDays } });
if (parsed.data.enabled && !before.enabled) await refreshReleases(new Date(), true).catch(() => undefined);
invalidateAlertsCache();
res.json(await payload());
}));
/** Looks up the newest releases now, instead of at the next daily pass. Only while the lookup is switched on. */
versionsRouter.post("/refresh", requireRole("admin"), asyncHandler(async (_req, res) => {
if (!(await getSettings()).versionChecks.enabled) return res.status(400).json({ error: "switched_off", message: "Looking up the newest releases is switched off." });
const result = await refreshReleases(new Date(), true);
invalidateAlertsCache();
res.json({ ...(await payload()), result });
}));
+8 -3
View File
@@ -88,8 +88,11 @@ const SOURCES: Record<string, { label: string; link: string }> = {
fragnet: { label: "Fragnet", link: "/game-servers" },
sonarr: { label: "Sonarr", link: "/media" },
radarr: { label: "Radarr", link: "/media" },
lidarr: { label: "Lidarr", link: "/media" },
readarr: { label: "Readarr", link: "/media" },
prowlarr: { label: "Prowlarr", link: "/media" },
adguard: { label: "AdGuard Home", link: "/adguard" },
versions: { label: "Versions", link: "/versions" },
grafana: { label: "Grafana", link: "/grafana" },
secrets: { label: "Secrets", link: "/secrets" },
domains: { label: "Domains", link: "/dns?view=domains" },
@@ -133,11 +136,13 @@ function originOfConditionKey(key: string): { type: string; id: number | null; c
if (m) return { type: "speedtest", id: Number(m[1]), category: "monitoring" };
m = /^hetzner-(off|stuck|rescue|traffic|forecast|backup|lb|cert|fip):(\d+):/.exec(key);
if (m) return { type: "hetzner", id: Number(m[2]), category: m[1] === "traffic" || m[1] === "forecast" ? "monitoring" : m[1] === "backup" ? "backup" : "services" };
m = /^version-behind:(\d+)$/.exec(key);
if (m) return { type: "versions", id: Number(m[1]), category: "updates" };
m = /^adguard-(stopped|dns|protection|filters):(\d+)/.exec(key);
if (m) return { type: "adguard", id: Number(m[2]), category: m[1] === "stopped" || m[1] === "dns" ? "services" : "monitoring" };
m = /^grafana-(firing|rule-error|ds):(\d+):/.exec(key);
if (m) return { type: "grafana", id: Number(m[2]), category: m[1] === "ds" ? "integration" : "monitoring" };
m = /^(sonarr|radarr|prowlarr)-(health|queue|disk):(\d+)/.exec(key);
m = /^(sonarr|radarr|prowlarr|lidarr|readarr)-(health|queue|disk):(\d+)/.exec(key);
if (m) return { type: m[1], id: Number(m[3]), category: m[2] === "disk" ? "disk" : "services" };
m = /^fragnet-(disk|memory|backup):(\d+):/.exec(key);
if (m) return { type: "fragnet", id: Number(m[2]), category: m[1] === "disk" ? "disk" : m[1] === "backup" ? "backup" : "monitoring" };
@@ -283,7 +288,7 @@ export async function collectAlerts(): Promise<AlertsReport> {
type: origin.type,
message: c.message,
key: c.key,
link: origin.type === "server" && origin.id !== null ? `/servers/${origin.id}${/^(failed-units|smart|zfs):/.test(c.key) ? "?view=health" : c.key.startsWith("new-port:") ? "?view=network" : c.key.startsWith("rule:") || c.key.startsWith("baseline:") ? "?view=history" : ""}` : origin.type === "unifi" ? "/network/devices" : origin.type === "ups" ? "/ups" : origin.type === "slo" ? "/service-levels" : origin.type === "dockhand" ? "/docker" : origin.type === "duplicati" ? "/duplicati" : origin.type === "jellyfin" ? "/jellyfin" : origin.type === "authentik" ? "/authentik" : origin.type === "prometheus" ? "/prometheus" : origin.type === "immich" ? "/immich" : origin.type === "paperless" ? "/paperless" : origin.type === "nextcloud" ? "/nextcloud" : origin.type === "netbox" ? "/netbox" : origin.type === "n8n" ? "/n8n" : origin.type === "hetzner" ? "/hetzner" : origin.type === "speedtest" ? "/speedtest" : origin.type === "fragnet" ? "/game-servers" : origin.type === "sonarr" || origin.type === "radarr" || origin.type === "prowlarr" ? "/media" : origin.type === "adguard" ? "/adguard" : origin.type === "grafana" ? "/grafana" : undefined,
link: origin.type === "server" && origin.id !== null ? `/servers/${origin.id}${/^(failed-units|smart|zfs):/.test(c.key) ? "?view=health" : c.key.startsWith("new-port:") ? "?view=network" : c.key.startsWith("rule:") || c.key.startsWith("baseline:") ? "?view=history" : ""}` : origin.type === "unifi" ? "/network/devices" : origin.type === "ups" ? "/ups" : origin.type === "slo" ? "/service-levels" : origin.type === "dockhand" ? "/docker" : origin.type === "duplicati" ? "/duplicati" : origin.type === "jellyfin" ? "/jellyfin" : origin.type === "authentik" ? "/authentik" : origin.type === "prometheus" ? "/prometheus" : origin.type === "immich" ? "/immich" : origin.type === "paperless" ? "/paperless" : origin.type === "nextcloud" ? "/nextcloud" : origin.type === "netbox" ? "/netbox" : origin.type === "n8n" ? "/n8n" : origin.type === "hetzner" ? "/hetzner" : origin.type === "speedtest" ? "/speedtest" : origin.type === "fragnet" ? "/game-servers" : origin.type === "sonarr" || origin.type === "radarr" || origin.type === "prowlarr" || origin.type === "lidarr" || origin.type === "readarr" ? "/media" : origin.type === "adguard" ? "/adguard" : origin.type === "grafana" ? "/grafana" : undefined,
silenced: subject !== null && subjects.has(subject), target: targetOfSubject(subject),
});
}
@@ -293,7 +298,7 @@ export async function collectAlerts(): Promise<AlertsReport> {
if (held.has("slo")) cannotCheck("Service-level targets", "couldn't be judged — see the server log", "Server and storage health");
if (held.has("server:baseline")) cannotCheck("What is usual for the time", "couldn't be judged — see the server log", "Server and storage health");
for (const h of held) {
const m = /^(proxmox|synology|unifi|ups|dockhand|jellyfin|authentik|prometheus|immich|paperless|nextcloud|netbox|n8n|hetzner|speedtest|fragnet|sonarr|radarr|prowlarr|adguard|grafana):(\d+)(?::(.+))?$/.exec(h);
const m = /^(proxmox|synology|unifi|ups|dockhand|jellyfin|authentik|prometheus|immich|paperless|nextcloud|netbox|n8n|hetzner|speedtest|fragnet|sonarr|radarr|prowlarr|lidarr|readarr|adguard|grafana):(\d+)(?::(.+))?$/.exec(h);
if (!m || (m[3] && held.has(`${m[1]}:${m[2]}`))) continue;
const row = intById.get(Number(m[2]));
cannotCheck(`${SOURCES[m[1]].label} “${row?.name ?? `#${m[2]}`}”${m[3] === "vuln" ? " (vulnerability scans)" : m[3] === "images" ? " (age of the images)" : m[3] ? ` (node ${m[3]})` : ""}`, "couldn't be read — see the Diagnostic Log", "Server and storage health");
+207
View File
@@ -0,0 +1,207 @@
/**
* Which version each connected application runs — as its integration last read it — against the newest release of that application, so that what has fallen behind can be seen in one
* list. The newest release is asked of GitHub (`GET /repos/{owner}/{repo}/releases/latest`, which leaves out pre-releases and drafts) once a day for each application there is a connected
* integration for, and kept. **Nothing is asked unless the setting is on** (Operations → Versions): that is the only thing in this app that calls out to an address of its own choosing.
*
* Versions are compared by their first three numbers (a build number after them is ignored), after the usual prefixes — `v`, `n8n@`, `version/` — are taken off. A difference in the first number is a
* *major* update, in the second a *minor* one, in the third a *patch*; what is newer on this machine than the newest release is *ahead* (a beta, a nightly). With *alert after* days set, an
* application that has had a newer release out for that long raises a warning (and one that is merely a day behind does not).
*/
import { eq, inArray } from "drizzle-orm";
import { db } from "../db/client.js";
import { adguardState, arrState, authentikState, grafanaState, immichState, integrations, jellyfinState, netboxState, nextcloudState, paperlessState, prometheusState, releaseCache } from "../db/schema.js";
import { requestJson } from "../integrations/httpJson.js";
import { getSettings } from "./settingsStore.js";
export const CHECK_INTERVAL_MS = 12 * 60 * 60_000;
/** A release looked up more recently than this is not looked up again (unless asked to). */
export const FRESH_MS = 6 * 60 * 60_000;
const DAY = 86_400_000;
/** Where the newest release of each kind of application is published. A kind with no entry (Proxmox, Synology, Hetzner …) has no version to compare. */
export const RELEASE_SOURCES: Record<string, { repo: string; label: string }> = {
sonarr: { repo: "Sonarr/Sonarr", label: "Sonarr" },
radarr: { repo: "Radarr/Radarr", label: "Radarr" },
prowlarr: { repo: "Prowlarr/Prowlarr", label: "Prowlarr" },
lidarr: { repo: "Lidarr/Lidarr", label: "Lidarr" },
readarr: { repo: "Readarr/Readarr", label: "Readarr" },
adguard: { repo: "AdguardTeam/AdGuardHome", label: "AdGuard Home" },
grafana: { repo: "grafana/grafana", label: "Grafana" },
jellyfin: { repo: "jellyfin/jellyfin", label: "Jellyfin" },
immich: { repo: "immich-app/immich", label: "Immich" },
paperless: { repo: "paperless-ngx/paperless-ngx", label: "Paperless-ngx" },
nextcloud: { repo: "nextcloud/server", label: "Nextcloud" },
netbox: { repo: "netbox-community/netbox", label: "NetBox" },
authentik: { repo: "goauthentik/authentik", label: "Authentik" },
prometheus: { repo: "prometheus/prometheus", label: "Prometheus" },
};
export type Lag = "same" | "patch" | "minor" | "major" | "ahead" | "unknown";
/** Pure: the first three numbers of a version, after a prefix such as "v", "n8n@" or "version/"; null when there is no number. */
export function parseVersion(text: string | null | undefined): [number, number, number] | null {
if (!text) return null;
const last = String(text).split(/[@/]/).pop() ?? "";
const m = /^[^0-9]*(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(last);
if (!m) return null;
return [Number(m[1]), Number(m[2] ?? 0), Number(m[3] ?? 0)];
}
/** Pure: how far the running version is behind the newest release. */
export function lagOf(running: string | null | undefined, latest: string | null | undefined): Lag {
const a = parseVersion(running);
const b = parseVersion(latest);
if (!a || !b) return "unknown";
for (let i = 0; i < 3; i++) {
if (a[i] === b[i]) continue;
if (a[i] > b[i]) return "ahead";
return i === 0 ? "major" : i === 1 ? "minor" : "patch";
}
return "same";
}
export interface LatestRelease {
tag: string;
publishedAt: string | null;
url: string | null;
}
type Fetcher = (repo: string) => Promise<LatestRelease>;
/** Asks GitHub for the newest release of a repository. Throws, with the reason, when it cannot say. */
async function githubLatest(repo: string): Promise<LatestRelease> {
const res = await requestJson(`https://api.github.com/repos/${repo}/releases/latest`, { headers: { Accept: "application/vnd.github+json", "User-Agent": "Homelab-Manager" } });
if (res.status === 403 || res.status === 429) throw new Error("GitHub's limit on requests without a sign-in was reached — it is tried again later");
if (res.status === 404) throw new Error("GitHub lists no releases for it");
if (res.status < 200 || res.status >= 300 || res.json === null || typeof res.json !== "object") throw new Error(`GitHub answered with HTTP ${res.status}`);
const o = res.json as Record<string, unknown>;
const tag = typeof o.tag_name === "string" && o.tag_name.trim() !== "" ? o.tag_name.trim() : null;
if (!tag) throw new Error("GitHub's answer has no release tag");
const at = typeof o.published_at === "string" && Number.isFinite(Date.parse(o.published_at)) ? new Date(o.published_at).toISOString() : null;
return { tag, publishedAt: at, url: typeof o.html_url === "string" ? o.html_url : null };
}
let fetcher: Fetcher = githubLatest;
/** For tests: what answers "what is the newest release of this" instead of GitHub. */
export function setReleaseFetcherForTests(f: Fetcher | null): void {
fetcher = f ?? githubLatest;
}
/** The versions the integrations last read, by integration id. */
async function readVersions(): Promise<Map<number, string>> {
const out = new Map<number, string>();
const tables = [arrState, adguardState, grafanaState, nextcloudState, netboxState, paperlessState, immichState, prometheusState, authentikState, jellyfinState];
for (const t of tables) {
for (const r of await db.select({ id: t.integrationId, version: t.version }).from(t)) if (r.version) out.set(r.id, r.version);
}
return out;
}
export interface VersionRow {
integrationId: number;
type: string;
label: string;
name: string;
running: string;
latest: { tag: string; publishedAt: string | null; url: string | null } | null;
/** The reason the newest release could not be looked up, when it could not. */
lookupError: string | null;
lag: Lag;
/** How many days the newer release has been out; null when it is not behind or the date is not known. */
daysOut: number | null;
checkedAt: string | null;
}
/** What each connected application runs against the newest release kept for it. Reads only what is stored: nothing is asked of GitHub here. */
export async function versionRows(nowMs: number = Date.now()): Promise<VersionRow[]> {
const rows = await db.select({ id: integrations.id, type: integrations.type, name: integrations.name }).from(integrations).where(eq(integrations.enabled, true));
const mine = rows.filter((r) => RELEASE_SOURCES[r.type]);
if (mine.length === 0) return [];
const [versions, cached] = await Promise.all([readVersions(), db.select().from(releaseCache).where(inArray(releaseCache.repo, [...new Set(mine.map((r) => RELEASE_SOURCES[r.type].repo))]))]);
const byRepo = new Map(cached.map((c) => [c.repo, c]));
const out: VersionRow[] = [];
for (const r of mine) {
const running = versions.get(r.id);
if (!running) continue;
const src = RELEASE_SOURCES[r.type];
const c = byRepo.get(src.repo);
const latest = c?.tag ? { tag: c.tag, publishedAt: c.publishedAt, url: c.url } : null;
const lag = lagOf(running, latest?.tag);
out.push({
integrationId: r.id,
type: r.type,
label: src.label,
name: r.name,
running,
latest,
lookupError: c?.error ?? null,
lag,
daysOut: latest?.publishedAt && (lag === "patch" || lag === "minor" || lag === "major") ? Math.max(0, Math.floor((nowMs - Date.parse(latest.publishedAt)) / DAY)) : null,
checkedAt: c?.checkedAt ?? null,
});
}
return out.sort((a, b) => a.label.localeCompare(b.label) || a.name.localeCompare(b.name));
}
/** Looks up the newest release of every application there is a connected integration for, and keeps it. A repository looked up lately is left alone unless `force`; one that cannot be looked up keeps what it had, with the reason. */
export async function refreshReleases(now: Date = new Date(), force = false): Promise<{ checked: number; failed: number }> {
// Only for an application whose version has been read: the newest release of one that has not is of no use yet.
const [rows, versions] = await Promise.all([db.select({ id: integrations.id, type: integrations.type }).from(integrations).where(eq(integrations.enabled, true)), readVersions()]);
const repos = [...new Set(rows.filter((r) => RELEASE_SOURCES[r.type] && versions.has(r.id)).map((r) => RELEASE_SOURCES[r.type].repo))];
const cached = new Map((await db.select().from(releaseCache)).map((c) => [c.repo, c]));
let checked = 0;
let failed = 0;
for (const repo of repos) {
const known = cached.get(repo);
if (!force && known && now.getTime() - Date.parse(known.checkedAt) < FRESH_MS && !known.error) continue;
try {
const l = await fetcher(repo);
const values = { tag: l.tag, publishedAt: l.publishedAt, url: l.url, checkedAt: now.toISOString(), error: null };
await db.insert(releaseCache).values({ repo, ...values }).onConflictDoUpdate({ target: releaseCache.repo, set: values });
checked++;
} catch (err) {
failed++;
const values = { checkedAt: now.toISOString(), error: err instanceof Error ? err.message : String(err) };
await db.insert(releaseCache).values({ repo, tag: known?.tag ?? "", publishedAt: known?.publishedAt ?? null, url: known?.url ?? null, ...values }).onConflictDoUpdate({ target: releaseCache.repo, set: values });
console.error(`[versions] couldn't look up ${repo}:`, values.error);
}
}
return { checked, failed };
}
export interface VersionProblem {
key: string;
message: string;
severity: "warning";
}
/** Pure: an application that has had a newer release out for `alertAfterDays` or more is a warning; 0 turns it off. */
export function versionProblems(rows: VersionRow[], alertAfterDays: number): VersionProblem[] {
if (alertAfterDays <= 0) return [];
const out: VersionProblem[] = [];
for (const r of rows) {
if (!r.latest || r.daysOut === null || r.daysOut < alertAfterDays) continue;
out.push({
key: `version-behind:${r.integrationId}`,
severity: "warning",
message: `${r.name}: ${r.label} ${r.running} is running; ${r.latest.tag} came out ${r.daysOut} days ago (${r.lag === "patch" ? "a patch" : r.lag === "minor" ? "a minor update" : "a new major version"})`,
});
}
return out;
}
let timer: ReturnType<typeof setInterval> | null = null;
export function initVersionCheck(): void {
if (timer) return;
const pass = async () => {
try {
if ((await getSettings()).versionChecks.enabled) await refreshReleases();
} catch (err) {
console.error("[versions] pass failed:", err);
}
};
timer = setInterval(() => void pass(), CHECK_INTERVAL_MS);
setTimeout(() => void pass(), 3 * 60_000);
console.log(`[versions] looking up the newest releases every ${CHECK_INTERVAL_MS / 3_600_000} hours, when switched on`);
}
+17
View File
@@ -32,6 +32,7 @@ import { dockerImageAgeProblems, dockerVulnProblems, dockerVulnSyncStatuses, isD
import { expectedOf as speedtestExpected, isSpeedtestFresh, recentResults as recentSpeedtestResults, speedtestProblems, speedtestSyncStatuses, type SpeedtestProblem } from "./speedtestSync.js";
import { hetznerProblems, hetznerSyncStatuses, imagesOf as hetznerImagesOf, loadBalancersOf as hetznerLoadBalancersOf, floatingIpsOf as hetznerFloatingIpsOf, certificatesOf as hetznerCertificatesOf, isHetznerFresh, serversOf as hetznerServersOf, type HetznerProblem } from "./hetznerSync.js";
import { ARR_KINDS, type ArrKind } from "../integrations/arr/adapter.js";
import { versionProblems, versionRows, type VersionProblem } from "./appVersions.js";
import { adguardProblems, adguardSyncStatuses, isAdguardFresh, storedOf as adguardStoredOf, type AdguardProblem } from "./adguardSync.js";
import { grafanaProblems, grafanaSyncStatuses, isGrafanaFresh, storedOf as grafanaStoredOf, type GrafanaProblem } from "./grafanaSync.js";
import { arrProblems, arrSyncStatuses, isArrFresh, storedOf as arrStoredOf, type ArrProblem } from "./arrSync.js";
@@ -138,6 +139,8 @@ export interface HealthSnapshot {
arr?: { integrationId: number; kind: ArrKind; problems: ArrProblem[] }[];
/** What is wrong with each AdGuard Home (DNS not running or not answering, protection left off, filter lists not updating), only while that reading is recent (services/adguardSync.ts). */
adguard?: { integrationId: number; problems: AdguardProblem[] }[];
/** Applications a newer release of which has been out for the number of days set (services/appVersions.ts), only while the lookup of releases is on. */
versions?: VersionProblem[];
/** What is wrong with each Grafana (rules firing or failing, data sources failing their check), only while that reading is recent (services/grafanaSync.ts). */
grafana?: { integrationId: number; problems: GrafanaProblem[] }[];
/** Containers to leave alone. */
@@ -281,6 +284,9 @@ export function evaluateHealth(snapshot: HealthSnapshot, thresholds: Thresholds,
// Speedtest Tracker: the internet slower than it is sold at, speed tests that keep failing.
for (const s of snapshot.speedtest ?? []) for (const p of s.problems) out.push({ key: p.key, source: `speedtest:${s.integrationId}`, message: p.message, severity: p.severity });
// Applications that have fallen behind their newest release.
for (const p of snapshot.versions ?? []) out.push({ key: p.key, source: "versions", message: p.message, severity: p.severity });
// AdGuard Home and Grafana.
for (const a of snapshot.adguard ?? []) for (const p of a.problems) out.push({ key: p.key, source: `adguard:${a.integrationId}`, message: p.message, severity: p.severity });
for (const g of snapshot.grafana ?? []) for (const p of g.problems) out.push({ key: p.key, source: `grafana:${g.integrationId}`, message: p.message, severity: p.severity });
@@ -557,6 +563,17 @@ export async function collectSnapshot(): Promise<{ snapshot: HealthSnapshot; hel
console.error("[health] couldn't judge Speedtest Tracker:", err instanceof Error ? err.message : err);
}
// The newest releases, as the daily lookup stored them (nothing is asked of GitHub here), only with the lookup and the alert switched on.
try {
const { versionChecks } = await getSettings();
if (versionChecks.enabled && versionChecks.alertAfterDays > 0) {
const problems = versionProblems(await versionRows(), versionChecks.alertAfterDays);
if (problems.length > 0) snapshot.versions = problems;
}
} catch (err) {
console.error("[health] couldn't judge the versions:", err instanceof Error ? err.message : err);
}
// AdGuard Home: read by its own pass every two minutes; what is judged is what that pass stored, and only while it is recent.
try {
const rowsG = await db.select({ id: integrations.id, name: integrations.name }).from(integrations).where(and(eq(integrations.type, "adguard"), eq(integrations.enabled, true)));
+1 -1
View File
@@ -4,7 +4,7 @@
*/
export const INTEGRATION_GROUPS: { id: string; label: string; types: string[] }[] = [
{ id: "infrastructure", label: "Infrastructure", types: ["proxmox", "synology", "dockhand", "hetzner", "fragnet", "tailscale"] },
{ id: "apps", label: "Apps", types: ["homeassistant", "jellyfin", "sonarr", "radarr", "prowlarr", "immich", "paperless", "nextcloud", "authentik"] },
{ id: "apps", label: "Apps", types: ["homeassistant", "jellyfin", "sonarr", "radarr", "lidarr", "readarr", "prowlarr", "immich", "paperless", "nextcloud", "authentik"] },
{ id: "backups", label: "Backups", types: ["pbs"] },
{ id: "network", label: "Network", types: ["unifi", "npm", "phpipam", "netbox", "adguard"] },
{ id: "monitoring", label: "Monitoring", types: ["uptimekuma", "prometheus", "grafana", "ups", "speedtest"] },
+3 -1
View File
@@ -43,7 +43,9 @@ export function subjectOfConditionKey(key: string): string | null {
if (m) return `integration:${m[1]}`;
m = /^fragnet-(?:disk|memory|backup):(\d+):/.exec(key);
if (m) return `integration:${m[1]}`;
m = /^(?:sonarr|radarr|prowlarr)-(?:health|queue|disk):(\d+)/.exec(key);
m = /^(?:sonarr|radarr|prowlarr|lidarr|readarr)-(?:health|queue|disk):(\d+)/.exec(key);
if (m) return `integration:${m[1]}`;
m = /^version-behind:(\d+)$/.exec(key);
if (m) return `integration:${m[1]}`;
m = /^adguard-(?:stopped|dns|protection|filters):(\d+)/.exec(key);
if (m) return `integration:${m[1]}`;
+11
View File
@@ -15,6 +15,7 @@ import { dockerVulnSyncStatuses, isDockerVulnFresh } from "./dockerVulnSync.js";
import { isSpeedtestFresh, recentResults as recentSpeedtestResults, speedtestSyncStatuses } from "./speedtestSync.js";
import { costOf as hetznerCostOf, hetznerSyncStatuses, isHetznerFresh, serversOf as hetznerServersOf, loadBalancersOf as hetznerLoadBalancersOf, certificatesOf as hetznerCertificatesOf, trafficForecast as hetznerTrafficForecast } from "./hetznerSync.js";
import { ARR_KINDS } from "../integrations/arr/adapter.js";
import { versionRows as appVersionRows } from "./appVersions.js";
import { adguardSyncStatuses, isAdguardFresh, storedOf as adguardStoredOf } from "./adguardSync.js";
import { grafanaSyncStatuses, isGrafanaFresh, storedOf as grafanaStoredOf } from "./grafanaSync.js";
import { arrSyncStatuses, distinctDisks as arrDisks, isArrFresh, stuckItems as arrStuck, storedOf as arrStoredOf } from "./arrSync.js";
@@ -105,6 +106,15 @@ async function addSpeedtestMetrics(out: Exposition, now: Date) {
}
}
/** Each connected application whose newest release is known, for /metrics: 1 if a newer release is out than the one it runs, else 0. Only while the lookup of releases is switched on. */
async function addVersionMetrics(out: Exposition) {
if (!(await getSettings()).versionChecks.enabled) return;
for (const r of await appVersionRows()) {
if (r.lag === "unknown" || r.latest === null) continue;
out.add("homelab_app_update_available", "gauge", "1 if a newer release of the application is out than the one it runs, else 0.", r.lag === "same" || r.lag === "ahead" ? 0 : 1, { app: r.type, name: r.name, running: r.running, latest: r.latest.tag });
}
}
/** Each AdGuard Home, for /metrics: whether its DNS server runs and protects, whether the test question was answered and how fast, and what it has done over its statistics period. Only while the reading is recent. */
async function addAdguardMetrics(out: Exposition, now: Date) {
const statuses = await adguardSyncStatuses();
@@ -542,6 +552,7 @@ export async function buildMetrics(now: Date = new Date()): Promise<string> {
await addFragnetMetrics(out, now);
await addArrMetrics(out, now);
await addAdguardMetrics(out, now);
await addVersionMetrics(out);
await addGrafanaMetrics(out, now);
await addHeartbeatMetrics(out, now);
return out.toString();
+9
View File
@@ -262,6 +262,13 @@ export interface AlertTicketSettings {
reopenAfterMinutes: number;
}
/** Looking up the newest release of each connected application (Operations → Versions). The one thing this app asks of an address that is not one of yours, so it is off until it is switched on. */
export interface VersionCheckSettings {
enabled: boolean;
/** A newer release that has been out this many days is a warning for the application that has not caught up; 0 = never. */
alertAfterDays: number;
}
export interface AppSettings {
gotify: GotifySettings;
ntfy: NtfySettings;
@@ -291,9 +298,11 @@ export interface AppSettings {
consistency: ConsistencySettings;
nameGenerator: NameGeneratorSettings;
alertTickets: AlertTicketSettings;
versionChecks: VersionCheckSettings;
}
const DEFAULTS: AppSettings = {
versionChecks: { enabled: false, alertAfterDays: 0 },
gotify: { enabled: false, url: "", token: "", priority: 5 },
ntfy: { enabled: false, url: "https://ntfy.sh", topic: "", token: "", priority: 3 },
smtp: { enabled: false, host: "", port: 587, secure: false, username: "", password: "", from: "", to: "" },
+1 -1
View File
@@ -123,7 +123,7 @@ export async function buildWallExtras(
if (known) tiles.push({ id: "vulnerabilities", label: `critical ${plural(critical, "vulnerability", "vulnerabilities")}`, figure: String(critical), state: critical > 0 ? "bad" : "ok" });
}
const media = ids(["sonarr", "radarr"]);
const media = ids(["sonarr", "radarr", "lidarr", "readarr"]);
if (media.length > 0) {
const statuses = await arrSyncStatuses();
let stuck = 0;