From edb4c8e0f2db04e0ee9e3d42b3f2cc57d74fa3c9 Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Sun, 17 Aug 2025 08:07:39 +0000 Subject: [PATCH] fix: guest alerts and webhook notifications working properly - Fixed double CPU percentage multiplication for containers/VMs - Added CheckGuest calls to efficient polling path - Fixed newline escaping in grouped webhook notifications - Guest alerts now properly trigger for containers and VMs These changes address issues where guest alerts weren't being triggered at all due to the efficient polling path not calling CheckGuest, and webhook notifications were failing due to unescaped newlines in grouped alert messages breaking JSON templates. --- internal/alerts/alerts.go | 6 +++--- internal/monitoring/monitor.go | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/alerts/alerts.go b/internal/alerts/alerts.go index ce8b21053..f737907a5 100644 --- a/internal/alerts/alerts.go +++ b/internal/alerts/alerts.go @@ -403,7 +403,7 @@ func (m *Manager) CheckGuest(guest interface{}, instanceName string) { node = g.Node status = g.Status guestType = "VM" - cpu = g.CPU * 100 // Convert to percentage + cpu = g.CPU // Already in percentage memUsage = g.Memory.Usage diskUsage = g.Disk.Usage diskRead = g.DiskRead @@ -416,7 +416,7 @@ func (m *Manager) CheckGuest(guest interface{}, instanceName string) { node = g.Node status = g.Status guestType = "Container" - cpu = g.CPU * 100 // Convert to percentage + cpu = g.CPU // Already in percentage memUsage = g.Memory.Usage diskUsage = g.Disk.Usage diskRead = g.DiskRead @@ -450,7 +450,7 @@ func (m *Manager) CheckGuest(guest interface{}, instanceName string) { m.mu.RUnlock() // Check each metric - log.Debug(). + log.Info(). Str("guest", name). Float64("cpu", cpu). Float64("memory", memUsage). diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go index d00236ea4..dcda34aca 100644 --- a/internal/monitoring/monitor.go +++ b/internal/monitoring/monitor.go @@ -924,6 +924,9 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam allVMs = append(allVMs, vm) + // Check thresholds for alerts + m.alertManager.CheckGuest(vm, instanceName) + } else if res.Type == "lxc" { // Skip templates if configured if res.Template == 1 { @@ -966,6 +969,9 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam } allContainers = append(allContainers, container) + + // Check thresholds for alerts + m.alertManager.CheckGuest(container, instanceName) } } @@ -1241,6 +1247,7 @@ func (m *Monitor) pollContainersWithNodes(ctx context.Context, instanceName stri m.metricsHistory.AddGuestMetric(modelCT.ID, "netout", float64(modelCT.NetworkOut), now) // Check thresholds for alerts + log.Info().Str("container", modelCT.Name).Msg("Checking container alerts") m.alertManager.CheckGuest(modelCT, instanceName) } }