From 6922a79d596d17cec7fe49c79cd183d0409497eb Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Sun, 10 Aug 2025 22:29:14 +0000 Subject: [PATCH] fix: reload alert and notification configs after import - Import was saving configs to disk but not updating in-memory state - Added explicit reloading of alert thresholds after import - Added explicit reloading of webhooks after import - Added explicit reloading of email config after import - Settings now show immediately in UI without requiring restart Fixes #291 where imported alert thresholds and webhooks weren't visible until after service restart --- internal/api/config_handlers.go | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/internal/api/config_handlers.go b/internal/api/config_handlers.go index 8f0caccc9..59f194209 100644 --- a/internal/api/config_handlers.go +++ b/internal/api/config_handlers.go @@ -1394,6 +1394,43 @@ func (h *ConfigHandlers) HandleImportConfig(w http.ResponseWriter, r *http.Reque } } + // Also reload alert and notification configs explicitly + // (the monitor reload only reloads nodes unless it's a full reload) + if h.monitor != nil { + // Reload alert configuration + if alertConfig, err := h.persistence.LoadAlertConfig(); err == nil { + h.monitor.GetAlertManager().UpdateConfig(*alertConfig) + log.Info().Msg("Reloaded alert configuration after import") + } else { + log.Warn().Err(err).Msg("Failed to reload alert configuration after import") + } + + // Reload webhook configuration + if webhooks, err := h.persistence.LoadWebhooks(); err == nil { + // Clear existing webhooks and add new ones + notificationMgr := h.monitor.GetNotificationManager() + // Get current webhooks to clear them + for _, webhook := range notificationMgr.GetWebhooks() { + notificationMgr.DeleteWebhook(webhook.ID) + } + // Add imported webhooks + for _, webhook := range webhooks { + notificationMgr.AddWebhook(webhook) + } + log.Info().Int("count", len(webhooks)).Msg("Reloaded webhook configuration after import") + } else { + log.Warn().Err(err).Msg("Failed to reload webhook configuration after import") + } + + // Reload email configuration + if emailConfig, err := h.persistence.LoadEmailConfig(); err == nil { + h.monitor.GetNotificationManager().SetEmailConfig(*emailConfig) + log.Info().Msg("Reloaded email configuration after import") + } else { + log.Warn().Err(err).Msg("Failed to reload email configuration after import") + } + } + log.Info().Msg("Configuration imported successfully") w.WriteHeader(http.StatusOK)