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
package alerts
import (
"testing"
"time"
)
func TestNotificationActivationDoesNotSuppressDetectionOrActiveReadModel(t *testing.T) {
for _, activationState := range []ActivationState{
ActivationPending,
ActivationSnoozed,
} {
t.Run(string(activationState), func(t *testing.T) {
m := newTestManager(t)
delivered := make(chan *Alert, 1)
lifecycle := make(chan LifecycleEvent, 1)
m.SetAlertCallback(func(alert *Alert) {
delivered <- alert
})
m.SubscribeLifecycleCallback(func(event LifecycleEvent) {
lifecycle <- event
})
m.mu.Lock()
m.config.Enabled = true
m.config.ActivationState = activationState
m.config.TimeThresholds = map[string]int{}
m.config.SuppressionWindow = 0
m.config.MinimumDelta = 0
m.mu.Unlock()
m.checkMetric(
"boundary-resource",
"Boundary Resource",
"node-1",
"instance-1",
"guest",
"cpu",
95,
&HysteresisThreshold{Trigger: 80, Clear: 75},
nil,
)
active := m.GetActiveAlerts()
if len(active) != 1 {
t.Fatalf(
"activation state %q produced %d active alerts, want 1",
activationState,
len(active),
)
}
if active[0].ResourceID != "boundary-resource" {
t.Fatalf(
"activation state %q exposed resource %q, want boundary-resource",
activationState,
active[0].ResourceID,
)
}
select {
case event := <-lifecycle:
if event.Type != "fired" || event.Alert == nil || event.Alert.ID != active[0].ID {
t.Fatalf("activation state %q emitted unexpected lifecycle event: %#v", activationState, event)
}
default:
t.Fatalf("activation state %q suppressed the alert lifecycle event", activationState)
}
select {
case alert := <-delivered:
t.Fatalf(
"activation state %q delivered external notification for %q",
activationState,
alert.ID,
)
case <-time.After(50 * time.Millisecond):
}
})
}
}