From e6253cfa3da1ad458cc064b973e4f86bc1e301fd Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Sun, 31 Aug 2025 15:03:09 +0000 Subject: [PATCH] fix: enable alert checking for mock mode data (addresses #399) Mock mode was bypassing alert checking entirely, causing alerts not to trigger even when thresholds were exceeded. Added checkMockAlerts() function that processes mock VMs, containers, nodes and storage through the alert manager. --- internal/monitoring/monitor.go | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go index 28b44cf54..f9051bcd9 100644 --- a/internal/monitoring/monitor.go +++ b/internal/monitoring/monitor.go @@ -406,6 +406,9 @@ func (m *Monitor) Start(ctx context.Context, wsHub *websocket.Hub) { // Start polling in a goroutine so it doesn't block the ticker (only if not in mock mode) if !mockEnabled { go m.poll(ctx, wsHub) + } else { + // In mock mode, still check alerts for mock data + go m.checkMockAlerts() } case <-broadcastTicker.C: @@ -2800,3 +2803,38 @@ func (m *Monitor) pollPBSBackups(ctx context.Context, instanceName string, clien // Update state m.state.UpdatePBSBackups(instanceName, allBackups) } + +// checkMockAlerts checks alerts for mock data +func (m *Monitor) checkMockAlerts() { + if !mock.IsMockEnabled() { + return + } + + // Get mock state + state := mock.GetMockState() + + log.Info(). + Int("vms", len(state.VMs)). + Int("containers", len(state.Containers)). + Msg("Checking alerts for mock data") + + // Check alerts for each VM + for _, vm := range state.VMs { + m.alertManager.CheckGuest(vm, "mock") + } + + // Check alerts for each container + for _, container := range state.Containers { + m.alertManager.CheckGuest(container, "mock") + } + + // Check alerts for each node + for _, node := range state.Nodes { + m.alertManager.CheckNode(node) + } + + // Check alerts for storage + for _, storage := range state.Storage { + m.alertManager.CheckStorage(storage) + } +}