Prometheus, Immich and Paperless-ngx integrations
Three read-only integrations, each with a monitoring page, alerts, maintenance silencing and held-when-unreadable handling. Prometheus: scrape targets that stop answering (5 minutes, one alert per job) and alerts that Prometheus's own rules fire (critical when labelled so). Immich: disk under the library filling, failed background jobs, counts. Paperless-ngx: worker/database/Redis in error, documents that failed to import, index and sanity check, disk. Immich and Paperless also in /metrics. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aebe98bf15
commit
251a4a9d73
47 files changed
+24148
-7
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { Router } from "express";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { immichState, integrations } from "../db/schema.js";
|
||||
import { requireAuth } from "../auth/middleware.js";
|
||||
import { immichProblems, immichSyncStatuses, isImmichFresh, queuesOf } from "../services/immichSync.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const immichRouter = Router();
|
||||
immichRouter.use(requireAuth);
|
||||
|
||||
/** Every Immich, how it is, from what the last read stored: the disk under the library, the counts, the job queues and what is wrong. Everyone signed in can see it, like the other pages made of stored readings. */
|
||||
immichRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
const [rows, states, statuses] = await Promise.all([
|
||||
db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "immich")).orderBy(integrations.name),
|
||||
db.select().from(immichState),
|
||||
immichSyncStatuses(),
|
||||
]);
|
||||
const byId = new Map(states.map((s) => [s.integrationId, s]));
|
||||
const now = Date.now();
|
||||
res.json({
|
||||
immiches: rows.map((r) => {
|
||||
const state = byId.get(r.id) ?? null;
|
||||
const status = statuses[r.id] ?? null;
|
||||
const fresh = isImmichFresh(status ?? undefined, now);
|
||||
return {
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
enabled: r.enabled,
|
||||
status,
|
||||
fresh,
|
||||
state: state
|
||||
? {
|
||||
version: state.version,
|
||||
latestVersion: state.latestVersion,
|
||||
updateAvailable: state.updateAvailable,
|
||||
disk: state.diskSize !== null && state.diskUsed !== null ? { size: state.diskSize, used: state.diskUsed, percent: state.diskPercent } : null,
|
||||
photos: state.photos,
|
||||
videos: state.videos,
|
||||
usageBytes: state.usageBytes,
|
||||
queues: queuesOf(state),
|
||||
updatedAt: state.updatedAt,
|
||||
}
|
||||
: null,
|
||||
problems: state && fresh ? immichProblems(r.id, r.name, state) : [],
|
||||
};
|
||||
}),
|
||||
});
|
||||
}));
|
||||
@@ -31,6 +31,9 @@ import { removeHomeAssistantData, syncHomeAssistant } from "../services/homeAssi
|
||||
import { forgetUps, syncUps } from "../services/upsSync.js";
|
||||
import { forgetJellyfin, syncJellyfin } from "../services/jellyfinSync.js";
|
||||
import { forgetAuthentik, syncAuthentik } from "../services/authentikSync.js";
|
||||
import { forgetPrometheus, syncPrometheus } from "../services/prometheusSync.js";
|
||||
import { forgetImmich, syncImmich } from "../services/immichSync.js";
|
||||
import { forgetPaperless, syncPaperless } from "../services/paperlessSync.js";
|
||||
import { invalidateAlertsCache } from "../services/alerts.js";
|
||||
import { getSettings, updateSettings } from "../services/settingsStore.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
@@ -135,6 +138,9 @@ integrationsRouter.post("/", requireRole("admin"), asyncHandler(async (req, res)
|
||||
if (type === "ups") void syncUps(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "jellyfin") void syncJellyfin(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "authentik") void syncAuthentik(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "prometheus") void syncPrometheus(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "immich") void syncImmich(created.id).then(() => invalidateAlertsCache());
|
||||
if (type === "paperless") void syncPaperless(created.id).then(() => invalidateAlertsCache());
|
||||
|
||||
res.status(201).json({
|
||||
integration: {
|
||||
@@ -240,6 +246,9 @@ integrationsRouter.patch("/:id", requireRole("admin"), asyncHandler(async (req,
|
||||
if (updated.type === "ups" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncUps(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "jellyfin" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncJellyfin(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "authentik" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncAuthentik(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "prometheus" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncPrometheus(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "immich" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncImmich(updated.id).then(() => invalidateAlertsCache());
|
||||
if (updated.type === "paperless" && updated.enabled && (parsed.data.config || parsed.data.enabled === true)) void syncPaperless(updated.id).then(() => invalidateAlertsCache());
|
||||
|
||||
res.json({
|
||||
integration: {
|
||||
@@ -321,6 +330,9 @@ integrationsRouter.delete("/:id", requireRole("admin"), asyncHandler(async (req,
|
||||
if (existing.type === "ups") await forgetUps(id);
|
||||
if (existing.type === "jellyfin") await forgetJellyfin(id);
|
||||
if (existing.type === "authentik") await forgetAuthentik(id);
|
||||
if (existing.type === "prometheus") await forgetPrometheus(id);
|
||||
if (existing.type === "immich") await forgetImmich(id);
|
||||
if (existing.type === "paperless") await forgetPaperless(id);
|
||||
await db.delete(integrations).where(eq(integrations.id, id));
|
||||
if (existing.credentialId) {
|
||||
await db.delete(integrationCredentials).where(eq(integrationCredentials.id, existing.credentialId));
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { Router } from "express";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { integrations, paperlessState } from "../db/schema.js";
|
||||
import { requireAuth } from "../auth/middleware.js";
|
||||
import { componentsOf, failedOf, isPaperlessFresh, paperlessProblems, paperlessSyncStatuses } from "../services/paperlessSync.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const paperlessRouter = Router();
|
||||
paperlessRouter.use(requireAuth);
|
||||
|
||||
/** Every Paperless-ngx, how it is, from what the last read stored: its status components, the disk, the counts, the imports that failed and what is wrong. Everyone signed in can see it, like the other pages made of stored readings. */
|
||||
paperlessRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
const [rows, states, statuses] = await Promise.all([
|
||||
db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "paperless")).orderBy(integrations.name),
|
||||
db.select().from(paperlessState),
|
||||
paperlessSyncStatuses(),
|
||||
]);
|
||||
const byId = new Map(states.map((s) => [s.integrationId, s]));
|
||||
const now = Date.now();
|
||||
res.json({
|
||||
paperlesses: rows.map((r) => {
|
||||
const state = byId.get(r.id) ?? null;
|
||||
const status = statuses[r.id] ?? null;
|
||||
const fresh = isPaperlessFresh(status ?? undefined, now);
|
||||
return {
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
enabled: r.enabled,
|
||||
status,
|
||||
fresh,
|
||||
state: state
|
||||
? {
|
||||
version: state.version,
|
||||
latestVersion: state.latestVersion,
|
||||
updateAvailable: state.updateAvailable,
|
||||
storage: state.storageTotal !== null && state.storageAvailable !== null ? { total: state.storageTotal, available: state.storageAvailable } : null,
|
||||
components: componentsOf(state),
|
||||
documents: state.documents,
|
||||
inbox: state.inbox,
|
||||
failed: failedOf(state),
|
||||
updatedAt: state.updatedAt,
|
||||
}
|
||||
: null,
|
||||
problems: state && fresh ? paperlessProblems(r.id, r.name, state) : [],
|
||||
};
|
||||
}),
|
||||
});
|
||||
}));
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Router } from "express";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { integrations, prometheusState } from "../db/schema.js";
|
||||
import { requireAuth } from "../auth/middleware.js";
|
||||
import { alertsOf, downOf, isPrometheusFresh, jobsOf, prometheusProblems, prometheusSyncStatuses } from "../services/prometheusSync.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const prometheusRouter = Router();
|
||||
prometheusRouter.use(requireAuth);
|
||||
|
||||
/** Every Prometheus, how it is, from what the last read stored: targets by job, the ones that are down, the alerts firing, and what is wrong. Everyone signed in can see it, like the other pages made of stored readings. */
|
||||
prometheusRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
const [rows, states, statuses] = await Promise.all([
|
||||
db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "prometheus")).orderBy(integrations.name),
|
||||
db.select().from(prometheusState),
|
||||
prometheusSyncStatuses(),
|
||||
]);
|
||||
const byId = new Map(states.map((s) => [s.integrationId, s]));
|
||||
const now = new Date();
|
||||
res.json({
|
||||
prometheuses: rows.map((r) => {
|
||||
const state = byId.get(r.id) ?? null;
|
||||
const status = statuses[r.id] ?? null;
|
||||
const fresh = isPrometheusFresh(status ?? undefined, now.getTime());
|
||||
return {
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
enabled: r.enabled,
|
||||
status,
|
||||
fresh,
|
||||
state: state ? { version: state.version, jobs: jobsOf(state), down: downOf(state), alerts: alertsOf(state), updatedAt: state.updatedAt } : null,
|
||||
problems: state && fresh ? prometheusProblems(r.id, r.name, state, now) : [],
|
||||
};
|
||||
}),
|
||||
});
|
||||
}));
|
||||
Reference in new issue
Block a user