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
fix(alerts): always send recovery notifications regardless of quiet hours
rcourtmandf23d8091952
diff --git a/internal/alerts/alerts.go b/internal/alerts/alerts.goindex cfddafcb81..ae486896c6 100644--- a/internal/alerts/alerts.go+++ b/internal/alerts/alerts.go@@ -7058,8 +7058,7 @@ func (m *Manager) clearNodeOfflineAlert(node models.Node) {}m.addRecentlyResolvedWithPrimaryLock(alertID, resolvedAlert)- // Send recovery notification (async to avoid deadlock — callback acquires m.mu.RLock- // via ShouldSuppressResolvedNotification, and we currently hold m.mu.Lock)+ // Send recovery notification (async to avoid blocking alert cleanup while holding m.mu.Lock)m.safeCallResolvedCallback(alertID, true)// Log recovery@@ -7177,8 +7176,7 @@ func (m *Manager) clearPBSOfflineAlert(pbs models.PBSInstance) {}m.addRecentlyResolvedWithPrimaryLock(alertID, resolvedAlert)- // Send recovery notification (async to avoid deadlock — callback acquires m.mu.RLock- // via ShouldSuppressResolvedNotification, and we currently hold m.mu.Lock)+ // Send recovery notification (async to avoid blocking alert cleanup while holding m.mu.Lock)m.safeCallResolvedCallback(alertID, true)// Log recovery@@ -7296,8 +7294,7 @@ func (m *Manager) clearPMGOfflineAlert(pmg models.PMGInstance) {}m.addRecentlyResolvedWithPrimaryLock(alertID, resolvedAlert)- // Send recovery notification (async to avoid deadlock — callback acquires m.mu.RLock- // via ShouldSuppressResolvedNotification, and we currently hold m.mu.Lock)+ // Send recovery notification (async to avoid blocking alert cleanup while holding m.mu.Lock)m.safeCallResolvedCallback(alertID, true)// Log recovery@@ -8424,8 +8421,7 @@ func (m *Manager) clearStorageOfflineAlert(storage models.Storage) {}m.addRecentlyResolvedWithPrimaryLock(alertID, resolvedAlert)- // Send recovery notification (async to avoid deadlock — callback acquires m.mu.RLock- // via ShouldSuppressResolvedNotification, and we currently hold m.mu.Lock)+ // Send recovery notification (async to avoid blocking alert cleanup while holding m.mu.Lock)m.safeCallResolvedCallback(alertID, true)// Log recovery@@ -8573,8 +8569,7 @@ func (m *Manager) clearGuestPoweredOffAlert(guestID, name string) {}m.addRecentlyResolvedWithPrimaryLock(alertID, resolvedAlert)- // Send recovery notification (async to avoid deadlock — callback acquires m.mu.RLock- // via ShouldSuppressResolvedNotification, and we currently hold m.mu.Lock)+ // Send recovery notification (async to avoid blocking alert cleanup while holding m.mu.Lock)m.safeCallResolvedCallback(alertID, true)// Log recoverydiff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex 731f1c6708..e823915914 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -8944,7 +8944,7 @@ func (m *Monitor) handleAlertResolved(alertID string) {}}- // Handle notifications (may be suppressed by quiet hours)+ // Handle notificationsif m.notificationMgr != nil {m.notificationMgr.CancelAlert(alertID)if m.notificationMgr.GetNotifyOnResolve() {@@ -8952,10 +8952,6 @@ func (m *Monitor) handleAlertResolved(alertID string) {resolvedAlert = m.alertManager.GetResolvedAlert(alertID)}if resolvedAlert != nil {- // Check if recovery notification should be suppressed during quiet hours- if m.alertManager.ShouldSuppressResolvedNotification(resolvedAlert.Alert) {- return- }go m.notificationMgr.SendResolvedAlert(resolvedAlert)}}diff --git a/internal/monitoring/monitor_alert_handling_test.go b/internal/monitoring/monitor_alert_handling_test.goindex 3fb53fd0fd..35357bb3bc 100644--- a/internal/monitoring/monitor_alert_handling_test.go+++ b/internal/monitoring/monitor_alert_handling_test.go@@ -1,9 +1,15 @@package monitoringimport (+ "encoding/json"+ "io"+ "net/http"+ "net/http/httptest""testing"+ "time""github.com/rcourtman/pulse-go-rewrite/internal/alerts"+ "github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/internal/notifications""github.com/rcourtman/pulse-go-rewrite/internal/websocket")@@ -59,3 +65,100 @@ func TestMonitor_HandleAlertResolved_Detailed_Extra(t *testing.T) {// This should run safelym.handleAlertResolved("alert-id")}++func TestHandleAlertResolved_QuietHoursDoesNotSuppressRecovery(t *testing.T) {+ received := make(chan []byte, 1)+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ defer r.Body.Close()+ body, _ := io.ReadAll(r.Body)+ select {+ case received <- body:+ default:+ }+ w.WriteHeader(http.StatusOK)+ }))+ t.Cleanup(srv.Close)++ notifMgr := notifications.NewNotificationManagerWithDataDir("http://pulse.example", t.TempDir())+ if err := notifMgr.UpdateAllowedPrivateCIDRs("127.0.0.1/32,::1/128"); err != nil {+ t.Fatalf("UpdateAllowedPrivateCIDRs: %v", err)+ }+ notifMgr.AddWebhook(notifications.WebhookConfig{+ ID: "test-webhook",+ Name: "test-webhook",+ URL: srv.URL,+ Enabled: true,+ Service: "generic",+ })+ notifMgr.SetNotifyOnResolve(true)++ alertMgr := alerts.NewManager()+ cfg := alertMgr.GetConfig()+ cfg.Enabled = true+ cfg.GuestDefaults.PoweredOffSeverity = alerts.AlertLevelWarning+ cfg.Schedule.QuietHours.Enabled = true+ cfg.Schedule.QuietHours.Timezone = "UTC"+ cfg.Schedule.QuietHours.Days = map[string]bool{+ "monday": true,+ "tuesday": true,+ "wednesday": true,+ "thursday": true,+ "friday": true,+ "saturday": true,+ "sunday": true,+ }+ now := time.Now().UTC()+ cfg.Schedule.QuietHours.Start = now.Add(-1 * time.Hour).Format("15:04")+ cfg.Schedule.QuietHours.End = now.Add(1 * time.Hour).Format("15:04")+ alertMgr.UpdateConfig(cfg)++ m := &Monitor{+ alertManager: alertMgr,+ notificationMgr: notifMgr,+ }+ alertMgr.SetResolvedCallback(m.handleAlertResolved)++ vm := models.VM{+ ID: "vm-1",+ Name: "test-vm",+ Node: "node-1",+ Instance: "inst-1",+ Status: "stopped",+ Memory: models.Memory{Usage: 0},+ Disk: models.Disk{Usage: 0},+ }++ // Two consecutive stopped polls are required to trigger the powered-off alert.+ alertMgr.CheckGuest(vm, vm.Instance)+ alertMgr.CheckGuest(vm, vm.Instance)++ alertID := "guest-powered-off-" + vm.ID++ // Recover while quiet hours are active.+ vm.Status = "running"+ alertMgr.CheckGuest(vm, vm.Instance)++ resolved := alertMgr.GetResolvedAlert(alertID)+ if resolved == nil || resolved.Alert == nil {+ t.Fatalf("expected resolved alert %q to exist", alertID)+ }+ if !alertMgr.ShouldSuppressResolvedNotification(resolved.Alert) {+ t.Fatalf("expected quiet hours suppression to be active for non-critical resolved alert %q (test precondition)", alertID)+ }++ select {+ case body := <-received:+ var payload map[string]interface{}+ if err := json.Unmarshal(body, &payload); err != nil {+ t.Fatalf("failed to parse webhook payload: %v", err)+ }+ if payload["event"] != "resolved" {+ t.Fatalf("expected webhook event=resolved, got %v", payload["event"])+ }+ if payload["alertId"] != alertID {+ t.Fatalf("expected webhook alertId=%q, got %v", alertID, payload["alertId"])+ }+ case <-time.After(5 * time.Second):+ t.Fatalf("timed out waiting for resolved notification webhook (should not be suppressed by quiet hours)")+ }+}