Nextcloud cron and Nextcloud's own checks; bulk close and open again
Nextcloud: its own "Cron last run" setup check (GET /settings/setupcheck, Nextcloud 28+, found by class name) raises an alert when background jobs have stopped; other checks that report an error are one alert, warnings are shown on the page. The core version Nextcloud says is available is shown too. Before 28, cron and the checks are unknown, never "fine". Alerts page: bulk Close... (one reason, written on each incident, undoable) and Open again. Bulk Wake now leaves closed alerts alone. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5ae61a1ece
commit
65214f6f0f
25 files changed
+8108
-35
No files matched your search
@@ -1187,6 +1187,10 @@ export const nextcloudState = sqliteTable("nextcloud_state", {
|
||||
files: integer("files"),
|
||||
active24h: integer("active_24h"),
|
||||
appUpdates: integer("app_updates"), // how many apps have an update waiting; null: not asked
|
||||
coreUpdate: text("core_update"), // the version Nextcloud says is available ("newer" when it does not say which); null: none, or not asked
|
||||
cronState: text("cron_state"), // Nextcloud's own "Cron last run" check: success, info, warning or error; null: not known (no login, or before Nextcloud 28)
|
||||
cronText: text("cron_text"), // what that check said ("Last background job execution ran 3 hours ago. Something seems wrong.")
|
||||
setupIssues: text("setup_issues"), // JSON: name, severity, text — the other setup checks that report an error or a warning; null: could not be asked
|
||||
updatedAt: text("updated_at").notNull(), // ISO
|
||||
});
|
||||
|
||||
|
||||
@@ -6,8 +6,13 @@
|
||||
* upgrading** (either way nobody can sign in). With an administrator's app password the *Monitoring* ("serverinfo") app is also asked: how much room is left for the data, how many
|
||||
* users and files, who was active, and how many app updates wait. Nothing is sent to Nextcloud but GET requests for these.
|
||||
*
|
||||
* Endpoints and field names are from Nextcloud's published API (`/status.php`, `/ocs/v2.php/apps/serverinfo/api/v1/info`) and have not been checked against a live server here;
|
||||
* every field is read defensively. Whether background jobs (cron) are running is *not* read: the API this app uses does not say.
|
||||
* With the same login, **Nextcloud's own setup checks** are asked too (`GET /settings/setupcheck`, Nextcloud 28 and later; no administrator is needed): the one called *Cron last run* says whether the
|
||||
* **background jobs are running** (Nextcloud itself calls it an error when the last run was more than an hour ago), and any other check that reports an error or a warning is kept to show.
|
||||
* The serverinfo app does not report cron — its source has no such field — which is why this is a separate request.
|
||||
*
|
||||
* Endpoints and field names are from Nextcloud's published API and source (`/status.php`, `/ocs/v2.php/apps/serverinfo/api/v1/info`, `/settings/setupcheck`, whose results are
|
||||
* { category: { checkClass: { name, severity, description } } }) and have not been checked against a live server here; every field is read defensively. Before Nextcloud 28 there is no such check,
|
||||
* and cron is simply not known.
|
||||
*/
|
||||
import { requestJson } from "../httpJson.js";
|
||||
import { withDiagLogging } from "../../services/diagLog.js";
|
||||
@@ -33,8 +38,25 @@ export interface NextcloudRead {
|
||||
active24h: number | null;
|
||||
/** How many apps have an update waiting; null when not asked. */
|
||||
appUpdates: number | null;
|
||||
/** The version Nextcloud itself says is available, or "newer" when it says one is but not which; null when none is or it was not asked. */
|
||||
coreUpdate: string | null;
|
||||
/** Nextcloud's own "Cron last run" check; null when it could not be asked (no login, or before Nextcloud 28). */
|
||||
cron: { state: SetupSeverity; text: string | null } | null;
|
||||
/** The other setup checks that report an error or a warning, at most MAX_ISSUES; null when the checks could not be asked. */
|
||||
setupIssues: SetupIssue[] | null;
|
||||
}
|
||||
|
||||
export type SetupSeverity = "success" | "info" | "warning" | "error";
|
||||
|
||||
export interface SetupIssue {
|
||||
/** The check's own name for itself, as Nextcloud shows it (in the language it is set to). */
|
||||
name: string;
|
||||
severity: "warning" | "error";
|
||||
text: string | null;
|
||||
}
|
||||
|
||||
export const MAX_ISSUES = 40;
|
||||
|
||||
export interface NextcloudAdapter {
|
||||
ping(): Promise<{ ok: boolean; latencyMs?: number; error?: string }>;
|
||||
read(): Promise<NextcloudRead>;
|
||||
@@ -53,14 +75,16 @@ export function parseStatus(raw: unknown): Pick<NextcloudRead, "version" | "main
|
||||
}
|
||||
|
||||
/** Pure: what the monitoring app says (`ocs.data`). */
|
||||
export function parseServerInfo(raw: unknown): Pick<NextcloudRead, "freeBytes" | "users" | "files" | "active24h" | "appUpdates"> | null {
|
||||
export function parseServerInfo(raw: unknown): Pick<NextcloudRead, "freeBytes" | "users" | "files" | "active24h" | "appUpdates" | "coreUpdate"> | null {
|
||||
const data = obj(obj(raw).ocs).data;
|
||||
if (data === undefined || data === null || typeof data !== "object") return null;
|
||||
const nc = obj(obj(data).nextcloud);
|
||||
const system = obj(nc.system);
|
||||
const apps = obj(system.apps);
|
||||
const listed = Object.keys(obj(apps.app_updates)).length;
|
||||
const update = obj(system.update);
|
||||
return {
|
||||
coreUpdate: flag(update.available) ? (str(update.available_version) ?? "newer") : null,
|
||||
freeBytes: num(system.freespace),
|
||||
users: num(obj(nc.storage).num_users),
|
||||
files: num(obj(nc.storage).num_files),
|
||||
@@ -69,6 +93,44 @@ export function parseServerInfo(raw: unknown): Pick<NextcloudRead, "freeBytes" |
|
||||
};
|
||||
}
|
||||
|
||||
const SEVERITIES = new Set(["success", "info", "warning", "error"]);
|
||||
|
||||
/** Nextcloud writes a link as a {placeholder} in the text; it is not wanted here, and what is left is tidied. */
|
||||
const plain = (v: unknown): string | null => {
|
||||
const t = str(v);
|
||||
if (!t) return null;
|
||||
const cleaned = t.replace(/\{[A-Za-z0-9_]+\}/g, "").replace(/\s+/g, " ").replace(/\s+([.,;:])/g, "$1").replace(/([.!?])\s*\.+/g, "$1").trim();
|
||||
return cleaned === "" ? null : cleaned;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pure: the setup checks, { category: { checkClass: { name, severity, description } } } (sometimes inside an OCS envelope). Returns Nextcloud's Cron check on its own, and the other
|
||||
* checks that say error or warning; null when the answer is not that shape at all (which is not the same as every check passing).
|
||||
*/
|
||||
export function parseSetupChecks(raw: unknown): { cron: NextcloudRead["cron"]; issues: SetupIssue[] } | null {
|
||||
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
||||
let root = obj(raw);
|
||||
if (root.ocs !== undefined) root = obj(obj(root.ocs).data);
|
||||
else if (root.data !== undefined && Object.keys(root).length <= 2) root = obj(root.data);
|
||||
const categories = Object.values(root).filter((v) => v !== null && typeof v === "object" && !Array.isArray(v));
|
||||
if (categories.length === 0) return Object.keys(root).length === 0 ? { cron: null, issues: [] } : null;
|
||||
let cron: NextcloudRead["cron"] = null;
|
||||
const issues: SetupIssue[] = [];
|
||||
for (const category of categories) {
|
||||
for (const [checkClass, value] of Object.entries(obj(category))) {
|
||||
const r = obj(value);
|
||||
const severity = str(r.severity)?.toLowerCase();
|
||||
if (!severity || !SEVERITIES.has(severity)) continue;
|
||||
if (/(^|\\)CronInfo$/i.test(checkClass)) {
|
||||
cron = { state: severity as SetupSeverity, text: plain(r.description) };
|
||||
continue;
|
||||
}
|
||||
if ((severity === "error" || severity === "warning") && issues.length < MAX_ISSUES) issues.push({ name: str(r.name) ?? checkClass.split("\\").pop() ?? checkClass, severity, text: plain(r.description) });
|
||||
}
|
||||
}
|
||||
return { cron, issues };
|
||||
}
|
||||
|
||||
export function createNextcloudAdapter(config: NextcloudConfig): NextcloudAdapter {
|
||||
const base = String(config.url ?? "").replace(/\/+$/, "");
|
||||
const insecure = config.insecure === true;
|
||||
@@ -87,14 +149,33 @@ export function createNextcloudAdapter(config: NextcloudConfig): NextcloudAdapte
|
||||
const status = parseStatus(await get("/status.php"));
|
||||
if (!status.installed) throw new Error("That Nextcloud says it is not installed yet");
|
||||
let detail: ReturnType<typeof parseServerInfo> = null;
|
||||
let checks: ReturnType<typeof parseSetupChecks> = null;
|
||||
if (login) {
|
||||
try {
|
||||
detail = parseServerInfo(await get("/ocs/v2.php/apps/serverinfo/api/v1/info?format=json", login));
|
||||
} catch {
|
||||
detail = null; // not an administrator, or the Monitoring app is off: the rest is still worth having
|
||||
}
|
||||
try {
|
||||
checks = parseSetupChecks(await get("/settings/setupcheck", login));
|
||||
} catch {
|
||||
checks = null; // before Nextcloud 28 there is no such page: cron is then simply not known
|
||||
}
|
||||
}
|
||||
return { version: status.version, maintenance: status.maintenance, needsUpgrade: status.needsUpgrade, detail: detail !== null, freeBytes: detail?.freeBytes ?? null, users: detail?.users ?? null, files: detail?.files ?? null, active24h: detail?.active24h ?? null, appUpdates: detail?.appUpdates ?? null };
|
||||
return {
|
||||
version: status.version,
|
||||
maintenance: status.maintenance,
|
||||
needsUpgrade: status.needsUpgrade,
|
||||
detail: detail !== null,
|
||||
freeBytes: detail?.freeBytes ?? null,
|
||||
users: detail?.users ?? null,
|
||||
files: detail?.files ?? null,
|
||||
active24h: detail?.active24h ?? null,
|
||||
appUpdates: detail?.appUpdates ?? null,
|
||||
coreUpdate: detail?.coreUpdate ?? null,
|
||||
cron: checks?.cron ?? null,
|
||||
setupIssues: checks ? checks.issues : null,
|
||||
};
|
||||
}
|
||||
|
||||
async function ping(): Promise<{ ok: boolean; latencyMs?: number; error?: string }> {
|
||||
|
||||
@@ -4,7 +4,8 @@ import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { AckError, MAX_HOURS, MAX_NOTE } from "../services/alertAcks.js";
|
||||
import { SnoozeError } from "../services/alertSnoozes.js";
|
||||
import { recordAudit } from "../services/audit.js";
|
||||
import { acknowledgeAlerts, BulkInputError, changeAssets, changeServerTag, MAX_BULK, restoreAcks, restoreAssets, restoreServerParents, restoreSnoozes, setServerParents, setServerTags, silenceTargets, snoozeAlerts, targetsOfAlerts, undoSilence, unacknowledgeAlerts, unsnoozeAlerts } from "../services/bulkActions.js";
|
||||
import { acknowledgeAlerts, BulkInputError, changeAssets, closeAlerts, reopenAlerts, changeServerTag, MAX_BULK, restoreAcks, restoreAssets, restoreServerParents, restoreSnoozes, setServerParents, setServerTags, silenceTargets, snoozeAlerts, targetsOfAlerts, undoSilence, unacknowledgeAlerts, unsnoozeAlerts } from "../services/bulkActions.js";
|
||||
import { addNote, openIncidentIds } from "../services/incidents.js";
|
||||
import { InvalidTagError } from "../services/serverTags.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
@@ -109,7 +110,10 @@ const alertsBody = z.discriminatedUnion("action", [
|
||||
/** When they should come back, as a date and time with its zone. */
|
||||
z.object({ action: z.literal("snooze"), alertIds: stringIds, until: z.string().min(1).max(40) }),
|
||||
z.object({ action: z.literal("unsnooze"), alertIds: stringIds }),
|
||||
z.object({ action: z.literal("restore_snoozes"), items: z.array(z.object({ alertId: z.string().min(1).max(600), previous: snoozeRecord.nullable() })).min(1).max(MAX_BULK) }),
|
||||
/** "Dealt with, or accepted": hidden with no end, until each gets worse. The note is written on each one's incident. */
|
||||
z.object({ action: z.literal("close"), alertIds: stringIds, note: z.string().max(500).nullable().optional() }),
|
||||
z.object({ action: z.literal("reopen"), alertIds: stringIds }),
|
||||
z.object({ action: z.literal("restore_snoozes"), items: z.array(z.object({ alertId: z.string().min(1).max(600), previous: snoozeRecord.nullable() })).min(1).max(MAX_BULK), closed: z.boolean().optional() }),
|
||||
z.object({ action: z.literal("acknowledge"), alertIds: stringIds, note: z.string().max(MAX_NOTE).default(""), assigneeId: z.number().int().positive().nullable().default(null), hours: z.number().int().min(1).max(MAX_HOURS).nullable().default(null) }),
|
||||
z.object({ action: z.literal("unacknowledge"), alertIds: stringIds }),
|
||||
z.object({ action: z.literal("restore_acks"), items: z.array(z.object({ alertId: z.string().min(1).max(600), previous: previousAck })).min(1).max(MAX_BULK) }),
|
||||
@@ -151,9 +155,43 @@ alertsBulkRouter.post("/", asyncHandler(async (req, res) => {
|
||||
await recordAudit({ actor, category: "alert", action: "bulk_unsnooze", detail: { changed: r.changed, alerts: detailIds(body.alertIds) } });
|
||||
return res.json(r);
|
||||
}
|
||||
case "close": {
|
||||
const note = (body.note ?? "").trim() === "" ? null : (body.note ?? "").trim();
|
||||
const who = nameOf(req);
|
||||
const r = await closeAlerts(body.alertIds, note, who);
|
||||
// Each one's incident says it was closed, by whom and why, as when one is closed alone.
|
||||
const open = await openIncidentIds((r.undo?.items ?? []).map((i) => i.alertId));
|
||||
const together = r.changed > 1 ? ` (closed together with ${r.changed - 1} other${r.changed === 2 ? "" : "s"})` : "";
|
||||
for (const item of r.undo?.items ?? []) {
|
||||
const incidentId = open.get(item.alertId);
|
||||
if (incidentId) await addNote(incidentId, who, (note ? "Closed: " + note : "Closed without a note.") + together);
|
||||
}
|
||||
await recordAudit({ actor, category: "alert", action: "bulk_close", detail: { changed: r.changed, note, alerts: detailIds(body.alertIds) } });
|
||||
return res.json(r);
|
||||
}
|
||||
case "reopen": {
|
||||
const who = nameOf(req);
|
||||
const r = await reopenAlerts(body.alertIds);
|
||||
const open = await openIncidentIds((r.undo?.items ?? []).map((i) => i.alertId));
|
||||
for (const item of r.undo?.items ?? []) {
|
||||
const incidentId = open.get(item.alertId);
|
||||
if (incidentId) await addNote(incidentId, who, "Opened again.");
|
||||
}
|
||||
await recordAudit({ actor, category: "alert", action: "bulk_reopen", detail: { changed: r.changed, alerts: detailIds(body.alertIds) } });
|
||||
return res.json(r);
|
||||
}
|
||||
case "restore_snoozes": {
|
||||
const changed = await restoreSnoozes(body.items);
|
||||
await recordAudit({ actor, category: "alert", action: "bulk_undo", detail: { changed, what: "snooze" } });
|
||||
if (body.closed) {
|
||||
// The undo of closing several: those that are open again say so on their incidents.
|
||||
const reopened = body.items.filter((i) => i.previous?.kind !== "closed").map((i) => i.alertId);
|
||||
const open = await openIncidentIds(reopened);
|
||||
for (const alertId of reopened) {
|
||||
const incidentId = open.get(alertId);
|
||||
if (incidentId) await addNote(incidentId, nameOf(req), "Opened again (closing it was undone).");
|
||||
}
|
||||
}
|
||||
await recordAudit({ actor, category: "alert", action: "bulk_undo", detail: { changed, what: body.closed ? "close" : "snooze" } });
|
||||
return res.json({ changed, skipped: [], undo: null });
|
||||
}
|
||||
case "silence": {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { integrations, nextcloudState } from "../db/schema.js";
|
||||
import { requireAuth } from "../auth/middleware.js";
|
||||
import { isNextcloudFresh, nextcloudProblems, nextcloudSyncStatuses } from "../services/nextcloudSync.js";
|
||||
import { isNextcloudFresh, nextcloudProblems, nextcloudSyncStatuses, setupIssuesOf } from "../services/nextcloudSync.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const nextcloudRouter = Router();
|
||||
@@ -40,6 +40,9 @@ nextcloudRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
files: state.files,
|
||||
active24h: state.active24h,
|
||||
appUpdates: state.appUpdates,
|
||||
coreUpdate: state.coreUpdate,
|
||||
cron: state.cronState ? { state: state.cronState, text: state.cronText } : null,
|
||||
setupIssues: setupIssuesOf(state),
|
||||
updatedAt: state.updatedAt,
|
||||
}
|
||||
: null,
|
||||
|
||||
@@ -121,7 +121,7 @@ function originOfConditionKey(key: string): { type: string; id: number | null; c
|
||||
if (m) return { type: "dockhand", id: Number(m[1]), category: "services" };
|
||||
m = /^duplicati-(?:failed|stale):(\d+)/.exec(key);
|
||||
if (m) return { type: "duplicati", id: Number(m[1]), category: "backup" };
|
||||
m = /^nextcloud-(?:maintenance|upgrade|disk):(\d+)/.exec(key);
|
||||
m = /^nextcloud-(?:maintenance|upgrade|disk|cron|checks):(\d+)/.exec(key);
|
||||
if (m) return { type: "nextcloud", id: Number(m[1]), category: key.startsWith("nextcloud-disk") ? "disk" : "services" };
|
||||
m = /^netbox-(?:workers):(\d+)/.exec(key);
|
||||
if (m) return { type: "netbox", id: Number(m[1]), category: "services" };
|
||||
|
||||
@@ -8,7 +8,7 @@ import { db } from "../db/client.js";
|
||||
import { assets, maintenanceWindows, servers } from "../db/schema.js";
|
||||
import { invalidateAlertsCache, getAlerts } from "./alerts.js";
|
||||
import { clearAck, restoreAck, setAck, type AckInfo, type SetAckInput } from "./alertAcks.js";
|
||||
import { clearSnooze, readSnooze, restoreSnooze, setSnooze, type SnoozeRecord } from "./alertSnoozes.js";
|
||||
import { clearSnooze, readSnooze, restoreSnooze, setClosed, setSnooze, type SnoozeRecord } from "./alertSnoozes.js";
|
||||
import { keyOfAlertId } from "./flapGuard.js";
|
||||
import { impactOf } from "./dependencies.js";
|
||||
import { isRealDate } from "./inventory.js";
|
||||
@@ -237,6 +237,44 @@ export async function restoreAcks(items: AcksUndo["items"]): Promise<number> {
|
||||
export interface SnoozesUndo {
|
||||
action: "restore_snoozes";
|
||||
items: { alertId: string; previous: SnoozeRecord | null }[];
|
||||
/** The undo of closing several: the ones it opens again say so on their incidents. */
|
||||
closed?: boolean;
|
||||
}
|
||||
|
||||
/** Closes each alert the same way (see setClosed): hidden with no end, until it gets worse. Alerts that are no longer there are skipped. */
|
||||
export async function closeAlerts(alertIds: string[], note: string | null, actor: string, now: Date = new Date()): Promise<BulkResult<SnoozesUndo>> {
|
||||
const present = new Map((await getAlerts(false)).alerts.map((a) => [a.id, a]));
|
||||
const skipped: Skipped[] = [];
|
||||
const items: SnoozesUndo["items"] = [];
|
||||
for (const alertId of unique(alertIds)) {
|
||||
const alert = present.get(alertId);
|
||||
if (!alert) {
|
||||
skipped.push({ id: alertId, name: alertId, reason: "it isn't there any more" });
|
||||
continue;
|
||||
}
|
||||
const previous = await readSnooze(alertId);
|
||||
await setClosed({ alertId, conditionKey: keyOfAlertId(alert.id, alert.category), message: alert.message, severity: alert.severity, note, actor }, now);
|
||||
items.push({ alertId, previous });
|
||||
}
|
||||
if (items.length > 0) invalidateAlertsCache();
|
||||
return { changed: items.length, skipped, undo: items.length > 0 ? { action: "restore_snoozes", items, closed: true } : null };
|
||||
}
|
||||
|
||||
/** Opens each closed alert again. One that is only snoozed (or neither) is left as it is. */
|
||||
export async function reopenAlerts(alertIds: string[]): Promise<BulkResult<SnoozesUndo>> {
|
||||
const skipped: Skipped[] = [];
|
||||
const items: SnoozesUndo["items"] = [];
|
||||
for (const alertId of unique(alertIds)) {
|
||||
const previous = await readSnooze(alertId);
|
||||
if (!previous || previous.kind !== "closed") {
|
||||
skipped.push({ id: alertId, name: alertId, reason: "it wasn't closed" });
|
||||
continue;
|
||||
}
|
||||
await clearSnooze(alertId);
|
||||
items.push({ alertId, previous });
|
||||
}
|
||||
if (items.length > 0) invalidateAlertsCache();
|
||||
return { changed: items.length, skipped, undo: items.length > 0 ? { action: "restore_snoozes", items } : null };
|
||||
}
|
||||
|
||||
/** Snoozes each alert until the same time (an earlier snooze is replaced). Alerts that are no longer there are skipped. A time that is not allowed refuses the whole thing, before anything is changed. */
|
||||
@@ -264,8 +302,8 @@ export async function unsnoozeAlerts(alertIds: string[]): Promise<BulkResult<Sno
|
||||
const items: SnoozesUndo["items"] = [];
|
||||
for (const alertId of unique(alertIds)) {
|
||||
const previous = await readSnooze(alertId);
|
||||
if (!previous) {
|
||||
skipped.push({ id: alertId, name: alertId, reason: "it wasn't snoozed" });
|
||||
if (!previous || previous.kind === "closed") {
|
||||
skipped.push({ id: alertId, name: alertId, reason: previous ? "it is closed, not snoozed — use Open again" : "it wasn't snoozed" });
|
||||
continue;
|
||||
}
|
||||
await clearSnooze(alertId);
|
||||
|
||||
@@ -183,7 +183,11 @@ export function describeChange(category: string, action: string, detail: Record<
|
||||
case "note/photo_delete":
|
||||
return { title: `A photo was removed from a note${name ? ` on ${name}` : ""}`, tone: "neutral", detail: null };
|
||||
case "alert/bulk_undo":
|
||||
return { title: detail.what === "snooze" ? "Snoozing several alerts at once was undone" : "Acknowledging several alerts at once was undone", tone: "neutral", detail: null };
|
||||
return { title: detail.what === "snooze" ? "Snoozing several alerts at once was undone" : detail.what === "close" ? "Closing several alerts at once was undone" : "Acknowledging several alerts at once was undone", tone: "neutral", detail: null };
|
||||
case "alert/bulk_close":
|
||||
return { title: `${typeof detail.changed === "number" ? detail.changed : "Several"} alert${detail.changed === 1 ? "" : "s"} closed at once`, tone: "neutral", detail: str(detail.note) };
|
||||
case "alert/bulk_reopen":
|
||||
return { title: `${typeof detail.changed === "number" ? detail.changed : "Several"} closed alert${detail.changed === 1 ? "" : "s"} opened again at once`, tone: "neutral", detail: null };
|
||||
case "alert/bulk_snooze":
|
||||
return { title: `${typeof detail.changed === "number" ? detail.changed : "Several"} alert${detail.changed === 1 ? "" : "s"} snoozed at once`, tone: "neutral", detail: str(detail.until) ? `until ${str(detail.until)!.slice(0, 16).replace("T", " ")} UTC` : null };
|
||||
case "alert/bulk_unsnooze":
|
||||
|
||||
@@ -33,7 +33,7 @@ export function subjectOfConditionKey(key: string): string | null {
|
||||
if (m) return `integration:${m[1]}`;
|
||||
m = /^jellyfin-(?:restart|task|logins):(\d+)/.exec(key);
|
||||
if (m) return `integration:${m[1]}`;
|
||||
m = /^nextcloud-(?:maintenance|upgrade|disk):(\d+)/.exec(key);
|
||||
m = /^nextcloud-(?:maintenance|upgrade|disk|cron|checks):(\d+)/.exec(key);
|
||||
if (m) return `integration:${m[1]}`;
|
||||
m = /^netbox-(?:workers):(\d+)/.exec(key);
|
||||
if (m) return `integration:${m[1]}`;
|
||||
|
||||
@@ -78,6 +78,7 @@ async function addNextcloudMetrics(out: Exposition, now: Date) {
|
||||
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.cronState !== null) out.add("homelab_nextcloud_cron_ok", "gauge", "1 if Nextcloud's own check says its background jobs ran within the last hour, else 0; absent when it could not be asked.", s.cronState === "error" ? 0 : 1, labels);
|
||||
if (s.appUpdates !== null) out.add("homelab_nextcloud_app_updates", "gauge", "How many apps have an update waiting.", s.appUpdates, labels);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { integrations, nextcloudState } from "../db/schema.js";
|
||||
import { createNextcloudAdapter, type NextcloudRead } from "../integrations/nextcloud/adapter.js";
|
||||
import { createNextcloudAdapter, type NextcloudRead, type SetupIssue } from "../integrations/nextcloud/adapter.js";
|
||||
import { loadIntegrationConfig } from "../integrations/loadIntegration.js";
|
||||
import { getInternalFlag, setInternalFlag } from "./settingsStore.js";
|
||||
|
||||
@@ -44,6 +44,17 @@ export const isNextcloudFresh = (status: NextcloudSyncStatus | undefined, nowMs:
|
||||
|
||||
export type StateRow = typeof nextcloudState.$inferSelect;
|
||||
|
||||
/** The other setup checks that report an error or a warning; null when the checks could not be asked (not the same as there being none). */
|
||||
export const setupIssuesOf = (row: Pick<StateRow, "setupIssues">): SetupIssue[] | null => {
|
||||
if (row.setupIssues === null) return null;
|
||||
try {
|
||||
const v = JSON.parse(row.setupIssues);
|
||||
return Array.isArray(v) ? (v as SetupIssue[]) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/** Writes down one read, replacing the last. */
|
||||
export async function storeRead(integrationId: number, r: NextcloudRead, now: Date = new Date()): Promise<void> {
|
||||
const values = {
|
||||
@@ -56,6 +67,10 @@ export async function storeRead(integrationId: number, r: NextcloudRead, now: Da
|
||||
files: r.files,
|
||||
active24h: r.active24h,
|
||||
appUpdates: r.appUpdates,
|
||||
coreUpdate: r.coreUpdate,
|
||||
cronState: r.cron?.state ?? null,
|
||||
cronText: r.cron?.text ?? null,
|
||||
setupIssues: r.setupIssues && JSON.stringify(r.setupIssues),
|
||||
updatedAt: now.toISOString(),
|
||||
};
|
||||
await db.insert(nextcloudState).values({ integrationId, ...values }).onConflictDoUpdate({ target: nextcloudState.integrationId, set: values });
|
||||
@@ -112,13 +127,24 @@ export interface NextcloudProblem {
|
||||
const gb = (bytes: number) => `${(bytes / 1024 ** 3).toFixed(bytes >= 100 * 1024 ** 3 ? 0 : 1)} GB`;
|
||||
|
||||
/** Pure: what is wrong with one Nextcloud, from what is stored for it. */
|
||||
export function nextcloudProblems(id: number, name: string, s: Pick<StateRow, "maintenance" | "needsUpgrade" | "freeBytes">): NextcloudProblem[] {
|
||||
export function nextcloudProblems(id: number, name: string, s: Pick<StateRow, "maintenance" | "needsUpgrade" | "freeBytes"> & Partial<Pick<StateRow, "cronState" | "cronText" | "setupIssues">>): NextcloudProblem[] {
|
||||
const out: NextcloudProblem[] = [];
|
||||
if (s.needsUpgrade) out.push({ key: `nextcloud-upgrade:${id}`, severity: "critical", message: `${name}: its database needs upgrading — nobody can use it until "occ upgrade" has been run` });
|
||||
if (s.maintenance) out.push({ key: `nextcloud-maintenance:${id}`, severity: "warning", message: `${name} is in maintenance mode — nobody can sign in ("occ maintenance:mode --off" ends it)` });
|
||||
if (s.freeBytes !== null && s.freeBytes < FREE_WARN_BYTES) {
|
||||
out.push({ key: `nextcloud-disk:${id}`, severity: s.freeBytes < FREE_CRITICAL_BYTES ? "critical" : "warning", message: `${name}: only ${gb(s.freeBytes)} is left where the data is kept` });
|
||||
}
|
||||
// Nextcloud's own "Cron last run" check says error when the last background job ran more than an hour ago: nothing it does in the background (notifications, clean-up, indexing, sharing
|
||||
// expiry) is being done. Not known (no login, or before Nextcloud 28) is not a problem.
|
||||
if (s.cronState === "error") {
|
||||
out.push({ key: `nextcloud-cron:${id}`, severity: "warning", message: `${name}: its background jobs are not running — ${s.cronText ?? "the last run was more than an hour ago"}` });
|
||||
}
|
||||
// The rest of what Nextcloud's own checks call an error (a warning is only shown on the page).
|
||||
const errors = (setupIssuesOf({ setupIssues: s.setupIssues ?? null }) ?? []).filter((i) => i.severity === "error");
|
||||
if (errors.length > 0) {
|
||||
const names = errors.slice(0, 3).map((i) => i.name).join("; ") + (errors.length > 3 ? ` and ${errors.length - 3} more` : "");
|
||||
out.push({ key: `nextcloud-checks:${id}`, severity: "warning", message: `${name}: Nextcloud's own checks report ${errors.length === 1 ? "an error" : `${errors.length} errors`} — ${names}${errors.length === 1 && errors[0].text ? ` (${errors[0].text})` : ""}` });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user