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.
This commit is contained in:
Pulse Monitor
2025-08-17 08:07:39 +00:00
parent aa4a26d42c
commit edb4c8e0f2
2 changed files with 10 additions and 3 deletions
+3 -3
View File
@@ -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).
+7
View File
@@ -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)
}
}