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
add patrol scope for flapping postmortem
rcourtmanfb05c38ec76e
diff --git a/internal/ai/patrol_triggers.go b/internal/ai/patrol_triggers.goindex 72468215c7..4cd1583706 100644--- a/internal/ai/patrol_triggers.go+++ b/internal/ai/patrol_triggers.go@@ -33,6 +33,7 @@ const (TriggerReasonManual TriggerReason = "manual" // User-initiated patrolTriggerReasonAlertFired TriggerReason = "alert_fired" // New alert triggeredTriggerReasonAlertCleared TriggerReason = "alert_cleared" // Alert was resolved+ TriggerReasonAlertFlapping TriggerReason = "alert_flapping" // Alert flapping detected and suppressedTriggerReasonAnomalyDetected TriggerReason = "anomaly" // Baseline breach detectedTriggerReasonUserAction TriggerReason = "user_action" // User dismissed/snoozed findingTriggerReasonConfigChanged TriggerReason = "config_changed" // System configuration changed@@ -352,7 +353,7 @@ func (tm *TriggerManager) SetEventTriggersEnabled(enabled bool) {// (alerts firing/clearing, anomaly detection) as opposed to user-initiated or scheduled triggers.func isEventDrivenTrigger(reason TriggerReason) bool {switch reason {- case TriggerReasonAlertFired, TriggerReasonAlertCleared, TriggerReasonAnomalyDetected:+ case TriggerReasonAlertFired, TriggerReasonAlertCleared, TriggerReasonAlertFlapping, TriggerReasonAnomalyDetected:return truedefault:return false@@ -361,7 +362,7 @@ func isEventDrivenTrigger(reason TriggerReason) bool {func (cfg PatrolEventTriggerConfig) allows(reason TriggerReason) bool {switch reason {- case TriggerReasonAlertFired, TriggerReasonAlertCleared:+ case TriggerReasonAlertFired, TriggerReasonAlertCleared, TriggerReasonAlertFlapping:return cfg.AlertTriggersEnabledcase TriggerReasonAnomalyDetected:return cfg.AnomalyTriggersEnabled@@ -663,3 +664,26 @@ func ScheduledPatrolScope() PatrolScope {Priority: triggerPriorityScheduled,}}++// FlappingPostmortemPatrolScope creates a patrol scope for an alert that the+// alerts manager has just transitioned into flapping suppression. The intent+// is to produce a finding that explains WHAT is flapping, WHY Pulse suppressed+// it, and what the operator can do about it -- so users see the diagnosis,+// not silence. Priority matches anomaly detection (medium-high) because a+// suppressed flap is operationally similar: signal Pulse already saw, that+// the user has not yet.+func FlappingPostmortemPatrolScope(alertIdentifier, resourceID, resourceType, alertType string) PatrolScope {+ context := "Flapping: " + alertType+ if alertType == "" {+ context = "Flapping detected"+ }+ return PatrolScope{+ ResourceIDs: []string{resourceID},+ ResourceTypes: patrolScopeResourceTypes(resourceType),+ Depth: PatrolDepthQuick,+ Reason: TriggerReasonAlertFlapping,+ Context: context,+ Priority: triggerPriorityAnomaly,+ AlertIdentifier: alertIdentifier,+ }+}diff --git a/internal/ai/patrol_triggers_flapping_test.go b/internal/ai/patrol_triggers_flapping_test.gonew file mode 100644index 0000000000..7622b1e194--- /dev/null+++ b/internal/ai/patrol_triggers_flapping_test.go@@ -0,0 +1,68 @@+package ai++import "testing"++func TestFlappingPostmortemPatrolScope(t *testing.T) {+ scope := FlappingPostmortemPatrolScope("alert-vm-100-cpu", "vm-100", "vm", "cpu")++ if scope.Reason != TriggerReasonAlertFlapping {+ t.Errorf("expected reason %s, got %s", TriggerReasonAlertFlapping, scope.Reason)+ }+ if scope.Priority != triggerPriorityAnomaly {+ t.Errorf("expected priority %d, got %d", triggerPriorityAnomaly, scope.Priority)+ }+ if scope.Depth != PatrolDepthQuick {+ t.Errorf("expected quick depth, got %v", scope.Depth)+ }+ if len(scope.ResourceIDs) != 1 || scope.ResourceIDs[0] != "vm-100" {+ t.Errorf("expected resource vm-100, got %v", scope.ResourceIDs)+ }+ if len(scope.ResourceTypes) != 1 || scope.ResourceTypes[0] != "vm" {+ t.Errorf("expected resource type vm, got %v", scope.ResourceTypes)+ }+ if scope.AlertIdentifier != "alert-vm-100-cpu" {+ t.Errorf("expected alertIdentifier alert-vm-100-cpu, got %s", scope.AlertIdentifier)+ }+ if scope.Context != "Flapping: cpu" {+ t.Errorf("expected context 'Flapping: cpu', got %q", scope.Context)+ }+}++func TestFlappingPostmortemPatrolScope_EmptyAlertType(t *testing.T) {+ scope := FlappingPostmortemPatrolScope("alert-id", "vm-100", "vm", "")+ if scope.Context != "Flapping detected" {+ t.Errorf("expected context 'Flapping detected', got %q", scope.Context)+ }+}++func TestTriggerPatrol_FlappingGatedByAlertTriggersEnabled(t *testing.T) {+ tm := NewTriggerManager(DefaultTriggerManagerConfig())+ tm.SetEventTriggerConfig(PatrolEventTriggerConfig{+ AlertTriggersEnabled: false,+ AnomalyTriggersEnabled: true,+ })++ scope := FlappingPostmortemPatrolScope("alert-1", "vm-100", "vm", "cpu")+ if accepted := tm.TriggerPatrol(scope); accepted {+ t.Fatal("expected flapping postmortem trigger to be rejected when alert source is disabled")+ }+}++func TestTriggerPatrol_FlappingAcceptedWhenAlertTriggersEnabled(t *testing.T) {+ tm := NewTriggerManager(DefaultTriggerManagerConfig())+ tm.SetEventTriggerConfig(PatrolEventTriggerConfig{+ AlertTriggersEnabled: true,+ AnomalyTriggersEnabled: false,+ })++ scope := FlappingPostmortemPatrolScope("alert-1", "vm-100", "vm", "memory")+ if accepted := tm.TriggerPatrol(scope); !accepted {+ t.Fatal("expected flapping postmortem trigger to be accepted when alert source is enabled")+ }+}++func TestIsEventDrivenTrigger_IncludesFlapping(t *testing.T) {+ if !isEventDrivenTrigger(TriggerReasonAlertFlapping) {+ t.Fatal("expected TriggerReasonAlertFlapping to be treated as event-driven")+ }+}