Files
Homelab-manager/server/src/index.ts
T
bobbanandClaude Sonnet 5.5 4ff0b44943 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>
2026-10-24 23:13:13 +02:00

104 lines
5.0 KiB
TypeScript

import "./loadEnv.js";
// Before anything opens the database: puts a restore that was staged from Settings → Data → Backup in place.
import "./db/applyRestore.js";
import { env, warnIfAuthNotConfigured, checkSessionSecret } from "./env.js";
import { createApp } from "./app.js";
import { runMigrations } from "./db/migrate.js";
import { encryptStoredSettingsSecrets } from "./services/settingsStore.js";
import { initSecretExpiryScheduler } from "./services/secretExpiryScheduler.js";
import { initTailscaleKeyExpiryScheduler } from "./services/tailscaleKeyExpiryScheduler.js";
import { initLogRetentionScheduler } from "./services/logRetentionScheduler.js";
import { initDockerUpdateScheduler } from "./services/dockerUpdateScheduler.js";
import { initProxmoxBackupScheduler } from "./services/proxmoxBackupScheduler.js";
import { initPbsVerificationScheduler } from "./services/pbsVerificationScheduler.js";
import { initQuietHoursScheduler } from "./services/quietHoursScheduler.js";
import { initWeeklyDigestScheduler } from "./services/weeklyDigestScheduler.js";
import { initMonthlyReportScheduler } from "./services/monthlyReportScheduler.js";
import { initMaintenanceEvents } from "./services/maintenanceEvents.js";
import { initHealthScheduler } from "./services/healthScheduler.js";
import { initAlertTicketScheduler } from "./services/alertTicketScheduler.js";
import { initKumaMaintenanceScheduler } from "./services/kumaMaintenanceScheduler.js";
import { initMaintenanceScheduleScheduler } from "./services/maintenanceScheduleScheduler.js";
import { initUpdateRuns } from "./services/updateRuns.js";
import { initEscalation } from "./services/escalation.js";
import { initEndpointMonitor } from "./services/endpointMonitor.js";
import { initPatchPlans } from "./services/patchPlans.js";
import { initFlapMonitor } from "./services/flapMonitor.js";
import { initSnoozeMonitor } from "./services/snoozeMonitor.js";
import { initUnifiSync } from "./services/unifiSync.js";
import { initHomeAssistantSync } from "./services/homeAssistantSync.js";
import { initUpsSync } from "./services/upsSync.js";
import { initAwayMonitor } from "./services/awayMonitor.js";
import { initJellyfinSync } from "./services/jellyfinSync.js";
import { initAuthentikSync } from "./services/authentikSync.js";
import { initPrometheusSync } from "./services/prometheusSync.js";
import { initImmichSync } from "./services/immichSync.js";
import { initPaperlessSync } from "./services/paperlessSync.js";
import { initN8nSync } from "./services/n8nSync.js";
import { initNetBoxSync } from "./services/netboxSync.js";
import { initNextcloudSync } from "./services/nextcloudSync.js";
import { backfillMetricRollups } from "./services/serverMetrics.js";
import { backfillEndpointHourly } from "./services/endpointChecks.js";
import { initSelfBackupScheduler } from "./services/selfBackupScheduler.js";
import { initIncidentRecorder } from "./services/incidents.js";
import { getAlerts } from "./services/alerts.js";
{
// Sessions are signed with this secret. Without one, the app would sign them with a value that's in the source code.
const secret = checkSessionSecret(process.env.SESSION_SECRET, env.nodeEnv);
if (secret.fatal) {
console.error(secret.fatal);
process.exit(1);
}
if (secret.warning) console.warn(secret.warning);
}
warnIfAuthNotConfigured();
if (env.environmentWarning) console.warn(env.environmentWarning);
if (env.environment) console.log(`Environment: ${env.environment.name || "(unnamed)"} (${env.environment.color})`);
await runMigrations();
{
const converted = await encryptStoredSettingsSecrets();
if (converted > 0) console.log(`Encrypted the stored credentials of ${converted} notification channel${converted === 1 ? "" : "s"}.`);
}
await initSecretExpiryScheduler();
await initTailscaleKeyExpiryScheduler();
await initLogRetentionScheduler();
await initDockerUpdateScheduler();
await initProxmoxBackupScheduler();
await initPbsVerificationScheduler();
await initQuietHoursScheduler();
await initWeeklyDigestScheduler();
await initMonthlyReportScheduler();
initMaintenanceEvents();
await initHealthScheduler();
await initAlertTicketScheduler();
await initKumaMaintenanceScheduler();
await initMaintenanceScheduleScheduler();
initUpdateRuns();
await initSelfBackupScheduler();
initIncidentRecorder(() => getAlerts(false));
initEscalation();
initEndpointMonitor();
initPatchPlans();
initFlapMonitor();
initSnoozeMonitor();
initUnifiSync();
initHomeAssistantSync();
initUpsSync();
initAwayMonitor();
initJellyfinSync();
initAuthentikSync();
initPrometheusSync();
initImmichSync();
initPaperlessSync();
initN8nSync();
initNetBoxSync();
initNextcloudSync();
// 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));
createApp().listen(env.port, () => {
console.log(`homelab-manager listening on port ${env.port}`);
});