Nextcloud, NetBox and n8n integrations
Three read-only integrations, each with a monitoring page, alerts, maintenance silencing and held-when-unreadable handling. Nextcloud: database needing upgrade (critical), maintenance mode, and the data disk running low; users, files and app updates with an admin app password. NetBox: no background worker running, counts, and a list of the servers this app manages that have no address in NetBox (a list, not an alert). n8n: an active workflow whose last run failed, clearing when it next succeeds. Disk messages for Immich, Paperless and Nextcloud now use the same units as the pages that show them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a16996d975
commit
4ff0b44943
46 files changed
+10137
-10
No files matched your search
@@ -5,11 +5,14 @@
|
||||
*/
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { assets, endpointChecks, heartbeats, integrations, maintenanceWindows, secrets, servers, upsState, jellyfinState, authentikState, immichState, paperlessState } from "../db/schema.js";
|
||||
import { assets, endpointChecks, heartbeats, integrations, maintenanceWindows, secrets, servers, upsState, jellyfinState, authentikState, immichState, paperlessState, nextcloudState, netboxState, n8nState } from "../db/schema.js";
|
||||
import { isUpsFresh, upsSyncStatuses } from "./upsSync.js";
|
||||
import { levelStatuses } from "./serviceLevels.js";
|
||||
import { backupState, listAll as listDuplicati } from "./duplicati.js";
|
||||
import { isJellyfinFresh, jellyfinSyncStatuses, streamsOf } from "./jellyfinSync.js";
|
||||
import { isNextcloudFresh, nextcloudSyncStatuses } from "./nextcloudSync.js";
|
||||
import { isNetBoxFresh, netboxSyncStatuses } from "./netboxSync.js";
|
||||
import { isN8nFresh, n8nSyncStatuses, workflowsOf as n8nWorkflowsOf } from "./n8nSync.js";
|
||||
import { componentsOf as paperlessComponentsOf, failedOf as paperlessFailedOf, isPaperlessFresh, paperlessSyncStatuses } from "./paperlessSync.js";
|
||||
import { immichSyncStatuses, isImmichFresh, queuesOf as immichQueuesOf } from "./immichSync.js";
|
||||
import { authentikSyncStatuses, certificatesOf, daysUntil, isAuthentikFresh, outpostsOf } from "./authentikSync.js";
|
||||
@@ -64,6 +67,50 @@ class Exposition {
|
||||
}
|
||||
}
|
||||
|
||||
/** Each Nextcloud, for /metrics: whether it is in maintenance mode, the room left for the data, who was active and the app updates waiting. Only while the reading is recent. */
|
||||
async function addNextcloudMetrics(out: Exposition, now: Date) {
|
||||
const statuses = await nextcloudSyncStatuses();
|
||||
const names = new Map((await db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "nextcloud"))).map((r) => [r.id, r]));
|
||||
for (const s of await db.select().from(nextcloudState)) {
|
||||
const row = names.get(s.integrationId);
|
||||
if (!row || !row.enabled || !isNextcloudFresh(statuses[s.integrationId], now.getTime())) continue;
|
||||
const labels = { name: row.name };
|
||||
out.add("homelab_nextcloud_maintenance_mode", "gauge", "1 if Nextcloud is in maintenance mode, else 0.", s.maintenance ? 1 : 0, labels);
|
||||
if (s.freeBytes !== null) out.add("homelab_nextcloud_free_bytes", "gauge", "Bytes free where Nextcloud keeps its data.", s.freeBytes, labels);
|
||||
if (s.active24h !== null) out.add("homelab_nextcloud_active_users_24h", "gauge", "Users active in the last 24 hours.", s.active24h, labels);
|
||||
if (s.appUpdates !== null) out.add("homelab_nextcloud_app_updates", "gauge", "How many apps have an update waiting.", s.appUpdates, labels);
|
||||
}
|
||||
}
|
||||
|
||||
/** Each NetBox, for /metrics: the workers running and what it holds. Only while the reading is recent. */
|
||||
async function addNetBoxMetrics(out: Exposition, now: Date) {
|
||||
const statuses = await netboxSyncStatuses();
|
||||
const names = new Map((await db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "netbox"))).map((r) => [r.id, r]));
|
||||
for (const s of await db.select().from(netboxState)) {
|
||||
const row = names.get(s.integrationId);
|
||||
if (!row || !row.enabled || !isNetBoxFresh(statuses[s.integrationId], now.getTime())) continue;
|
||||
const labels = { name: row.name };
|
||||
if (s.workersRunning !== null) out.add("homelab_netbox_workers", "gauge", "How many background workers NetBox has running.", s.workersRunning, labels);
|
||||
if (s.devices !== null) out.add("homelab_netbox_devices", "gauge", "How many devices NetBox holds.", s.devices, labels);
|
||||
if (s.ipAddresses !== null) out.add("homelab_netbox_ip_addresses", "gauge", "How many IP addresses NetBox holds.", s.ipAddresses, labels);
|
||||
}
|
||||
}
|
||||
|
||||
/** Each n8n, for /metrics: how many workflows there are, are switched on and have failed on their last run. Only while the reading is recent. */
|
||||
async function addN8nMetrics(out: Exposition, now: Date) {
|
||||
const statuses = await n8nSyncStatuses();
|
||||
const names = new Map((await db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "n8n"))).map((r) => [r.id, r]));
|
||||
for (const s of await db.select().from(n8nState)) {
|
||||
const row = names.get(s.integrationId);
|
||||
if (!row || !row.enabled || !isN8nFresh(statuses[s.integrationId], now.getTime())) continue;
|
||||
const labels = { name: row.name };
|
||||
const workflows = n8nWorkflowsOf(s);
|
||||
out.add("homelab_n8n_workflows", "gauge", "How many workflows n8n has.", workflows.length, labels);
|
||||
out.add("homelab_n8n_workflows_active", "gauge", "How many of them are switched on.", workflows.filter((w) => w.active).length, labels);
|
||||
if (s.executionsKnown) out.add("homelab_n8n_workflows_failing", "gauge", "Active workflows whose last run failed.", workflows.filter((w) => w.active && (w.lastStatus === "error" || w.lastStatus === "crashed")).length, labels);
|
||||
}
|
||||
}
|
||||
|
||||
/** Each Paperless-ngx, for /metrics: the documents, the inbox, the imports that failed and whether each component of its status is in order. Only while the reading is recent. */
|
||||
async function addPaperlessMetrics(out: Exposition, now: Date) {
|
||||
const statuses = await paperlessSyncStatuses();
|
||||
@@ -337,6 +384,9 @@ export async function buildMetrics(now: Date = new Date()): Promise<string> {
|
||||
await addAuthentikMetrics(out, now);
|
||||
await addImmichMetrics(out, now);
|
||||
await addPaperlessMetrics(out, now);
|
||||
await addN8nMetrics(out, now);
|
||||
await addNetBoxMetrics(out, now);
|
||||
await addNextcloudMetrics(out, now);
|
||||
await addHeartbeatMetrics(out, now);
|
||||
return out.toString();
|
||||
}
|
||||
Reference in new issue
Block a user