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

+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;