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
Preserve queued resolved notifications on cancellation
rcourtman675dff7da52b
diff --git a/docs/release-control/v6/internal/subsystems/notifications.md b/docs/release-control/v6/internal/subsystems/notifications.mdindex 1be90c884c..0ef863ca0f 100644--- a/docs/release-control/v6/internal/subsystems/notifications.md+++ b/docs/release-control/v6/internal/subsystems/notifications.md@@ -143,6 +143,11 @@ That same queue ownership also governs persistent queue storage roots. Thenotifications queue database must normalize its owned data directory andresolve the fixed `notification_queue.db` leaf through the shared storage-pathhelper instead of joining raw caller-provided directory strings.+That same queue owner also governs alert-resolution cancellation policy.+Cancelling queued work by alert identifier must remove outstanding firing+deliveries for that alert, but it must preserve already-queued resolved+notifications so recovery deliveries cannot be dropped just because the alert+was resolved before the queue drained.`internal/api/notifications.go` and`frontend-modern/src/api/notifications.ts` are shared boundaries withdiff --git a/internal/notifications/queue.go b/internal/notifications/queue.goindex e4b0285091..40dbd9c7cd 100644--- a/internal/notifications/queue.go+++ b/internal/notifications/queue.go@@ -1030,7 +1030,7 @@ func (nq *NotificationQueue) CancelByAlertIdentifiers(alertIdentifiers []string)// Query pending/sending notificationsquery := `- SELECT id, alerts+ SELECT id, type, alertsFROM notification_queueWHERE status IN ('pending', 'sending')`@@ -1048,8 +1048,9 @@ func (nq *NotificationQueue) CancelByAlertIdentifiers(alertIdentifiers []string)for rows.Next() {var notifID string+ var notifType stringvar alertsJSON []byte- if err := rows.Scan(¬ifID, &alertsJSON); err != nil {+ if err := rows.Scan(¬ifID, ¬ifType, &alertsJSON); err != nil {log.Error().Err(err).Str("component", "notification_queue").@@ -1057,6 +1058,9 @@ func (nq *NotificationQueue) CancelByAlertIdentifiers(alertIdentifiers []string)Msg("Failed to scan notification for cancellation")continue}+ if !queueTypeCancelableOnAlertResolution(notifType) {+ continue+ }var alerts []*alerts.Alertif err := json.Unmarshal(alertsJSON, &alerts); err != nil {@@ -1114,6 +1118,11 @@ func (nq *NotificationQueue) CancelByAlertIdentifiers(alertIdentifiers []string)return nil}+func queueTypeCancelableOnAlertResolution(notifType string) bool {+ _, event := normalizeQueueType(notifType)+ return event != eventResolved+}+// CancelByTypes marks queued notifications of the given types as cancelled.func (nq *NotificationQueue) CancelByTypes(types []string, reason string) error {if len(types) == 0 {diff --git a/internal/notifications/queue_test.go b/internal/notifications/queue_test.goindex 067557cb0b..ede4403f56 100644--- a/internal/notifications/queue_test.go+++ b/internal/notifications/queue_test.go@@ -561,6 +561,61 @@ func TestCancelByAlertIdentifiers_MatchingNotificationCancelled(t *testing.T) {}}+func TestCancelByAlertIdentifiers_PreservesResolvedNotifications(t *testing.T) {+ tempDir := t.TempDir()+ nq, err := NewNotificationQueue(tempDir)+ if err != nil {+ t.Fatalf("Failed to create notification queue: %v", err)+ }+ defer func() { _ = nq.Stop() }()++ futureRetry := time.Now().Add(1 * time.Hour)+ firing := &QueuedNotification{+ ID: "notif-firing",+ Type: "webhook",+ Status: QueueStatusPending,+ MaxAttempts: 3,+ Config: []byte(`{}`),+ NextRetryAt: &futureRetry,+ Alerts: []*alerts.Alert{{ID: "alert-1"}},+ }+ resolved := &QueuedNotification{+ ID: "notif-resolved",+ Type: "webhook" + queueTypeSuffixResolved,+ Status: QueueStatusPending,+ MaxAttempts: 3,+ Config: []byte(`{}`),+ NextRetryAt: &futureRetry,+ Alerts: []*alerts.Alert{{ID: "alert-1"}},+ }++ for _, notif := range []*QueuedNotification{firing, resolved} {+ if err := nq.Enqueue(notif); err != nil {+ t.Fatalf("Failed to enqueue %s: %v", notif.ID, err)+ }+ }++ if err := nq.CancelByAlertIdentifiers([]string{"alert-1"}); err != nil {+ t.Fatalf("CancelByAlertIdentifiers returned error: %v", err)+ }++ var statusFiring NotificationQueueStatus+ if err := nq.db.QueryRow(`SELECT status FROM notification_queue WHERE id = ?`, firing.ID).Scan(&statusFiring); err != nil {+ t.Fatalf("failed to read firing notification status: %v", err)+ }+ if statusFiring != QueueStatusCancelled {+ t.Fatalf("expected firing notification to be cancelled, got %s", statusFiring)+ }++ var statusResolved NotificationQueueStatus+ if err := nq.db.QueryRow(`SELECT status FROM notification_queue WHERE id = ?`, resolved.ID).Scan(&statusResolved); err != nil {+ t.Fatalf("failed to read resolved notification status: %v", err)+ }+ if statusResolved != QueueStatusPending {+ t.Fatalf("expected resolved notification to remain pending, got %s", statusResolved)+ }+}+func TestCancelByAlertIdentifiers_MultipleAlertsPartialMatch(t *testing.T) {tempDir := t.TempDir()nq, err := NewNotificationQueue(tempDir)