Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Make alert threshold Off stick for Docker, PMG and backups
rcourtmanc22871c0bde7
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.mdindex 5dd17b9271..7e3638ac2a 100644--- a/docs/release-control/v6/internal/subsystems/alerts.md+++ b/docs/release-control/v6/internal/subsystems/alerts.md@@ -4010,10 +4010,10 @@ defaults states them in its header throughreads the same column list and defaults object the group's resource tableedits (each section hoists its columns into one module constant), and dropsevery metric `isAlertResourceMetricOff` reports, so the header can never show-a limit the engine is not evaluating. Rules whose zero means a fallback rather-than Off are stated as whole rules with their effective values: Docker's-restart loop (count within its window) and memory-limit warn/critical, which-`NormalizeDockerDefaults` always resolves to positive values. Backup age is+a limit the engine is not evaluating. Docker's restart loop (count within its+window) and memory-limit warn/critical are stated as whole rules with their+effective values: an unset value is the factory value, and a rule or level at+0 reads "off", as the engine evaluates it. Backup age issummarized by its warning and critical days only, because fresh and stalehours colour the dashboard and never alert. A group switched off as a wholeshows its Disabled badge and no defaults line. The CPU averaging line counts@@ -4025,6 +4025,45 @@ and Machines list their resource groups before Docker-only rules and theSMART card. Threshold values, inheritance, metric evaluation windows andpersistence are unchanged.+### Off is 0 for Docker and PMG count thresholds, and per-row edits exist only where an override stores them++Docker's restart-loop and memory-limit thresholds and every PMG threshold are+plain ints in `DockerThresholdConfig` and `PMGThresholdConfig`, and 0 is Off:+the PMG checks already skipped a level at 0, and the Docker restart-loop check+now turns off when its count or window is 0 while the memory-limit check+evaluates warning and critical as independent levels. The settings Off toggle+sends -1, so `NormalizeDockerDefaults` and `NormalizePMGDefaults` store any+negative value as 0 instead of the factory value they used to substitute, which+reverted every Off on save. To keep a value an older `alerts.json` or an import+predates from reading as Off, `AlertConfig` and both threshold types decode+omitted keys as `ThresholdCountUnset`, and the normalizers (also run by+`ConfigPersistence` on load and save) replace that marker with the factory+value before the config is used or written. A PMG quarantine growth level needs+both its percentage and its minimum growth; either at 0 turns that level off,+because passing one alone made the canonical spec invalid and skipped the whole+quarantine check.++A Docker container override re-enables state alerts over a disabled Docker+default only when it carries its own powered-off severity, the same rule+`applyThresholdOverride` applies to every other resource. `DisableConnectivity`+is a plain bool, so an override saved for a CPU threshold alone used to turn+that container's state alerts back on.++The frontend mirrors the backend instead of second-guessing it. Backup and+snapshot ages keep a critical of 0 Off, both in the editor's sanitizers+(`useThresholdsRecoveryDefaultsState`) and in the saved payload+(`normalizeAgeWarningCriticalPair`); only snapshot sizes raise a 0 critical to+the warning size, as the backend does. Per-resource rows offer only metrics `ThresholdConfig` stores:+`alertResourceSupportsMetric` gives Docker containers CPU and memory, and PMG+servers nothing, and the PMG section has no bulk edit, because restart,+memory-limit and PMG thresholds exist only as defaults and the backend dropped+per-container and per-server edits of them on save.++Not covered here: AI Patrol's threshold adapter (`internal/ai/alert_threshold_adapter.go`)+still maps an Off alert threshold to its factory value, so Patrol keeps flagging+a metric whose alerts are off; honouring Off there is a Patrol product decision,+because a zero Patrol level would flag every reading.+### External watchdog is Pulse-availability evidence, not notification deliveryThe Alerts destinations surface owns the operator contract for an externaldiff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.mdindex 5fe2a4daba..eaf7f1fa6c 100644--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md@@ -9264,3 +9264,14 @@ VmwareOverview retains the page-owned workload state and renders an h2 VMsthrough the WorkloadsSurface tableTitle slot. Kiosk may remove the filter bar,not this name. The count is filtered rows once shared-toolbar readiness holds,including zero; no extra state, toolbar, route or hidden input is added.++### Threshold Off reads as the engine reads it (11 October 2026)++The alerts feature model and the shared threshold summary helper mirror the+backend's Off encoding rather than substituting their own. A backup or snapshot+critical age left Off stays 0 instead of rising to the warning age, and the+Docker restart-loop and memory-limit summary items read "off" for a rule or+level at 0 instead of restating factory values. Per-resource rows render a+muted dash for metrics an override cannot store (Docker container restart and+memory-limit rules, every PMG threshold). No shared primitive, table component+or layout changes.diff --git a/frontend-modern/browser-verification/96afaaf634d5c422.json b/frontend-modern/browser-verification/96afaaf634d5c422.jsonnew file mode 100644index 0000000000..4f9be724c5--- /dev/null+++ b/frontend-modern/browser-verification/96afaaf634d5c422.json@@ -0,0 +1,56 @@+{+ "version": 1,+ "base_sha": "149b55c3f942464f4978bcf3f4b26f7f45063f7e",+ "verified_at": "2026-10-11T17:03:40Z",+ "result": "passed",+ "changed_paths": [+ "frontend-modern/src/components/Alerts/ThresholdsTableProxmoxPMGSection.tsx",+ "frontend-modern/src/components/Alerts/alertResourceTableModel.ts",+ "frontend-modern/src/features/alerts/alertsConfigurationModel.ts",+ "frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsRecoveryDefaultsState.ts",+ "frontend-modern/src/utils/alertThresholdsSectionPresentation.ts"+ ],+ "content_sha256": {+ "frontend-modern/src/components/Alerts/ThresholdsTableProxmoxPMGSection.tsx": "bddf4da818ec12d05e2992fa752cc0a0ceec6140185b96afbea3943f9a507ec1",+ "frontend-modern/src/components/Alerts/alertResourceTableModel.ts": "93098cd63b72a56cda1a8bd21280b57b39569f3b967f45dc2fabc72f9accb390",+ "frontend-modern/src/features/alerts/alertsConfigurationModel.ts": "7371a268e73420581c857d987a5c373b8418af0ad3c6f424c45fae9b987eea5f",+ "frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsRecoveryDefaultsState.ts": "6624fc383186a07e5e68f0ab5bfa824bf67ae185f1cc595ff99777d95cfc4fb3",+ "frontend-modern/src/utils/alertThresholdsSectionPresentation.ts": "fb7e3ccb888c627e7ced6a3ae6c2b7c8ee5d27b309360a1fe5ae0582b5e8dcd5"+ },+ "routes": [+ "/alerts/thresholds/mail-gateway",+ "/alerts/thresholds/docker",+ "/alerts/thresholds/proxmox"+ ],+ "viewports": [+ {+ "width": 1280,+ "height": 900+ },+ {+ "width": 800,+ "height": 600+ },+ {+ "width": 760,+ "height": 900+ }+ ],+ "states": [+ "Private PULSE_MOCK_MODE stack (sidecar backend on :7687, Vite on :5197), fresh data dir: alert config reports factory Docker restart 3 / memory warn 90 and PMG queue warn 500",+ "Mail Gateway Thresholds global defaults with Queue Warn and Growth Warn Min Off after save and reload; header omits Queue Warn; API and alerts.json store 0 for both; no invalid quarantine spec warnings in the backend log",+ "Mail Gateway per-server cards (mail-gateway-eu, mail-gateway-us) show only the offline control, and the row editor offers only a note and offline, no queue fields",+ "Docker Containers global defaults with Restart Count and Memory Warn % Off after save and reload; header reads Restart loop off; API and alerts.json store 0 for both",+ "Docker container cards (loki, loki-2, nginx-edge) show CPU and Memory only; the loki editor offers note, CPU and Memory only; desktop container rows show no restart or memory-limit cells",+ "Recovery global defaults enabled with Critical Days Off after save and reload; header reads Warning 7 days; API stores criticalDays 0 with warningDays 7 (before the sanitizer fix the same toggle snapped to Critical 7)",+ "Docker container state alert for stopped nextcloud cleared by the Docker offline default and stays cleared after a CPU-only override for that container is saved"+ ],+ "interactions": [+ "Expanded Mail Gateway Thresholds, toggled Queue Warn and Growth Warn Min Off, clicked Save Changes, reloaded",+ "Opened the mail-gateway-eu row editor and cancelled it",+ "Expanded Containers at 1280px and 760px, toggled Restart Count and Memory Warn % Off, clicked Save Changes, reloaded",+ "Opened and cancelled the loki container threshold editor",+ "Expanded Recovery, enabled backup alerts, toggled Critical Days Off, clicked Save Changes, reloaded",+ "PUT /api/alerts/config with stateDisableConnectivity and then a CPU-only nextcloud override; read /api/alerts/active after each poll"+ ]+}diff --git a/frontend-modern/src/components/Alerts/ThresholdsTableProxmoxPMGSection.tsx b/frontend-modern/src/components/Alerts/ThresholdsTableProxmoxPMGSection.tsxindex a658b8d4ab..b73b9e1b0b 100644--- a/frontend-modern/src/components/Alerts/ThresholdsTableProxmoxPMGSection.tsx+++ b/frontend-modern/src/components/Alerts/ThresholdsTableProxmoxPMGSection.tsx@@ -65,7 +65,6 @@ export function ThresholdsTableProxmoxPMGSection(props: ThresholdsTableSectionPrsetEditingThresholds={state.setEditingThresholds}editingNote={state.editingNote}setEditingNote={state.setEditingNote}- onBulkEdit={(ids) => state.handleBulkEdit(ids, ['CPU %', 'Memory %', 'Disk %'])}formatMetricValue={formatMetricValue}hasActiveAlert={state.hasActiveAlert}globalDefaults={state.pmgGlobalDefaults()}diff --git a/frontend-modern/src/components/Alerts/__tests__/alertResourceTableModel.branchcov0712.test.ts b/frontend-modern/src/components/Alerts/__tests__/alertResourceTableModel.branchcov0712.test.tsindex 24299a0597..11f0331833 100644--- a/frontend-modern/src/components/Alerts/__tests__/alertResourceTableModel.branchcov0712.test.ts+++ b/frontend-modern/src/components/Alerts/__tests__/alertResourceTableModel.branchcov0712.test.ts@@ -551,22 +551,35 @@ describe('alertResourceSupportsMetric', () => {});});+ // PMG thresholds exist only as PMG defaults; per-server edits were dropped.+ describe('pmg — nothing supported per server', () => {+ it('returns false for queue and host metrics', () => {+ expect(alertResourceSupportsMetric('pmg', 'queueTotalWarning')).toBe(false);+ expect(alertResourceSupportsMetric('pmg', 'cpu')).toBe(false);+ });+ });+describe('vmwareNetwork — nothing supported', () => {it('returns false for any metric', () => {expect(alertResourceSupportsMetric('vmwareNetwork', 'cpu')).toBe(false);});});- describe('dockerContainer — restart + memory-warn set', () => {- it('supports restart and memory-warn metrics', () => {- expect(alertResourceSupportsMetric('dockerContainer', 'restartCount')).toBe(true);- expect(alertResourceSupportsMetric('dockerContainer', 'restartWindow')).toBe(true);- expect(alertResourceSupportsMetric('dockerContainer', 'memoryWarnPct')).toBe(true);- expect(alertResourceSupportsMetric('dockerContainer', 'memoryCriticalPct')).toBe(true);+ describe('dockerContainer — cpu and memory only', () => {+ it('supports the metrics a container override stores', () => {expect(alertResourceSupportsMetric('dockerContainer', 'cpu')).toBe(true);expect(alertResourceSupportsMetric('dockerContainer', 'memory')).toBe(true);});+ // Restart and memory-limit rules exist only as Docker defaults; the+ // backend dropped per-container edits of them on save.+ it('rejects the restart and memory-limit rules', () => {+ expect(alertResourceSupportsMetric('dockerContainer', 'restartCount')).toBe(false);+ expect(alertResourceSupportsMetric('dockerContainer', 'restartWindow')).toBe(false);+ expect(alertResourceSupportsMetric('dockerContainer', 'memoryWarnPct')).toBe(false);+ expect(alertResourceSupportsMetric('dockerContainer', 'memoryCriticalPct')).toBe(false);+ });+it('rejects temperature and disk', () => {expect(alertResourceSupportsMetric('dockerContainer', 'temperature')).toBe(false);expect(alertResourceSupportsMetric('dockerContainer', 'disk')).toBe(false);diff --git a/frontend-modern/src/components/Alerts/__tests__/alertResourceTableModel.branchcov2.test.ts b/frontend-modern/src/components/Alerts/__tests__/alertResourceTableModel.branchcov2.test.tsindex 40dd64ab6a..d9d1487f3a 100644--- a/frontend-modern/src/components/Alerts/__tests__/alertResourceTableModel.branchcov2.test.ts+++ b/frontend-modern/src/components/Alerts/__tests__/alertResourceTableModel.branchcov2.test.ts@@ -581,14 +581,12 @@ describe('alertResourceSupportsMetric', () => {});});- describe('dockerContainer — restart + memory-warn set', () => {- it('supports restart and memory-warn metrics', () => {- expect(alertResourceSupportsMetric('dockerContainer', 'restartCount')).toBe(true);- expect(alertResourceSupportsMetric('dockerContainer', 'restartWindow')).toBe(true);- expect(alertResourceSupportsMetric('dockerContainer', 'memoryWarnPct')).toBe(true);- expect(alertResourceSupportsMetric('dockerContainer', 'memoryCriticalPct')).toBe(true);+ describe('dockerContainer — cpu and memory only', () => {+ it('supports cpu and memory but not the Docker-default-only rules', () => {expect(alertResourceSupportsMetric('dockerContainer', 'cpu')).toBe(true);expect(alertResourceSupportsMetric('dockerContainer', 'memory')).toBe(true);+ expect(alertResourceSupportsMetric('dockerContainer', 'restartCount')).toBe(false);+ expect(alertResourceSupportsMetric('dockerContainer', 'memoryWarnPct')).toBe(false);});it('rejects temperature and disk', () => {diff --git a/frontend-modern/src/components/Alerts/alertResourceTableModel.ts b/frontend-modern/src/components/Alerts/alertResourceTableModel.tsindex dd2ef9076b..c23a97acce 100644--- a/frontend-modern/src/components/Alerts/alertResourceTableModel.ts+++ b/frontend-modern/src/components/Alerts/alertResourceTableModel.ts@@ -377,15 +377,15 @@ export function alertResourceSupportsMetric(if (resourceType === 'vmwareNetwork') {return false;}+ // A per-resource override stores only the metrics in the backend's+ // ThresholdConfig. Restart and memory-limit rules exist only as Docker+ // defaults, and PMG thresholds only as PMG defaults, so the backend dropped+ // per-container and per-server edits of them on save.if (resourceType === 'dockerContainer') {- return [- 'cpu',- 'memory',- 'restartCount',- 'restartWindow',- 'memoryWarnPct',- 'memoryCriticalPct',- ].includes(metric);+ return ['cpu', 'memory'].includes(metric);+ }+ if (resourceType === 'pmg') {+ return false;}return true;}diff --git a/frontend-modern/src/features/alerts/__tests__/alertsConfigurationModel.coverage.test.ts b/frontend-modern/src/features/alerts/__tests__/alertsConfigurationModel.coverage.test.tsindex 06c3fce0c4..1809afb8ba 100644--- a/frontend-modern/src/features/alerts/__tests__/alertsConfigurationModel.coverage.test.ts+++ b/frontend-modern/src/features/alerts/__tests__/alertsConfigurationModel.coverage.test.ts@@ -150,7 +150,7 @@ describe('normalizeWarningCriticalPair', () => {expect(snapshot.backupDefaults.criticalDays).toBe(7);});- it('clamps negative warning and critical inputs to 0 and collapses critical to warning', () => {+ it('clamps negative warning and critical inputs to 0 (both Off)', () => {const snapshot = readAlertsConfigurationSnapshot({overrides: {},backupDefaults: { enabled: true, warningDays: -3, criticalDays: -9 },@@ -170,24 +170,49 @@ describe('normalizeWarningCriticalPair', () => {expect(snapshot.backupDefaults.criticalDays).toBe(14);});- it('inherits critical from warning when critical is 0 (build snapshotDefaults path)', () => {+ // The backend reads a 0 critical age as Off. Raising it to the warning age+ // made snapshots and backups go critical at the warning age.+ it('keeps a critical age of 0 Off (build snapshotDefaults path)', () => {const snapshot = createDefaultAlertsConfigurationSnapshot();snapshot.snapshotDefaults = { enabled: true, warningDays: 15, criticalDays: 0 };const { alertConfig } = buildFromSnapshot(snapshot);expect(alertConfig?.snapshotDefaults?.warningDays).toBe(15);- expect(alertConfig?.snapshotDefaults?.criticalDays).toBe(15);+ expect(alertConfig?.snapshotDefaults?.criticalDays).toBe(0);});- it('defaults an undefined critical to 0 and inherits the warning value', () => {+ it('saves the Off toggle value for a backup critical age as 0, not the warning age', () => {+ const snapshot = createDefaultAlertsConfigurationSnapshot();+ snapshot.backupDefaults = { ...snapshot.backupDefaults, warningDays: 7, criticalDays: -1 };++ const { alertConfig } = buildFromSnapshot(snapshot);++ expect(alertConfig?.backupDefaults?.warningDays).toBe(7);+ expect(alertConfig?.backupDefaults?.criticalDays).toBe(0);+ });++ it('reads an undefined critical age as Off', () => {const snapshot = readAlertsConfigurationSnapshot({overrides: {},backupDefaults: { enabled: true, warningDays: 4, criticalDays: undefined },} as unknown as AlertConfig);expect(snapshot.backupDefaults.warningDays).toBe(4);- expect(snapshot.backupDefaults.criticalDays).toBe(4);+ expect(snapshot.backupDefaults.criticalDays).toBe(0);+ });++ it('still raises a 0 critical snapshot size to the warning size, as the backend does', () => {+ const snapshot = createDefaultAlertsConfigurationSnapshot();+ snapshot.snapshotDefaults = {+ ...snapshot.snapshotDefaults,+ warningSizeGiB: 50,+ criticalSizeGiB: 0,+ };++ const { alertConfig } = buildFromSnapshot(snapshot);++ expect(alertConfig?.snapshotDefaults?.criticalSizeGiB).toBe(50);});});diff --git a/frontend-modern/src/features/alerts/__tests__/alertsConfigurationModel.test.ts b/frontend-modern/src/features/alerts/__tests__/alertsConfigurationModel.test.tsindex cbb7e71946..111b647d14 100644--- a/frontend-modern/src/features/alerts/__tests__/alertsConfigurationModel.test.ts+++ b/frontend-modern/src/features/alerts/__tests__/alertsConfigurationModel.test.ts@@ -315,4 +315,37 @@ describe('alertsConfigurationModel', () => {}expect(reloaded.storageDefault).toBe(0);});++ // The backend reads a critical age of 0 as Off. The editor's Off toggle+ // stages -1, which used to be raised to the warning age, so backups and+ // snapshots went critical at the warning age instead of never.+ it('saves an Off backup or snapshot critical age as 0 and reads it back Off', () => {+ const snapshot = createDefaultAlertsConfigurationSnapshot();+ snapshot.backupDefaults = {+ ...snapshot.backupDefaults,+ warningDays: 7,+ criticalDays: ALERT_RESOURCE_METRIC_OFF_VALUE,+ };+ snapshot.snapshotDefaults = {+ ...snapshot.snapshotDefaults,+ warningDays: 30,+ criticalDays: ALERT_RESOURCE_METRIC_OFF_VALUE,+ };++ const { alertConfig } = buildAlertsConfigurationPayload({+ snapshot,+ rawOverridesConfig: {},+ alertsActivationState: null,+ alertsActivationConfig: null,+ });++ expect(alertConfig?.backupDefaults?.warningDays).toBe(7);+ expect(alertConfig?.backupDefaults?.criticalDays).toBe(0);+ expect(alertConfig?.snapshotDefaults?.warningDays).toBe(30);+ expect(alertConfig?.snapshotDefaults?.criticalDays).toBe(0);++ const reloaded = readAlertsConfigurationSnapshot(alertConfig as AlertConfig);+ expect(reloaded.backupDefaults.criticalDays).toBe(0);+ expect(reloaded.snapshotDefaults.criticalDays).toBe(0);+ });});diff --git a/frontend-modern/src/features/alerts/alertsConfigurationModel.ts b/frontend-modern/src/features/alerts/alertsConfigurationModel.tsindex c5c5bbe880..a539723198 100644--- a/frontend-modern/src/features/alerts/alertsConfigurationModel.ts+++ b/frontend-modern/src/features/alerts/alertsConfigurationModel.ts@@ -231,6 +231,22 @@ const normalizeWarningCriticalPair = (};};+// Backup and snapshot ages, as the backend reads them: each level is Off at 0+// (the editor's Off toggle stages -1), and a warning above a set critical+// drops to it. Unlike sizes, a critical age left Off stays Off; raising it to+// the warning age made backups go critical at the warning age.+const normalizeAgeWarningCriticalPair = (+ warning: number | undefined,+ critical: number | undefined,+): { warning: number; critical: number } => {+ const safeWarning = Math.max(0, warning ?? 0);+ const safeCritical = Math.max(0, critical ?? 0);+ return {+ warning: safeCritical > 0 && safeWarning > safeCritical ? safeCritical : safeWarning,+ critical: safeCritical,+ };+};+const normalizeStringList = (values: string[] | undefined): string[] =>(values ?? []).map((value) => value.trim()).filter((value) => value.length > 0);@@ -562,7 +578,7 @@ export function readAlertsConfigurationSnapshot(config: AlertConfig): AlertsConf}if (config.backupDefaults) {- const normalizedPair = normalizeWarningCriticalPair(+ const normalizedPair = normalizeAgeWarningCriticalPair(config.backupDefaults.warningDays,config.backupDefaults.criticalDays,);@@ -585,7 +601,7 @@ export function readAlertsConfigurationSnapshot(config: AlertConfig): AlertsConf}if (config.snapshotDefaults) {- const normalizedPair = normalizeWarningCriticalPair(+ const normalizedPair = normalizeAgeWarningCriticalPair(config.snapshotDefaults.warningDays,config.snapshotDefaults.criticalDays,);@@ -745,7 +761,7 @@ export function buildAlertsConfigurationPayload({};}- const normalizedSnapshotPair = normalizeWarningCriticalPair(+ const normalizedSnapshotPair = normalizeAgeWarningCriticalPair(snapshot.snapshotDefaults.warningDays,snapshot.snapshotDefaults.criticalDays,);@@ -753,7 +769,7 @@ export function buildAlertsConfigurationPayload({snapshot.snapshotDefaults.warningSizeGiB,snapshot.snapshotDefaults.criticalSizeGiB,);- const normalizedBackupPair = normalizeWarningCriticalPair(+ const normalizedBackupPair = normalizeAgeWarningCriticalPair(snapshot.backupDefaults.warningDays,snapshot.backupDefaults.criticalDays,);diff --git a/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsRecoveryDefaultsState.test.tsx b/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsRecoveryDefaultsState.test.tsxindex 1ef5bee7d7..635380e4ee 100644--- a/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsRecoveryDefaultsState.test.tsx+++ b/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsRecoveryDefaultsState.test.tsx@@ -93,6 +93,42 @@ describe('useThresholdsRecoveryDefaultsState', () => {});});+ // The Off toggle stages -1 for a critical age. The sanitizers used to raise+ // a 0 critical to the warning age, so turning critical off made backups and+ // snapshots go critical at the warning age instead.+ it('keeps an Off critical age Off instead of raising it to the warning age', () => {+ let captured: ReturnType<typeof useThresholdsRecoveryDefaultsState> | undefined;++ const Harness = () => {+ captured = useThresholdsRecoveryDefaultsState(buildProps());+ return null;+ };++ render(() => <Harness />);++ expect(+ captured!.sanitizeBackupConfig({+ alertOrphaned: true,+ criticalDays: -1,+ enabled: true,+ freshHours: 24,+ ignoreVMIDs: [],+ staleHours: 72,+ warningDays: 7,+ }),+ ).toMatchObject({ criticalDays: 0, warningDays: 7 });++ expect(+ captured!.sanitizeSnapshotConfig({+ criticalDays: -1,+ criticalSizeGiB: 0,+ enabled: true,+ warningDays: 30,+ warningSizeGiB: 50,+ }),+ ).toMatchObject({ criticalDays: 0, warningDays: 30, criticalSizeGiB: 50 });+ });+it('tracks factory drift for backup and snapshot defaults', () => {let captured: ReturnType<typeof useThresholdsRecoveryDefaultsState> | undefined;diff --git a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsRecoveryDefaultsState.ts b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsRecoveryDefaultsState.tsindex 407ee1b8ec..58994eff53 100644--- a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsRecoveryDefaultsState.ts+++ b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsRecoveryDefaultsState.ts@@ -27,12 +27,11 @@ export function useThresholdsRecoveryDefaultsState(props: ThresholdsTableProps)let warning = Math.max(0, Math.round(config.warningDays ?? 0));let critical = Math.max(0, Math.round(config.criticalDays ?? 0));+ // A critical age of 0 is Off, as the backend reads it; raising it to the+ // warning age made the Off toggle turn critical on at the warning age.if (critical > 0 && warning > critical) {warning = critical;}- if (critical === 0 && warning > 0) {- critical = warning;- }const rawWarningSize = Number.isFinite(config.warningSizeGiB)? Number(config.warningSizeGiB)@@ -85,12 +84,11 @@ export function useThresholdsRecoveryDefaultsState(props: ThresholdsTableProps)),);+ // A critical age of 0 is Off, as the backend reads it; raising it to the+ // warning age made the Off toggle turn critical on at the warning age.if (critical > 0 && warning > critical) {warning = critical;}- if (critical === 0 && warning > 0) {- critical = warning;- }if (stale < fresh) {stale = fresh;}diff --git a/frontend-modern/src/utils/__tests__/alertThresholdsSectionPresentation.test.ts b/frontend-modern/src/utils/__tests__/alertThresholdsSectionPresentation.test.tsindex e5145b690d..6f8398189c 100644--- a/frontend-modern/src/utils/__tests__/alertThresholdsSectionPresentation.test.ts+++ b/frontend-modern/src/utils/__tests__/alertThresholdsSectionPresentation.test.ts@@ -77,16 +77,27 @@ describe('alertThresholdsSectionPresentation', () => {memoryCriticalPct: 95,}),).toEqual(['Restart loop 3 in 5 min', 'Memory limit 90% warn, 95% critical']);- // Config normalization replaces <= 0 with the fallbacks, so these rules- // never read as Off.+ // 0 (or the editor's -1) is Off for these rules, as the engine reads+ // them; the header must not state a limit that never alerts.expect(getDockerContainerRuleSummaryItems({restartCount: -1,- restartWindow: 0,+ restartWindow: 300,memoryWarnPct: 0,memoryCriticalPct: -1,}),- ).toEqual(['Restart loop 3 in 5 min', 'Memory limit 90% warn, 95% critical']);+ ).toEqual(['Restart loop off', 'Memory limit off']);+ expect(+ getDockerContainerRuleSummaryItems({+ restartCount: 3,+ restartWindow: 0,+ memoryWarnPct: 0,+ memoryCriticalPct: 95,+ }),+ ).toEqual(['Restart loop off', 'Memory limit 95% critical']);+ expect(getDockerContainerRuleSummaryItems({ memoryWarnPct: 90, memoryCriticalPct: 0 })[1]).toBe(+ 'Memory limit 90% warn',+ );expect(getDockerContainerRuleSummaryItems({ restartCount: 5, restartWindow: 90 })[0]).toBe('Restart loop 5 in 90s',);diff --git a/frontend-modern/src/utils/alertThresholdsSectionPresentation.ts b/frontend-modern/src/utils/alertThresholdsSectionPresentation.tsindex ef95d4131c..d10abd2057 100644--- a/frontend-modern/src/utils/alertThresholdsSectionPresentation.ts+++ b/frontend-modern/src/utils/alertThresholdsSectionPresentation.ts@@ -99,11 +99,12 @@ export function getAlertThresholdsDefaultsSummary(return `Defaults: ${shown.join(' · ')}${hidden > 0 ? ` · +${hidden} more` : ''}`;}-// Docker's restart-loop and memory-limit rules always run: config-// normalization (internal/alerts/config/normalize.go, NormalizeDockerDefaults)-// replaces any value <= 0 with these fallbacks. So the summary states the-// effective rule rather than treating zero as Off, and pairs the restart count-// with its window because neither means anything alone.+// Docker's restart-loop and memory-limit rules, as the alert engine reads+// them after config normalization (internal/alerts/config/normalize.go,+// NormalizeDockerDefaults): an unset value takes these factory values, and 0+// (or the editor's -1 Off value) is Off. The restart count pairs with its+// window because neither means anything alone, so either one Off turns the+// restart-loop rule off; memory-limit warn and critical are independent levels.const DOCKER_RULE_FALLBACKS = {restartCount: 3,restartWindow: 300,@@ -111,12 +112,22 @@ const DOCKER_RULE_FALLBACKS = {memoryCriticalPct: 95,} as const;-const effectiveDockerRule = (value: number | undefined, fallback: number) =>- typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : fallback;+// Returns the effective value, or null when the rule level is Off.+const effectiveDockerRule = (value: number | undefined, fallback: number): number | null => {+ if (typeof value !== 'number' || !Number.isFinite(value)) return fallback;+ return value > 0 ? value : null;+};const formatRestartWindow = (seconds: number) =>seconds % 60 === 0 ? `${seconds / 60} min` : `${seconds}s`;+const formatMemoryLimitRule = (warn: number | null, critical: number | null) => {+ if (warn === null && critical === null) return 'Memory limit off';+ if (warn === null) return `Memory limit ${critical}% critical`;+ if (critical === null) return `Memory limit ${warn}% warn`;+ return `Memory limit ${warn}% warn, ${critical}% critical`;+};+export function getDockerContainerRuleSummaryItems(defaults: {restartCount?: number;restartWindow?: number;@@ -131,7 +142,9 @@ export function getDockerContainerRuleSummaryItems(defaults: {DOCKER_RULE_FALLBACKS.memoryCriticalPct,);return [- `Restart loop ${restarts} in ${formatRestartWindow(window)}`,- `Memory limit ${warn}% warn, ${critical}% critical`,+ restarts === null || window === null+ ? 'Restart loop off'+ : `Restart loop ${restarts} in ${formatRestartWindow(window)}`,+ formatMemoryLimitRule(warn, critical),];}diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.goindex 18f1a96a94..42e4ef1fd6 100644--- a/internal/alerts/alerts_test.go+++ b/internal/alerts/alerts_test.go@@ -22747,3 +22747,214 @@ func TestProxmoxDiskTemperatureAlertsReevaluatePerDiskType(t *testing.T) {t.Fatalf("a SATA alert without a disk type was resolved by the 70C agent default although its trigger is 55C")}}++func exitedDockerHost(hostID, containerID, name string) models.DockerHost {+ return models.DockerHost{+ ID: hostID,+ DisplayName: "Docker Host",+ Hostname: "docker.local",+ Containers: []models.DockerContainer{{+ ID: containerID,+ Name: name,+ State: "exited",+ Status: "Exited (1) seconds ago",+ }},+ }+}++// An override saved for a container's CPU threshold alone carries no+// DisableConnectivity, and used to turn that container's state alerts back+// on although the operator had turned them off for every container.+func TestDockerContainerThresholdOverrideKeepsDisabledStateDefault(t *testing.T) {+ m := newTestManager(t)+ cfg := m.GetConfig()+ cfg.DockerDefaults.StateDisableConnectivity = true+ cfg.Overrides = map[string]ThresholdConfig{+ dockerContainerOverrideKey("host-off", "web"): {CPU: &HysteresisThreshold{Trigger: 95, Clear: 90}},+ }+ m.UpdateConfig(cfg)++ host := exitedDockerHost("host-off", "container-off", "web")+ m.CheckDockerHost(host)+ m.CheckDockerHost(host)++ resourceID := DockerContainerResourceID(host.ID, "container-off", "")+ if testHasActiveAlert(t, m, fmt.Sprintf("docker-container-state-%s", resourceID)) {+ t.Fatal("a CPU-only override re-enabled container state alerts that the Docker default turns off")+ }+}++// The row's own offline control stores a severity, and that alone turns+// state alerts back on over a disabled default.+func TestDockerContainerSeverityOverrideReenablesStateAlerts(t *testing.T) {+ m := newTestManager(t)+ cfg := m.GetConfig()+ cfg.DockerDefaults.StateDisableConnectivity = true+ cfg.Overrides = map[string]ThresholdConfig{+ dockerContainerOverrideKey("host-on", "db"): {PoweredOffSeverity: AlertLevelCritical},+ }+ m.UpdateConfig(cfg)++ host := exitedDockerHost("host-on", "container-on", "db")+ m.CheckDockerHost(host)+ m.CheckDockerHost(host)++ resourceID := DockerContainerResourceID(host.ID, "container-on", "")+ alert, exists := testLookupActiveAlert(t, m, fmt.Sprintf("docker-container-state-%s", resourceID))+ if !exists {+ t.Fatal("an override with its own severity should re-enable container state alerts")+ }+ if alert.Level != AlertLevelCritical {+ t.Fatalf("alert level = %s, want critical from the override", alert.Level)+ }+}++func restartingDockerHost(hostID, containerID string, restarts int) models.DockerHost {+ return models.DockerHost{+ ID: hostID,+ DisplayName: "Docker Host",+ Hostname: "docker.local",+ Containers: []models.DockerContainer{{+ ID: containerID,+ Name: "flappy",+ State: "running",+ Status: "Up 1 second",+ RestartCount: restarts,+ }},+ }+}++func TestDockerRestartLoopOffAtZero(t *testing.T) {+ for _, tc := range []struct {+ name string+ count, window int+ wantAlert bool+ }{+ {name: "on", count: 3, window: 300, wantAlert: true},+ {name: "count off", count: 0, window: 300},+ {name: "window off", count: 3, window: 0},+ } {+ t.Run(tc.name, func(t *testing.T) {+ m := newTestManager(t)+ cfg := m.GetConfig()+ cfg.DockerDefaults.RestartCount = tc.count+ cfg.DockerDefaults.RestartWindow = tc.window+ m.UpdateConfig(cfg)++ hostID, containerID := "host-restart-off", "container-restart-off"+ m.CheckDockerHost(restartingDockerHost(hostID, containerID, 0))+ m.CheckDockerHost(restartingDockerHost(hostID, containerID, 5))++ resourceID := DockerContainerResourceID(hostID, containerID, "")+ got := testHasActiveAlert(t, m, fmt.Sprintf("docker-container-restart-loop-%s", resourceID))+ if got != tc.wantAlert {+ t.Fatalf("restart loop alert = %v, want %v (count %d, window %d)", got, tc.wantAlert, tc.count, tc.window)+ }+ })+ }+}++func memoryLimitDockerHost(hostID, containerID string, usedPct int64) models.DockerHost {+ return models.DockerHost{+ ID: hostID,+ DisplayName: "Docker Host",+ Hostname: "docker.local",+ Containers: []models.DockerContainer{{+ ID: containerID,+ Name: "memory-hog",+ State: "running",+ Status: "Up 10 minutes",+ MemoryUsage: usedPct * 1024 * 1024,+ MemoryLimit: 100 * 1024 * 1024,+ }},+ }+}++func TestDockerMemoryLimitLevelsOffAtZero(t *testing.T) {+ for _, tc := range []struct {+ name string+ warn, crit int+ usedPct int64+ wantLevel AlertLevel // empty means no alert+ }{+ {name: "warning off, below critical", warn: 0, crit: 95, usedPct: 92},+ {name: "warning off, above critical", warn: 0, crit: 95, usedPct: 97, wantLevel: AlertLevelCritical},+ {name: "critical off, above both", warn: 90, crit: 0, usedPct: 97, wantLevel: AlertLevelWarning},+ {name: "both off", warn: 0, crit: 0, usedPct: 99},+ } {+ t.Run(tc.name, func(t *testing.T) {+ m := newTestManager(t)+ cfg := m.GetConfig()+ cfg.DockerDefaults.MemoryWarnPct = tc.warn+ cfg.DockerDefaults.MemoryCriticalPct = tc.crit+ m.UpdateConfig(cfg)++ hostID, containerID := "host-memlimit-off", "container-memlimit-off"+ m.CheckDockerHost(memoryLimitDockerHost(hostID, containerID, tc.usedPct))++ resourceID := DockerContainerResourceID(hostID, containerID, "")+ alert, exists := testLookupActiveAlert(t, m, fmt.Sprintf("docker-container-memory-limit-%s", resourceID))+ if tc.wantLevel == "" {+ if exists {+ t.Fatalf("unexpected %s memory limit alert at %d%% (warn %d, crit %d)", alert.Level, tc.usedPct, tc.warn, tc.crit)+ }+ return+ }+ if !exists {+ t.Fatalf("expected %s memory limit alert at %d%% (warn %d, crit %d)", tc.wantLevel, tc.usedPct, tc.warn, tc.crit)+ }+ if alert.Level != tc.wantLevel {+ t.Fatalf("alert level = %s, want %s", alert.Level, tc.wantLevel)+ }+ })+ }+}++// The settings Off toggle sends -1. The normalizer used to turn it, and 0,+// back into the factory value, so Off never stuck for these thresholds.+func TestConfigUpdateKeepsDockerAndPMGThresholdsOff(t *testing.T) {+ m := newTestManager(t)+ update := []byte(`{+ "dockerDefaults": {"cpu": {"trigger": 80, "clear": 75}, "restartCount": -1, "restartWindow": 300, "memoryWarnPct": 0, "memoryCriticalPct": 95},+ "pmgDefaults": {"queueTotalWarning": -1, "queueTotalCritical": 0, "holdQueueWarn": 150}+ }`)+ if _, err := m.ApplyConfigUpdate(update); err != nil {+ t.Fatalf("ApplyConfigUpdate: %v", err)+ }+ cfg := m.GetConfig()++ docker := cfg.DockerDefaults+ if docker.RestartCount != 0 || docker.MemoryWarnPct != 0 {+ t.Fatalf("docker Off thresholds = restartCount %d, memoryWarnPct %d; want 0, 0", docker.RestartCount, docker.MemoryWarnPct)+ }+ if docker.RestartWindow != 300 || docker.MemoryCriticalPct != 95 {+ t.Fatalf("docker set thresholds = restartWindow %d, memoryCriticalPct %d; want 300, 95", docker.RestartWindow, docker.MemoryCriticalPct)+ }++ pmg := cfg.PMGDefaults+ if pmg.QueueTotalWarning != 0 || pmg.QueueTotalCritical != 0 {+ t.Fatalf("PMG Off thresholds = queueTotalWarning %d, queueTotalCritical %d; want 0, 0", pmg.QueueTotalWarning, pmg.QueueTotalCritical)+ }+ if pmg.HoldQueueWarn != 150 {+ t.Fatalf("PMG holdQueueWarn = %d, want the sent 150", pmg.HoldQueueWarn)+ }+ // A key the section omits is unset, not Off: it takes the factory value.+ if pmg.HoldQueueCritical != 300 || pmg.OldestMessageWarnMins != 30 {+ t.Fatalf("PMG omitted thresholds = holdQueueCritical %d, oldestMessageWarnMins %d; want factory 300, 30", pmg.HoldQueueCritical, pmg.OldestMessageWarnMins)+ }+}++// One half of a quarantine growth level set to Off used to make the spec+// invalid, which skipped the whole check, absolute thresholds included.+func TestPMGQuarantineGrowthHalfOffKeepsAbsoluteCheck(t *testing.T) {+ m := newTestManager(t)+ defaults := m.GetConfig().PMGDefaults+ defaults.QuarantineGrowthWarnMin = 0 // Off; QuarantineGrowthWarnPct stays 25+ pmg := models.PMGInstance{ID: "pmg-half-off", Name: "mail"}++ m.checkQuarantineMetric(pmg, "spam", defaults.QuarantineSpamWarn+500, nil, defaults)++ if !testHasActiveAlert(t, m, fmt.Sprintf("%s-quarantine-spam", pmg.ID)) {+ t.Fatal("spam quarantine above its absolute warning raised no alert while a growth level was half off")+ }+}diff --git a/internal/alerts/config/alerts_config_normalize_branchcov0716_test.go b/internal/alerts/config/alerts_config_normalize_branchcov0716_test.goindex 268fd269e5..aac065c710 100644--- a/internal/alerts/config/alerts_config_normalize_branchcov0716_test.go+++ b/internal/alerts/config/alerts_config_normalize_branchcov0716_test.go@@ -248,17 +248,10 @@ func TestBranchCovNormalizeDockerDefaults(t *testing.T) {if !htEq(d.Disk, alertconfig.HysteresisThreshold{Trigger: 0, Clear: 0}) {t.Fatalf("Disk = %+v, want {0 0} (Trigger==0 disabled path, NOT seeded)", d.Disk)}- if d.RestartCount != 3 {- t.Fatalf("RestartCount = %d, want 3", d.RestartCount)- }- if d.RestartWindow != 300 {- t.Fatalf("RestartWindow = %d, want 300", d.RestartWindow)- }- if d.MemoryWarnPct != 90 {- t.Fatalf("MemoryWarnPct = %d, want 90", d.MemoryWarnPct)- }- if d.MemoryCriticalPct != 95 {- t.Fatalf("MemoryCriticalPct = %d, want 95", d.MemoryCriticalPct)+ // 0 is Off for the restart and memory-limit thresholds, as for the+ // CPU/Memory/Disk triggers above; only unset values take defaults.+ if d.RestartCount != 0 || d.RestartWindow != 0 || d.MemoryWarnPct != 0 || d.MemoryCriticalPct != 0 {+ t.Fatalf("restart/memory-limit = %d/%d/%d/%d, want Off (0) kept", d.RestartCount, d.RestartWindow, d.MemoryWarnPct, d.MemoryCriticalPct)}if d.ServiceWarnGapPct != 10 {t.Fatalf("ServiceWarnGapPct = %d, want 10", d.ServiceWarnGapPct)@@ -274,6 +267,33 @@ func TestBranchCovNormalizeDockerDefaults(t *testing.T) {}})+ t.Run("unset restart and memory-limit thresholds take canonical defaults", func(t *testing.T) {+ cfg := &alertconfig.AlertConfig{+ DockerDefaults: alertconfig.DockerThresholdConfig{+ RestartCount: alertconfig.ThresholdCountUnset,+ RestartWindow: alertconfig.ThresholdCountUnset,+ MemoryWarnPct: alertconfig.ThresholdCountUnset,+ MemoryCriticalPct: alertconfig.ThresholdCountUnset,+ },+ }+ alertconfig.NormalizeDockerDefaults(cfg)+ d := cfg.DockerDefaults+ if d.RestartCount != 3 || d.RestartWindow != 300 || d.MemoryWarnPct != 90 || d.MemoryCriticalPct != 95 {+ t.Fatalf("restart/memory-limit = %d/%d/%d/%d, want 3/300/90/95", d.RestartCount, d.RestartWindow, d.MemoryWarnPct, d.MemoryCriticalPct)+ }+ })++ t.Run("negative restart and memory-limit thresholds are stored as Off", func(t *testing.T) {+ cfg := &alertconfig.AlertConfig{+ DockerDefaults: alertconfig.DockerThresholdConfig{RestartCount: -1, RestartWindow: 120, MemoryWarnPct: -1, MemoryCriticalPct: 97},+ }+ alertconfig.NormalizeDockerDefaults(cfg)+ d := cfg.DockerDefaults+ if d.RestartCount != 0 || d.RestartWindow != 120 || d.MemoryWarnPct != 0 || d.MemoryCriticalPct != 97 {+ t.Fatalf("restart/memory-limit = %d/%d/%d/%d, want 0/120/0/97", d.RestartCount, d.RestartWindow, d.MemoryWarnPct, d.MemoryCriticalPct)+ }+ })+t.Run("negative trigger CPU falls back to defaultTrigger and derives clear", func(t *testing.T) {cfg := &alertconfig.AlertConfig{DockerDefaults: alertconfig.DockerThresholdConfig{diff --git a/internal/alerts/config/alerts_config_normalize_defaults_branchcov0716_test.go b/internal/alerts/config/alerts_config_normalize_defaults_branchcov0716_test.goindex d06553cd6c..91dcc1792c 100644--- a/internal/alerts/config/alerts_config_normalize_defaults_branchcov0716_test.go+++ b/internal/alerts/config/alerts_config_normalize_defaults_branchcov0716_test.go@@ -1,6 +1,7 @@package config_testimport (+ "encoding/json""reflect""testing"@@ -31,7 +32,7 @@ func ptrHtEq(got *alertconfig.HysteresisThreshold, want alertconfig.HysteresisTh}// expectedPMGDefaults returns the canonical PMGThresholdConfig the normalizer-// must seed whenever a field is non-positive.+// must seed whenever a field is unset.func expectedPMGDefaults() alertconfig.PMGThresholdConfig {return alertconfig.PMGThresholdConfig{QueueTotalWarning: 500,@@ -53,18 +54,37 @@ func expectedPMGDefaults() alertconfig.PMGThresholdConfig {}}-// TestBranchCovNormalizePMGDefaults covers the <=0 default-seeding branch and-// the >0 preserve branch for every field of PMGThresholdConfig.+// unsetPMGDefaults is what decoding leaves for a pmgDefaults section the JSON+// omits.+func unsetPMGDefaults() alertconfig.PMGThresholdConfig {+ var cfg alertconfig.AlertConfig+ if err := json.Unmarshal([]byte(`{}`), &cfg); err != nil {+ panic(err)+ }+ return cfg.PMGDefaults+}++// TestBranchCovNormalizePMGDefaults covers the unset default-seeding branch,+// the Off (0, or a negative toggle value) branch and the >0 preserve branch+// for every field of PMGThresholdConfig.func TestBranchCovNormalizePMGDefaults(t *testing.T) {- t.Run("zero-valued config seeds every field with its canonical default", func(t *testing.T) {- cfg := &alertconfig.AlertConfig{}+ t.Run("unset config seeds every field with its canonical default", func(t *testing.T) {+ cfg := &alertconfig.AlertConfig{PMGDefaults: unsetPMGDefaults()}alertconfig.NormalizePMGDefaults(cfg)if !reflect.DeepEqual(cfg.PMGDefaults, expectedPMGDefaults()) {t.Fatalf("PMGDefaults = %+v, want defaults %+v", cfg.PMGDefaults, expectedPMGDefaults())}})- t.Run("negative values are replaced with defaults (<=0 branch)", func(t *testing.T) {+ t.Run("zero-valued config keeps every field Off", func(t *testing.T) {+ cfg := &alertconfig.AlertConfig{}+ alertconfig.NormalizePMGDefaults(cfg)+ if !reflect.DeepEqual(cfg.PMGDefaults, alertconfig.PMGThresholdConfig{}) {+ t.Fatalf("PMGDefaults = %+v, want every field Off (0)", cfg.PMGDefaults)+ }+ })++ t.Run("negative values are stored as Off", func(t *testing.T) {cfg := &alertconfig.AlertConfig{PMGDefaults: alertconfig.PMGThresholdConfig{QueueTotalWarning: -1,@@ -86,8 +106,8 @@ func TestBranchCovNormalizePMGDefaults(t *testing.T) {},}alertconfig.NormalizePMGDefaults(cfg)- if !reflect.DeepEqual(cfg.PMGDefaults, expectedPMGDefaults()) {- t.Fatalf("PMGDefaults = %+v, want defaults (negatives replaced)", cfg.PMGDefaults)+ if !reflect.DeepEqual(cfg.PMGDefaults, alertconfig.PMGThresholdConfig{}) {+ t.Fatalf("PMGDefaults = %+v, want every field Off (0)", cfg.PMGDefaults)}})@@ -117,18 +137,18 @@ func TestBranchCovNormalizePMGDefaults(t *testing.T) {}})- t.Run("mixed zero/negative/positive fields only seed the non-positive ones", func(t *testing.T) {- cfg := &alertconfig.AlertConfig{- PMGDefaults: alertconfig.PMGThresholdConfig{- QueueTotalWarning: 0, // -> 500- QueueTotalCritical: 7777, // preserved- OldestMessageWarnMins: -5, // -> 30- HoldQueueWarn: 42, // preserved- },- }+ t.Run("mixed unset/zero/negative/positive fields only seed the unset ones", func(t *testing.T) {+ pmg := unsetPMGDefaults()+ pmg.QueueTotalWarning = 0 // Off, kept+ pmg.QueueTotalCritical = 7777 // preserved+ pmg.OldestMessageWarnMins = -1 // Off toggle -> 0+ pmg.HoldQueueWarn = 42 // preserved+ cfg := &alertconfig.AlertConfig{PMGDefaults: pmg}alertconfig.NormalizePMGDefaults(cfg)want := expectedPMGDefaults()+ want.QueueTotalWarning = 0want.QueueTotalCritical = 7777+ want.OldestMessageWarnMins = 0want.HoldQueueWarn = 42if !reflect.DeepEqual(cfg.PMGDefaults, want) {t.Fatalf("PMGDefaults = %+v, want %+v", cfg.PMGDefaults, want)diff --git a/internal/alerts/config/normalize.go b/internal/alerts/config/normalize.goindex 187abae298..c793a93649 100644--- a/internal/alerts/config/normalize.go+++ b/internal/alerts/config/normalize.go@@ -67,23 +67,30 @@ func NormalizeDockerThreshold(th HysteresisThreshold, defaultTrigger float64, mereturn normalized}+// normalizeThresholdCount resolves a Docker or PMG count threshold, where 0 is+// Off. A value the decoded JSON did not carry takes the factory value. Any+// other negative value is Off: the settings Off toggle sends -1, and this+// normalizer used to turn it back into the factory value.+func normalizeThresholdCount(value, factory int) int {+ switch {+ case value == ThresholdCountUnset:+ return factory+ case value < 0:+ return 0+ default:+ return value+ }+}+func NormalizeDockerDefaults(config *AlertConfig) {config.DockerDefaults.CPU = NormalizeDockerThreshold(config.DockerDefaults.CPU, 80, "docker.cpu")config.DockerDefaults.Memory = NormalizeDockerThreshold(config.DockerDefaults.Memory, 85, "docker.memory")config.DockerDefaults.Disk = NormalizeDockerThreshold(config.DockerDefaults.Disk, 85, "docker.disk")- if config.DockerDefaults.RestartCount <= 0 {- config.DockerDefaults.RestartCount = 3- }- if config.DockerDefaults.RestartWindow <= 0 {- config.DockerDefaults.RestartWindow = 300- }- if config.DockerDefaults.MemoryWarnPct <= 0 {- config.DockerDefaults.MemoryWarnPct = 90- }- if config.DockerDefaults.MemoryCriticalPct <= 0 {- config.DockerDefaults.MemoryCriticalPct = 95- }+ config.DockerDefaults.RestartCount = normalizeThresholdCount(config.DockerDefaults.RestartCount, 3)+ config.DockerDefaults.RestartWindow = normalizeThresholdCount(config.DockerDefaults.RestartWindow, 300)+ config.DockerDefaults.MemoryWarnPct = normalizeThresholdCount(config.DockerDefaults.MemoryWarnPct, 90)+ config.DockerDefaults.MemoryCriticalPct = normalizeThresholdCount(config.DockerDefaults.MemoryCriticalPct, 95)if config.DockerDefaults.ServiceWarnGapPct <= 0 {config.DockerDefaults.ServiceWarnGapPct = 10}@@ -107,55 +114,26 @@ func NormalizeDockerDefaults(config *AlertConfig) {}}+// NormalizePMGDefaults fills unset PMG thresholds with their factory values.+// Each threshold is Off at 0, as the PMG checks read it.func NormalizePMGDefaults(config *AlertConfig) {- if config.PMGDefaults.QueueTotalWarning <= 0 {- config.PMGDefaults.QueueTotalWarning = 500- }- if config.PMGDefaults.QueueTotalCritical <= 0 {- config.PMGDefaults.QueueTotalCritical = 1000- }- if config.PMGDefaults.OldestMessageWarnMins <= 0 {- config.PMGDefaults.OldestMessageWarnMins = 30- }- if config.PMGDefaults.OldestMessageCritMins <= 0 {- config.PMGDefaults.OldestMessageCritMins = 60- }- if config.PMGDefaults.DeferredQueueWarn <= 0 {- config.PMGDefaults.DeferredQueueWarn = 200- }- if config.PMGDefaults.DeferredQueueCritical <= 0 {- config.PMGDefaults.DeferredQueueCritical = 500- }- if config.PMGDefaults.HoldQueueWarn <= 0 {- config.PMGDefaults.HoldQueueWarn = 100- }- if config.PMGDefaults.HoldQueueCritical <= 0 {- config.PMGDefaults.HoldQueueCritical = 300- }- if config.PMGDefaults.QuarantineSpamWarn <= 0 {- config.PMGDefaults.QuarantineSpamWarn = 2000- }- if config.PMGDefaults.QuarantineSpamCritical <= 0 {- config.PMGDefaults.QuarantineSpamCritical = 5000- }- if config.PMGDefaults.QuarantineVirusWarn <= 0 {- config.PMGDefaults.QuarantineVirusWarn = 2000- }- if config.PMGDefaults.QuarantineVirusCritical <= 0 {- config.PMGDefaults.QuarantineVirusCritical = 5000- }- if config.PMGDefaults.QuarantineGrowthWarnPct <= 0 {- config.PMGDefaults.QuarantineGrowthWarnPct = 25- }- if config.PMGDefaults.QuarantineGrowthWarnMin <= 0 {- config.PMGDefaults.QuarantineGrowthWarnMin = 250- }- if config.PMGDefaults.QuarantineGrowthCritPct <= 0 {- config.PMGDefaults.QuarantineGrowthCritPct = 50- }- if config.PMGDefaults.QuarantineGrowthCritMin <= 0 {- config.PMGDefaults.QuarantineGrowthCritMin = 500- }+ d := &config.PMGDefaults+ d.QueueTotalWarning = normalizeThresholdCount(d.QueueTotalWarning, 500)+ d.QueueTotalCritical = normalizeThresholdCount(d.QueueTotalCritical, 1000)+ d.OldestMessageWarnMins = normalizeThresholdCount(d.OldestMessageWarnMins, 30)+ d.OldestMessageCritMins = normalizeThresholdCount(d.OldestMessageCritMins, 60)+ d.DeferredQueueWarn = normalizeThresholdCount(d.DeferredQueueWarn, 200)+ d.DeferredQueueCritical = normalizeThresholdCount(d.DeferredQueueCritical, 500)+ d.HoldQueueWarn = normalizeThresholdCount(d.HoldQueueWarn, 100)+ d.HoldQueueCritical = normalizeThresholdCount(d.HoldQueueCritical, 300)+ d.QuarantineSpamWarn = normalizeThresholdCount(d.QuarantineSpamWarn, 2000)+ d.QuarantineSpamCritical = normalizeThresholdCount(d.QuarantineSpamCritical, 5000)+ d.QuarantineVirusWarn = normalizeThresholdCount(d.QuarantineVirusWarn, 2000)+ d.QuarantineVirusCritical = normalizeThresholdCount(d.QuarantineVirusCritical, 5000)+ d.QuarantineGrowthWarnPct = normalizeThresholdCount(d.QuarantineGrowthWarnPct, 25)+ d.QuarantineGrowthWarnMin = normalizeThresholdCount(d.QuarantineGrowthWarnMin, 250)+ d.QuarantineGrowthCritPct = normalizeThresholdCount(d.QuarantineGrowthCritPct, 50)+ d.QuarantineGrowthCritMin = normalizeThresholdCount(d.QuarantineGrowthCritMin, 500)}// NormalizePBSDefaults ensures PBS server threshold defaults exist.diff --git a/internal/alerts/config/types.go b/internal/alerts/config/types.goindex ded5a57db8..4826e71e21 100644--- a/internal/alerts/config/types.go+++ b/internal/alerts/config/types.go@@ -2,6 +2,7 @@ package configimport ("encoding/json"+ "math""strings""time")@@ -292,6 +293,67 @@ type PMGThresholdConfig struct {QuarantineGrowthCritMin int `json:"quarantineGrowthCritMin"` // Minimum message growth for critical (default: 500)}+// ThresholdCountUnset marks a Docker or PMG count threshold that the decoded+// JSON did not carry. These thresholds are plain ints where 0 is Off, so+// without a marker a value an older alerts.json predates would read as Off.+// NormalizeDockerDefaults and NormalizePMGDefaults replace it with the factory+// value before the config is used or saved.+const ThresholdCountUnset = math.MinInt32++func unsetDockerThresholdCounts() DockerThresholdConfig {+ return DockerThresholdConfig{+ RestartCount: ThresholdCountUnset,+ RestartWindow: ThresholdCountUnset,+ MemoryWarnPct: ThresholdCountUnset,+ MemoryCriticalPct: ThresholdCountUnset,+ }+}++// UnmarshalJSON leaves count thresholds the JSON omits unset, so they take+// their factory value instead of Off.+func (c *DockerThresholdConfig) UnmarshalJSON(data []byte) error {+ type plain DockerThresholdConfig+ decoded := plain(unsetDockerThresholdCounts())+ if err := json.Unmarshal(data, &decoded); err != nil {+ return err+ }+ *c = DockerThresholdConfig(decoded)+ return nil+}++func unsetPMGThresholdCounts() PMGThresholdConfig {+ return PMGThresholdConfig{+ QueueTotalWarning: ThresholdCountUnset,+ QueueTotalCritical: ThresholdCountUnset,+ OldestMessageWarnMins: ThresholdCountUnset,+ OldestMessageCritMins: ThresholdCountUnset,+ DeferredQueueWarn: ThresholdCountUnset,+ DeferredQueueCritical: ThresholdCountUnset,+ HoldQueueWarn: ThresholdCountUnset,+ HoldQueueCritical: ThresholdCountUnset,+ QuarantineSpamWarn: ThresholdCountUnset,+ QuarantineSpamCritical: ThresholdCountUnset,+ QuarantineVirusWarn: ThresholdCountUnset,+ QuarantineVirusCritical: ThresholdCountUnset,+ QuarantineGrowthWarnPct: ThresholdCountUnset,+ QuarantineGrowthWarnMin: ThresholdCountUnset,+ QuarantineGrowthCritPct: ThresholdCountUnset,+ QuarantineGrowthCritMin: ThresholdCountUnset,+ }+}++// UnmarshalJSON leaves thresholds the JSON omits unset, so they take their+// factory value instead of Off.+func (c *PMGThresholdConfig) UnmarshalJSON(data []byte) error {+ type plain PMGThresholdConfig+ decoded := plain(unsetPMGThresholdCounts())+ if err := json.Unmarshal(data, &decoded); err != nil {+ return err+ }+ *c = PMGThresholdConfig(decoded)+ return nil+}+// SnapshotAlertConfig represents snapshot age alert configurationtype SnapshotAlertConfig struct {Enabled bool `json:"enabled"`@@ -400,7 +462,13 @@ type AlertConfig struct {// UnmarshalJSON accepts canonical v6 alert config keys.func (c *AlertConfig) UnmarshalJSON(data []byte) error {type alias AlertConfig- var decoded alias+ // A config written before the Docker or PMG sections existed carries+ // neither key, so their count thresholds start unset rather than at the+ // zero that means Off.+ decoded := alias{+ DockerDefaults: unsetDockerThresholdCounts(),+ PMGDefaults: unsetPMGThresholdCounts(),+ }if err := json.Unmarshal(data, &decoded); err != nil {return err}diff --git a/internal/alerts/config_facade.go b/internal/alerts/config_facade.goindex f7858af005..2bb7bc2bf4 100644--- a/internal/alerts/config_facade.go+++ b/internal/alerts/config_facade.go@@ -118,6 +118,14 @@ func ensureValidHysteresis(threshold *HysteresisThreshold, metricName string) {alertconfig.EnsureValidHysteresis(threshold, metricName)}+// NormalizeDockerDefaults fills unset Docker container thresholds with their+// factory values and stores an Off count threshold as 0.+func NormalizeDockerDefaults(config *AlertConfig) { alertconfig.NormalizeDockerDefaults(config) }++// NormalizePMGDefaults fills unset PMG thresholds with their factory values+// and stores an Off threshold as 0.+func NormalizePMGDefaults(config *AlertConfig) { alertconfig.NormalizePMGDefaults(config) }+func normalizeSnapshotDefaults(config *AlertConfig) { alertconfig.NormalizeSnapshotDefaults(config) }func normalizeBackupDefaults(config *AlertConfig) { alertconfig.NormalizeBackupDefaults(config) }diff --git a/internal/alerts/docker.go b/internal/alerts/docker.goindex 74071b851d..df2d1f0512 100644--- a/internal/alerts/docker.go+++ b/internal/alerts/docker.go@@ -824,10 +824,16 @@ func (m *Manager) checkDockerContainerState(host models.DockerHost, container modisableConnectivity := defaultDisableseverity := defaultSeverityif hasOverride {- if defaultDisable && !override.DisableConnectivity {- disableConnectivity = false- } else if override.DisableConnectivity {+ // Same rule as applyThresholdOverride: an override turns state+ // alerts back on over a disabled default only when it carries the+ // row's own severity. DisableConnectivity is a plain bool, so an+ // override saved for a CPU or memory threshold alone reads false+ // here, and used to re-enable state alerts the operator had turned+ // off for every container.+ if override.DisableConnectivity {disableConnectivity = true+ } else if override.PoweredOffSeverity != "" {+ disableConnectivity = false}if override.PoweredOffSeverity != "" {@@ -1001,14 +1007,15 @@ func (m *Manager) checkDockerContainerRestartLoop(host models.DockerHost, contaim.mu.Lock()- // Get config values with defaults+ // NormalizeDockerDefaults owns the factory values; 0 here is the+ // operator's Off, so either one set to 0 turns restart-loop alerts off.restartThreshold := m.config.DockerDefaults.RestartCount- if restartThreshold == 0 {- restartThreshold = 3 // Default: 3 restarts- }timeWindow := m.config.DockerDefaults.RestartWindow- if timeWindow == 0 {- timeWindow = 300 // Default: 5 minutes (300 seconds)+ if restartThreshold <= 0 || timeWindow <= 0 {+ delete(m.dockerRestartTracking, resourceID)+ m.mu.Unlock()+ m.clearAlert(buildCanonicalStateID(resourceID, resourceID+"-restart-loop"))+ return}record, exists := m.dockerRestartTracking[resourceID]@@ -1169,18 +1176,21 @@ func (m *Manager) checkDockerContainerMemoryLimit(host models.DockerHost, contaiwarnThreshold := float64(m.config.DockerDefaults.MemoryWarnPct)criticalThreshold := float64(m.config.DockerDefaults.MemoryCriticalPct)m.mu.RUnlock()- if warnThreshold == 0 {- warnThreshold = 90.0 // Default: 90%- }- if criticalThreshold == 0 {- criticalThreshold = 95.0 // Default: 95%+ // NormalizeDockerDefaults owns the factory values; 0 here is the+ // operator's Off for that level.+ if warnThreshold <= 0 && criticalThreshold <= 0 {+ m.clearAlert(buildCanonicalStateID(resourceID, resourceID+"-memory-limit"))+ return}// Calculate percentage of limit usedlimitPercent := (float64(container.MemoryUsage) / float64(container.MemoryLimit)) * 100- clearThreshold := warnThreshold - 5- recovery := clearThreshold+ activation := warnThreshold+ if activation <= 0 {+ activation = criticalThreshold+ }+ recovery := activation - 5spec, err := buildCanonicalSeverityThresholdSpecWithRecovery(resourceID+"-memory-limit", resourceID, containerName, unifiedresources.ResourceTypeAppContainer, "memory-limit-percent", warnThreshold, criticalThreshold, &recovery, false)if err != nil {log.Warn().diff --git a/internal/alerts/pmg.go b/internal/alerts/pmg.goindex 5895dfe1f0..49bbadb7cb 100644--- a/internal/alerts/pmg.go+++ b/internal/alerts/pmg.go@@ -714,8 +714,20 @@ func (m *Manager) checkQuarantineMetric(pmg models.PMGInstance, metricType strin}}- if absoluteWarn <= 0 && absoluteCrit <= 0 &&- defaults.QuarantineGrowthWarnMin <= 0 && defaults.QuarantineGrowthCritMin <= 0 {+ // A growth level needs both its percentage and its minimum message+ // growth; either one set to Off (0) turns that level off. Passing one+ // without the other made the spec invalid, which skipped the whole+ // quarantine check, absolute thresholds included.+ growthWarnPct, growthWarnMin := defaults.QuarantineGrowthWarnPct, defaults.QuarantineGrowthWarnMin+ if growthWarnPct <= 0 || growthWarnMin <= 0 {+ growthWarnPct, growthWarnMin = 0, 0+ }+ growthCritPct, growthCritMin := defaults.QuarantineGrowthCritPct, defaults.QuarantineGrowthCritMin+ if growthCritPct <= 0 || growthCritMin <= 0 {+ growthCritPct, growthCritMin = 0, 0+ }++ if absoluteWarn <= 0 && absoluteCrit <= 0 && growthWarnMin <= 0 && growthCritMin <= 0 {m.clearAlert(buildCanonicalStateID(pmg.ID, alertID))return}@@ -728,10 +740,10 @@ func (m *Manager) checkQuarantineMetric(pmg models.PMGInstance, metricType strin"quarantine-"+metricType,float64(absoluteWarn),float64(absoluteCrit),- float64(defaults.QuarantineGrowthWarnMin),- float64(defaults.QuarantineGrowthCritMin),- float64(defaults.QuarantineGrowthWarnPct),- float64(defaults.QuarantineGrowthCritPct),+ float64(growthWarnMin),+ float64(growthCritMin),+ float64(growthWarnPct),+ float64(growthCritPct),2*time.Hour,false,)diff --git a/internal/config/persistence.go b/internal/config/persistence.goindex 1d222c88f5..62f8fcd0bc 100644--- a/internal/config/persistence.go+++ b/internal/config/persistence.go@@ -865,6 +865,12 @@ func normalizeAlertDefaults(config *alerts.AlertConfig) {config.TimeThresholds["all"] = defaultDelay}+ // Docker and PMG count thresholds decode unset when the JSON omits them+ // (an import or an alerts.json older than the field); resolve that marker+ // here so it never reaches disk, where it would read back as Off.+ alerts.NormalizeDockerDefaults(config)+ alerts.NormalizePMGDefaults(config)+// Snapshot defaultsif config.SnapshotDefaults.WarningDays < 0 {config.SnapshotDefaults.WarningDays = 0diff --git a/internal/config/persistence_offable_counts_test.go b/internal/config/persistence_offable_counts_test.gonew file mode 100644index 0000000000..85a95725c4--- /dev/null+++ b/internal/config/persistence_offable_counts_test.go@@ -0,0 +1,60 @@+package config++import (+ "encoding/json"+ "os"+ "path/filepath"+ "testing"++ "github.com/rcourtman/pulse-go-rewrite/internal/alerts"+ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++// Docker and PMG count thresholds are plain ints where 0 is Off. An+// alerts.json written before these sections existed carries neither key, and+// must load with factory values rather than everything Off.+func TestLoadAlertConfigOlderFileTakesFactoryDockerAndPMGCounts(t *testing.T) {+ tempDir := t.TempDir()+ cp := NewConfigPersistence(tempDir)+ require.NoError(t, os.WriteFile(filepath.Join(tempDir, "alerts.json"), []byte(`{"enabled": true}`), 0600))++ cfg, err := cp.LoadAlertConfig()+ require.NoError(t, err)++ assert.Equal(t, 3, cfg.DockerDefaults.RestartCount)+ assert.Equal(t, 300, cfg.DockerDefaults.RestartWindow)+ assert.Equal(t, 90, cfg.DockerDefaults.MemoryWarnPct)+ assert.Equal(t, 95, cfg.DockerDefaults.MemoryCriticalPct)+ assert.Equal(t, 500, cfg.PMGDefaults.QueueTotalWarning)+ assert.Equal(t, 500, cfg.PMGDefaults.QuarantineGrowthCritMin)+}++// An import hands SaveAlertConfig a config decoded from the export file+// without the manager's normalization. The unset marker for keys that file+// omits must not reach disk, where it would read back as Off.+func TestSaveAlertConfigResolvesUnsetDockerAndPMGCounts(t *testing.T) {+ tempDir := t.TempDir()+ cp := NewConfigPersistence(tempDir)++ var imported alerts.AlertConfig+ require.NoError(t, json.Unmarshal([]byte(`{"enabled": true, "pmgDefaults": {"queueTotalWarning": 0}}`), &imported))+ require.NoError(t, cp.SaveAlertConfig(imported))++ data, err := os.ReadFile(filepath.Join(tempDir, "alerts.json"))+ require.NoError(t, err)+ var saved struct {+ DockerDefaults map[string]any `json:"dockerDefaults"`+ PMGDefaults map[string]any `json:"pmgDefaults"`+ }+ require.NoError(t, json.Unmarshal(data, &saved))++ assert.EqualValues(t, 3, saved.DockerDefaults["restartCount"])+ assert.EqualValues(t, 0, saved.PMGDefaults["queueTotalWarning"], "the import's explicit Off")+ assert.EqualValues(t, 1000, saved.PMGDefaults["queueTotalCritical"], "a key the import omits")++ reloaded, err := cp.LoadAlertConfig()+ require.NoError(t, err)+ assert.Equal(t, 0, reloaded.PMGDefaults.QueueTotalWarning)+ assert.Equal(t, 1000, reloaded.PMGDefaults.QueueTotalCritical)+}