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
Stop operator-suppressed alerts before delivery dispatch
pulse-triage[bot]e2430fb759ec
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.mdindex 44d040e556..f6784ff6b0 100644--- a/docs/release-control/v6/internal/subsystems/alerts.md+++ b/docs/release-control/v6/internal/subsystems/alerts.md@@ -2591,7 +2591,14 @@ policy removal or expiry, and post-mutation reconciliation are exercised acrossprovider incidents, metric and canonical lifecycle writers in`internal/alerts/alert_admission_test.go`.Operator suppression is never converted into a quiet-hours replay, including-for recovery notifications carrying stale replay metadata.+for recovery notifications carrying stale replay metadata. The internal alert+dispatch path applies this terminal decision even for an already-active alert+between a policy save and its reconciliation: it neither invokes a delivery+callback nor marks the alert notified, and it removes stale replay metadata.+The read-only delivery diagnosis reports the operator reason as suppressed,+not as a quiet-hours deferral. `TestOperatorPolicySuppressesDirectAlertDispatchWithoutQueueReplay`+pins muted, expected-offline, maintenance and unaffected performance cases,+including the immutable suppression-versus-deferral event distinction.After a persisted policy mutation, `ReconcileResourceOperatorState` resolvesalready-active records for that resource immediately; later detector writescannot recreate them while suppression remains active. Existing prefix, tag,diff --git a/internal/alerts/intent_policy_test.go b/internal/alerts/intent_policy_test.goindex 68ebd4e7aa..e3372cc70d 100644--- a/internal/alerts/intent_policy_test.go+++ b/internal/alerts/intent_policy_test.go@@ -315,6 +315,79 @@ func TestCanonicalResourcePolicyCannotEnterQuietHoursReplay(t *testing.T) {}}+func TestOperatorPolicySuppressesDirectAlertDispatchWithoutQueueReplay(t *testing.T) {+ now := time.Now().UTC()+ end := now.Add(time.Hour)+ cases := []struct {+ name string+ intent OperatorIntentContext+ alertType string+ wantReason string+ wantSend bool+ }{+ {"muted resource", OperatorIntentContext{MonitoringMode: "muted"}, "cpu", "operator_muted", false},+ {"expected offline", OperatorIntentContext{MonitoringMode: "expected_offline"}, "offline", "operator_expected_offline", false},+ {"active maintenance", OperatorIntentContext{MaintenanceStartAt: &now, MaintenanceEndAt: &end}, "cpu", "operator_maintenance", false},+ {"unrelated performance alert", OperatorIntentContext{MonitoringMode: "expected_offline"}, "cpu", AlertDeliveryReasonReady, true},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ m := newEventLogManager(t)+ m.SetOperatorIntentContextResolver(func(resourceID string, observedAt time.Time) (OperatorIntentContext, bool) {+ if resourceID != "vm:101" {+ t.Fatalf("operator policy queried for %q", resourceID)+ }+ return tc.intent, true+ })+ delivered := 0+ m.SetAlertCallback(func(*Alert) { delivered++ })+ alert := &Alert{+ ID: "policy-alert", ResourceID: "vm:101", Type: tc.alertType,+ Level: AlertLevelCritical, StartTime: now, LastSeen: now,+ Metadata: map[string]interface{}{+ MetadataQuietHoursSuppressed: true,+ MetadataQuietHoursReplayAt: end.Format(time.RFC3339),+ },+ }+ // Simulate an existing alert while a newly saved policy is being+ // reconciled. Direct dispatch must not turn that policy into replay.+ m.mu.Lock()+ m.activeAlerts[alert.ID] = alert+ m.mu.Unlock()+ diagnosis, ok := m.DiagnoseAlertDelivery(alert.ID)+ m.mu.Lock()+ sent := m.dispatchAlert(alert, false)+ m.mu.Unlock()+ wantDelivered := 0+ if tc.wantSend {+ wantDelivered = 1+ }+ if sent != tc.wantSend || delivered != wantDelivered {+ t.Fatalf("dispatch = %v, callback count = %d; want send=%v", sent, delivered, tc.wantSend)+ }+ if !ok || diagnosis.Reason != tc.wantReason || diagnosis.QuietHoursReplayAt != nil {+ t.Fatalf("diagnosis = %+v, exists=%v; want reason %q", diagnosis, ok, tc.wantReason)+ }+ if hasQuietHoursNotificationReplay(alert) {+ t.Fatal("operator policy left or created replay metadata")+ }+ if !tc.wantSend {+ if alert.LastNotified != nil {+ t.Fatal("suppressed alert was marked notified")+ }+ suppressed := queryAlertEvents(t, m, eventlog.Filter{Types: []string{eventlog.TypeNotificationSuppressed}})+ if len(suppressed) != 1 || suppressed[0].Reason != tc.wantReason {+ t.Fatalf("suppression events = %+v; want one %q event", suppressed, tc.wantReason)+ }+ deferred := queryAlertEvents(t, m, eventlog.Filter{Types: []string{eventlog.TypeNotificationDeferred}})+ if len(deferred) != 0 {+ t.Fatalf("operator suppression produced deferred events: %+v", deferred)+ }+ }+ })+ }+}+func TestLifecycleAlertStartsAtFirstIntentMatch(t *testing.T) {m := NewManagerWithDataDir(t.TempDir())t.Cleanup(m.Stop)diff --git a/internal/alerts/notification_policy.go b/internal/alerts/notification_policy.goindex 811767fc81..a1cc40fbab 100644--- a/internal/alerts/notification_policy.go+++ b/internal/alerts/notification_policy.go@@ -191,6 +191,15 @@ func (m *Manager) dispatchAlert(alert *Alert, async bool) bool {map[string]string{"primaryAlertId": alert.Correlation.PrimaryAlertID})return false}+ // Resource monitoring policy is a terminal suppression, unlike quiet hours.+ // An alert already active when the policy changes must not be queued for+ // replay or reach a callback before reconciliation clears it.+ if suppressed, reason := m.operatorSuppressionForAlertNoLock(alert, m.policyNow().UTC()); suppressed {+ clearQuietHoursNotificationReplay(alert)+ m.recordAlertEvent(eventlog.TypeNotificationSuppressed, alert, "", reason,+ "Notification suppressed by resource monitoring policy.", nil)+ return false+ }trackingKey := canonicalTrackingKeyForAlert(alert)@@ -480,10 +489,8 @@ func (m *Manager) shouldSuppressNotification(alert *Alert) (bool, string) {if alert == nil {return false, ""}- if suppressed, reason := m.operatorSuppressionForAlertNoLock(alert, time.Now().UTC()); suppressed {- return true, reason- }-+ // Only quiet-hours matches are replayable. Operator policy is checked by+ // each caller before this helper, because it must drop rather than defer.if !m.isInQuietHours() {return false, ""}@@ -813,6 +820,14 @@ func (m *Manager) diagnoseActiveAlertLocked(alert *Alert) AlertDeliveryDiagnosisdiagnosis.setSuppressed(AlertDeliveryReasonSnoozed, "Alert is snoozed, so notifications and escalations are paused until the selected time.")return true}():+ case func() bool {+ suppressed, reason := m.operatorSuppressionForAlertNoLock(alert, now.UTC())+ if !suppressed {+ return false+ }+ diagnosis.setSuppressed(reason, "Alert notification is suppressed by the resource monitoring policy.")+ return true+ }():case !m.config.Enabled:diagnosis.setSuppressed(AlertDeliveryReasonNotificationsDisabled, "Alert notifications are disabled in the alert configuration.")case m.config.ActivationState != ActivationActive: