@@ -80,6 +80,16 @@ type Config struct {
8080 // During the grace period, the operator requeues the pod at this interval to check
8181 // whether the transient state has resolved or the grace period has elapsed.
8282 FailureRecheckInterval time.Duration
83+
84+ // WebhookSkipCategories is a list of failure categories that should not trigger webhook calls.
85+ // Valid values: ContainerWaiting, ContainerTerminated, PodPhase, PodStatus, PodCondition
86+ // Empty means all categories trigger webhooks.
87+ WebhookSkipCategories []string
88+
89+ // WebhookMinSeverity is the minimum severity level required to trigger a webhook call.
90+ // Valid values: LOW, MEDIUM, HIGH, CRITICAL
91+ // Empty means all severities trigger webhooks.
92+ WebhookMinSeverity string
8393}
8494
8595// DefaultConfig returns a Config with default values
@@ -183,6 +193,14 @@ func LoadFromEnv() *Config {
183193 }
184194 }
185195
196+ if v := os .Getenv ("WEBHOOK_SKIP_CATEGORIES" ); v != "" {
197+ cfg .WebhookSkipCategories = splitAndTrim (v , "," )
198+ }
199+
200+ if v := os .Getenv ("WEBHOOK_MIN_SEVERITY" ); v != "" {
201+ cfg .WebhookMinSeverity = strings .ToUpper (strings .TrimSpace (v ))
202+ }
203+
186204 return cfg
187205}
188206
@@ -221,6 +239,42 @@ func (c *Config) IsNamespaceWatched(namespace string) bool {
221239 return false
222240}
223241
242+ // severityLevel defines the numeric level of each severity for threshold comparison.
243+ // Lower number = higher severity, consistent with P-level conventions (P0/P1/...).
244+ var severityLevel = map [string ]int {
245+ "CRITICAL" : 0 ,
246+ "HIGH" : 1 ,
247+ "MEDIUM" : 2 ,
248+ "LOW" : 3 ,
249+ }
250+
251+ // ShouldSendWebhook returns true if the failure should trigger a webhook call.
252+ // Both conditions must pass (AND logic):
253+ // - The failure category must not be in WebhookSkipCategories
254+ // - The failure severity must meet or exceed WebhookMinSeverity
255+ //
256+ // If neither filter is configured, always returns true (default behavior preserved).
257+ func (c * Config ) ShouldSendWebhook (category , severity string ) bool {
258+ // Category filter: skip if category is in the skip list
259+ for _ , cat := range c .WebhookSkipCategories {
260+ if cat == category {
261+ return false
262+ }
263+ }
264+
265+ // Severity filter: skip if severity is below the minimum threshold
266+ // e.g. WebhookMinSeverity=HIGH → only CRITICAL and HIGH pass
267+ if c .WebhookMinSeverity != "" {
268+ minLevel , minKnown := severityLevel [c .WebhookMinSeverity ]
269+ curLevel , curKnown := severityLevel [severity ]
270+ if minKnown && curKnown && curLevel > minLevel {
271+ return false
272+ }
273+ }
274+
275+ return true
276+ }
277+
224278// splitAndTrim splits a string by separator and trims whitespace
225279func splitAndTrim (s , sep string ) []string {
226280 parts := strings .Split (s , sep )
0 commit comments