Suggested checks for the apps in your containers
With Dockhand connected, an image the app recognises (about 20 with a health endpoint of their own, plus a few dozen web UIs) is offered as an endpoint check on that app's own health address, with what a good answer looks like set up as a value check: Immich's ping says pong, Nextcloud's status.php is not in maintenance, Gitea's health says pass, and so on. Asked on the Docker host's address at the port the container publishes. Container ports are now read from Dockhand's list. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0fa50c2d5a
commit
12f2662465
10 files changed
+502
-5
No files matched your search
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* What the apps people run in containers answer when they are well: the address of each one's own health check, and what a good answer looks like. From the container's
|
||||
* image the app can say "this is Immich" and offer a check on `/api/server/ping` that wants `res` to be `pong`, instead of a bare "something answers on port 2283".
|
||||
*
|
||||
* The paths and answers are those the projects publish for the purpose (Immich's ping, Nextcloud's status.php, Authentik's health endpoints, Gitea's healthz, Grafana's health …),
|
||||
* not guesses. They have not been tried against live instances here; one that is wrong shows as a failing check, which can be edited. Apps with no such endpoint get a plain
|
||||
* "the web page answers" check on `/`. Nothing here asks anything: it only recognises images.
|
||||
*/
|
||||
|
||||
export interface CatalogApp {
|
||||
id: string;
|
||||
name: string;
|
||||
/** Matched against the image's repository (registry and tag left off), lower-case. */
|
||||
match: RegExp;
|
||||
/** The ports the app listens on inside the container, in order of preference. */
|
||||
ports: number[];
|
||||
/** Of those, the ones that speak TLS (self-signed, usually). */
|
||||
tlsPorts?: number[];
|
||||
path: string;
|
||||
/** Good status codes, "200-399" when left out. */
|
||||
expectStatus?: string;
|
||||
/** Text the answer must contain. */
|
||||
keyword?: string;
|
||||
/** A value in a JSON answer, and what it should be. */
|
||||
value?: { path: string; op: "=" | "contains"; expected: string };
|
||||
/** One line on what the check wants, for the person adding it. */
|
||||
says: string;
|
||||
}
|
||||
|
||||
const web = (id: string, name: string, match: RegExp, ports: number[], path = "/"): CatalogApp => ({ id, name, match, ports, path, says: "the web page answers" });
|
||||
|
||||
export const APPS: CatalogApp[] = [
|
||||
{ id: "immich", name: "Immich", match: /immich-app\/immich-server/, ports: [2283, 3001], path: "/api/server/ping", value: { path: "res", op: "=", expected: "pong" }, says: "its ping answers “pong”" },
|
||||
{ id: "paperless", name: "Paperless-ngx", match: /paperless-ngx\/paperless-ngx|^paperlessngx\/paperless-ngx/, ports: [8000], path: "/accounts/login/", expectStatus: "200", says: "its login page answers" },
|
||||
{ id: "nextcloud", name: "Nextcloud", match: /nextcloud-releases\/aio-apache|^(library\/)?nextcloud$|linuxserver\/nextcloud/, ports: [11000, 80, 443], tlsPorts: [443], path: "/status.php", value: { path: "maintenance", op: "=", expected: "false" }, says: "status.php answers, and it is not in maintenance mode" },
|
||||
{ id: "vaultwarden", name: "Vaultwarden", match: /vaultwarden\/server/, ports: [80, 8080], path: "/alive", expectStatus: "200", says: "its /alive answers" },
|
||||
{ id: "authentik", name: "Authentik", match: /goauthentik\/server/, ports: [9000, 9443], tlsPorts: [9443], path: "/-/health/live/", expectStatus: "200-299", says: "its health endpoint says it is alive" },
|
||||
{ id: "gitea", name: "Gitea", match: /^(gitea\/)?gitea$/, ports: [3000, 80], path: "/api/healthz", value: { path: "status", op: "=", expected: "pass" }, says: "its health check says “pass”" },
|
||||
{ id: "grafana", name: "Grafana", match: /grafana\/grafana/, ports: [3000], path: "/api/health", value: { path: "database", op: "=", expected: "ok" }, says: "its database is “ok”" },
|
||||
{ id: "prometheus", name: "Prometheus", match: /prom\/prometheus|prometheus\/prometheus/, ports: [9090], path: "/-/healthy", keyword: "Healthy", says: "it says it is healthy" },
|
||||
{ id: "jellyfin", name: "Jellyfin", match: /jellyfin\/jellyfin|linuxserver\/jellyfin/, ports: [8096, 8920], tlsPorts: [8920], path: "/health", keyword: "Healthy", says: "it says it is healthy" },
|
||||
{ id: "n8n", name: "n8n", match: /n8nio\/n8n/, ports: [5678], path: "/healthz", value: { path: "status", op: "=", expected: "ok" }, says: "its health check says “ok”" },
|
||||
{ id: "ntfy", name: "ntfy", match: /binwiederhier\/ntfy/, ports: [80], path: "/v1/health", value: { path: "healthy", op: "=", expected: "true" }, says: "it says it is healthy" },
|
||||
{ id: "gotify", name: "Gotify", match: /gotify\/server/, ports: [80], path: "/health", value: { path: "health", op: "=", expected: "green" }, says: "its health is “green”" },
|
||||
{ id: "npm", name: "Nginx Proxy Manager", match: /jc21\/nginx-proxy-manager/, ports: [81], path: "/api/", value: { path: "status", op: "=", expected: "OK" }, says: "its API says “OK”" },
|
||||
{ id: "open-webui", name: "Open WebUI", match: /open-webui\/open-webui/, ports: [8080], path: "/health", value: { path: "status", op: "=", expected: "true" }, says: "its health check is true" },
|
||||
{ id: "ollama", name: "Ollama", match: /ollama\/ollama/, ports: [11434], path: "/", keyword: "Ollama is running", says: "it says “Ollama is running”" },
|
||||
{ id: "searxng", name: "SearXNG", match: /searxng\/searxng/, ports: [8080], path: "/healthz", expectStatus: "200", says: "its /healthz answers" },
|
||||
{ id: "wikijs", name: "Wiki.js", match: /requarks\/wiki/, ports: [3000], path: "/healthz", expectStatus: "200", says: "its /healthz answers" },
|
||||
{ id: "bookstack", name: "BookStack", match: /bookstack/, ports: [80, 6875], path: "/status", value: { path: "database", op: "=", expected: "true" }, says: "its database is reachable" },
|
||||
{ id: "homebox", name: "Homebox", match: /homebox/, ports: [7745], path: "/api/v1/status", value: { path: "health", op: "=", expected: "true" }, says: "its status says it is healthy" },
|
||||
{ id: "semaphore", name: "Semaphore", match: /semaphoreui\/semaphore/, ports: [3000], path: "/api/ping", keyword: "pong", says: "its ping answers “pong”" },
|
||||
{ id: "meilisearch", name: "Meilisearch", match: /getmeili\/meilisearch/, ports: [7700], path: "/health", value: { path: "status", op: "=", expected: "available" }, says: "it says it is “available”" },
|
||||
// Apps with no health endpoint of their own that is open without signing in: the page answers.
|
||||
web("technitium", "Technitium DNS", /technitium\/dns-server/, [5380]),
|
||||
web("homepage", "Homepage", /gethomepage\/homepage/, [3000]),
|
||||
web("homarr", "Homarr", /homarr/, [7575]),
|
||||
web("firefly", "Firefly III", /fireflyiii\/core/, [8080]),
|
||||
web("grocy", "Grocy", /grocy/, [80, 9283]),
|
||||
web("freshrss", "FreshRSS", /freshrss\/freshrss/, [80]),
|
||||
web("kanboard", "Kanboard", /kanboard\/kanboard/, [80]),
|
||||
web("planka", "Planka", /plankanban\/planka/, [1337]),
|
||||
web("snipeit", "Snipe-IT", /snipe\/snipe-it/, [80]),
|
||||
web("wallos", "Wallos", /bellamy\/wallos/, [80]),
|
||||
web("2fauth", "2FAuth", /2fauth\/2fauth/, [8000]),
|
||||
web("duplicati", "Duplicati", /duplicati/, [8200]),
|
||||
web("dockge", "Dockge", /louislam\/dockge/, [5001]),
|
||||
web("karakeep", "Karakeep", /karakeep-app\/karakeep/, [3000]),
|
||||
web("it-tools", "IT-Tools", /corentinth\/it-tools/, [80]),
|
||||
web("drawio", "draw.io", /jgraph\/drawio/, [8080]),
|
||||
web("phpipam", "phpIPAM", /phpipam\/phpipam-www/, [80]),
|
||||
web("netbox", "NetBox", /netboxcommunity\/netbox/, [8080], "/login/"),
|
||||
web("nexterm", "Nexterm", /nexterm\/aio/, [6989]),
|
||||
];
|
||||
|
||||
/** The repository part of an image reference, lower-case: registry, tag and digest left off ("ghcr.io/immich-app/immich-server:v3@sha256:…" → "immich-app/immich-server"). */
|
||||
export function repoOf(image: string): string {
|
||||
let r = image.trim().toLowerCase().replace(/@sha256:[0-9a-f]+$/, "");
|
||||
r = r.replace(/:[^/:]+$/, "");
|
||||
// The first part is a registry when it has a dot or a port, or is localhost.
|
||||
const parts = r.split("/");
|
||||
if (parts.length > 1 && (/[.:]/.test(parts[0]) || parts[0] === "localhost")) parts.shift();
|
||||
return parts.join("/");
|
||||
}
|
||||
|
||||
/** Pure: which app an image is, or null. An image that is only a digest ("sha256:…") says nothing. */
|
||||
export function appForImage(image: string): CatalogApp | null {
|
||||
if (/^sha256:/i.test(image.trim())) return null;
|
||||
const repo = repoOf(image);
|
||||
return APPS.find((a) => a.match.test(repo)) ?? null;
|
||||
}
|
||||
|
||||
export interface PublishedPort {
|
||||
privatePort: number | null;
|
||||
publicPort: number | null;
|
||||
protocol: string;
|
||||
}
|
||||
|
||||
/** Pure: the port to ask an app on — the published one for the port it listens on, or the only published one — with the port inside the container; null when it cannot be told. */
|
||||
export function portFor(app: CatalogApp, published: PublishedPort[]): { port: number; inner: number | null } | null {
|
||||
const tcp = published.filter((p) => p.publicPort !== null && p.protocol.toLowerCase() !== "udp");
|
||||
for (const inner of app.ports) {
|
||||
const hit = tcp.find((p) => p.privatePort === inner);
|
||||
if (hit) return { port: hit.publicPort as number, inner };
|
||||
}
|
||||
const distinct = [...new Set(tcp.map((p) => p.publicPort as number))];
|
||||
if (distinct.length !== 1) return null;
|
||||
return { port: distinct[0], inner: tcp.find((p) => p.publicPort === distinct[0])?.privatePort ?? null };
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
* server it forwards to.
|
||||
* - A secret that already has a host to read the certificate from, as a certificate check: the secret only warns about the expiry, this also hears
|
||||
* when the service stops answering.
|
||||
* - An app running in a container Dockhand reports (Immich, Paperless, Nextcloud, Gitea, Grafana, Authentik …), recognised from its image, as a check on that app's own
|
||||
* health address with what a good answer looks like (services/appCatalog.ts) — on the Docker host's address, at the port the container publishes.
|
||||
*
|
||||
* It only reads what is stored (no network), leaves out what a check already covers, and remembers what somebody said no to. Uptime Kuma's monitors are
|
||||
* not offered: they are already being watched, and the adapter only keeps a host and port for them, not the address.
|
||||
@@ -16,6 +18,11 @@ import { dnsRecordsCache, endpointChecks, secrets, servers } from "../db/schema.
|
||||
import { isLoopback } from "./agentPorts.js";
|
||||
import { npmIntegrationIds, readNpm } from "./npmReader.js";
|
||||
import { matchServerForTarget } from "./uptimeKumaMatch.js";
|
||||
import { appForImage, portFor, type PublishedPort } from "./appCatalog.js";
|
||||
import { loadIntegrationConfig } from "../integrations/loadIntegration.js";
|
||||
import { createDockhandAdapter } from "../integrations/dockhand/adapter.js";
|
||||
import { integrations } from "../db/schema.js";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { getInternalFlag, setInternalFlag } from "./settingsStore.js";
|
||||
|
||||
export interface Suggestion {
|
||||
@@ -29,6 +36,14 @@ export interface Suggestion {
|
||||
serverName: string | null;
|
||||
/** Why it is offered, in a sentence. */
|
||||
reason: string;
|
||||
/** For an app recognised from its container: what the check wants, and the settings that make it so. */
|
||||
checks?: string;
|
||||
expectStatus?: string | null;
|
||||
keyword?: string | null;
|
||||
valuePath?: string | null;
|
||||
valueOp?: "=" | "contains" | null;
|
||||
valueExpected?: string | null;
|
||||
insecure?: boolean;
|
||||
}
|
||||
|
||||
export interface SuggestionInput {
|
||||
@@ -39,6 +54,8 @@ export interface SuggestionInput {
|
||||
dismissed: Set<string>;
|
||||
/** Hosts an Nginx Proxy Manager serves, with the server they forward to when the app knows it. */
|
||||
proxied?: { domain: string; secure: boolean; serverId: number | null; serverName: string | null; integrationName: string }[];
|
||||
/** Containers Dockhand reports, with the Docker host each runs on (its name there). */
|
||||
containers?: { environmentName: string; name: string; image: string; state: string; ports: PublishedPort[] }[];
|
||||
}
|
||||
|
||||
/** The web ports worth offering, and what they speak. */
|
||||
@@ -75,6 +92,46 @@ function coverage(existing: SuggestionInput["existing"]): Set<string> {
|
||||
export function suggestChecks(input: SuggestionInput): { suggestions: Suggestion[]; dismissed: Suggestion[] } {
|
||||
const covered = coverage(input.existing);
|
||||
const all = new Map<string, Suggestion>();
|
||||
/** The ports an app has been offered on, by server, so the plain "something answers on 8080" suggestion is not offered as well. */
|
||||
const appPorts = new Set<string>();
|
||||
|
||||
// Apps recognised from their containers: asked on the Docker host's address, at the port the container publishes, on the app's own health address.
|
||||
const matchable = input.servers.map((s) => ({ id: s.id, name: s.name, hostname: s.hostname, ips: s.ips }));
|
||||
for (const c of input.containers ?? []) {
|
||||
if (c.state !== "running") continue;
|
||||
const app = appForImage(c.image);
|
||||
if (!app) continue;
|
||||
const server = matchServerForTarget(c.environmentName, matchable);
|
||||
if (!server) continue;
|
||||
const listening = new Set(input.servers.find((s) => s.id === server.id)?.ports.filter((p) => (p.protocol ?? "tcp") === "tcp").map((p) => p.port));
|
||||
// When Dockhand says nothing about ports, the host's own listening ports (from its agent) stand in: the one the app is known to use.
|
||||
const chosen = c.ports.length > 0 ? portFor(app, c.ports) : (() => { const p = app.ports.find((x) => listening.has(x)); return p === undefined ? null : { port: p, inner: p }; })();
|
||||
const ip = server.ips.map((i) => i.trim()).find(usableIPv4);
|
||||
if (!chosen || !ip) continue;
|
||||
const tls = chosen.inner !== null ? (app.tlsPorts ?? []).includes(chosen.inner) : (app.tlsPorts ?? []).includes(chosen.port);
|
||||
const scheme = tls ? "https" : "http";
|
||||
if (covered.has(`web:${ip}:${chosen.port}`)) continue;
|
||||
const key = `app|${app.id}|${ip}|${chosen.port}`;
|
||||
if (all.has(key)) continue;
|
||||
appPorts.add(`${server.id}:${chosen.port}`);
|
||||
all.set(key, {
|
||||
key,
|
||||
kind: "http",
|
||||
name: `${app.name} on ${server.name}`,
|
||||
target: `${scheme}://${ip}:${chosen.port}${app.path}`,
|
||||
port: null,
|
||||
serverId: server.id,
|
||||
serverName: server.name,
|
||||
reason: `${c.name} runs ${app.name} on ${server.name}.`,
|
||||
checks: app.says,
|
||||
expectStatus: app.expectStatus ?? null,
|
||||
keyword: app.keyword ?? null,
|
||||
valuePath: app.value?.path ?? null,
|
||||
valueOp: app.value?.op ?? null,
|
||||
valueExpected: app.value?.expected ?? null,
|
||||
insecure: tls,
|
||||
});
|
||||
}
|
||||
|
||||
for (const s of input.servers) {
|
||||
const ips = new Set(s.ips.map((i) => i.trim().toLowerCase()));
|
||||
@@ -96,6 +153,8 @@ export function suggestChecks(input: SuggestionInput): { suggestions: Suggestion
|
||||
for (const port of Object.keys(WEB_PORTS).map(Number).filter((p) => listening.has(p))) {
|
||||
// Plain and secure on the same server: the secure one is the real service (the plain one is most likely its redirect), and reads the certificate.
|
||||
if (SECURE_TWIN[port] !== undefined && listening.has(SECURE_TWIN[port])) continue;
|
||||
// An app that is known to be there already has a better check offered.
|
||||
if (appPorts.has(`${s.id}:${port}`)) continue;
|
||||
const scheme = WEB_PORTS[port];
|
||||
const fallback = hostname && hostname.includes(".") ? [hostname] : [s.ips.map((i) => i.trim()).find(usableIPv4)].filter((x): x is string => !!x);
|
||||
const hosts = dnsNames.length > 0 ? dnsNames.slice(0, MAX_NAMES_PER_PORT) : fallback;
|
||||
@@ -193,6 +252,29 @@ function jsonArray<T>(stored: string | null): T[] {
|
||||
}
|
||||
}
|
||||
|
||||
/** The containers of every enabled Dockhand, kept a minute so opening the page twice does not ask every Docker host twice. A Dockhand that cannot be read adds nothing. */
|
||||
let containerCache: { at: number; rows: NonNullable<SuggestionInput["containers"]> } | null = null;
|
||||
async function dockerContainers(): Promise<NonNullable<SuggestionInput["containers"]>> {
|
||||
if (containerCache && Date.now() - containerCache.at < 60_000) return containerCache.rows;
|
||||
const rows: NonNullable<SuggestionInput["containers"]> = [];
|
||||
for (const row of await db.select({ id: integrations.id }).from(integrations).where(and(eq(integrations.type, "dockhand"), eq(integrations.enabled, true)))) {
|
||||
try {
|
||||
const loaded = await loadIntegrationConfig(row.id);
|
||||
if (!loaded) continue;
|
||||
for (const c of await createDockhandAdapter(loaded.config as never).listContainers()) rows.push({ environmentName: c.environmentName, name: c.name, image: c.image, state: c.state, ports: c.ports ?? [] });
|
||||
} catch {
|
||||
// nothing from this one
|
||||
}
|
||||
}
|
||||
containerCache = { at: Date.now(), rows };
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** For tests: forget what was read. */
|
||||
export function resetContainerCacheForTests(): void {
|
||||
containerCache = null;
|
||||
}
|
||||
|
||||
export async function loadSuggestions(): Promise<{ suggestions: Suggestion[]; dismissed: Suggestion[] }> {
|
||||
const [serverRows, dnsRows, secretRows, existing, dismissed] = await Promise.all([
|
||||
db.select({ id: servers.id, name: servers.name, hostname: servers.hostname, ipAddresses: servers.ipAddresses, listeningPorts: servers.listeningPorts }).from(servers),
|
||||
@@ -213,6 +295,7 @@ export async function loadSuggestions(): Promise<{ suggestions: Suggestion[]; di
|
||||
}
|
||||
}
|
||||
return suggestChecks({
|
||||
containers: await dockerContainers(),
|
||||
proxied,
|
||||
servers: serverRows.map((s) => ({ id: s.id, name: s.name, hostname: s.hostname, ips: jsonArray<string>(s.ipAddresses).filter((i) => typeof i === "string"), ports: jsonArray<{ protocol?: string; port: number; address?: string }>(s.listeningPorts).filter((p) => p && Number.isInteger(p.port)) })),
|
||||
dns: dnsRows,
|
||||
|
||||
Reference in new issue
Block a user