From 32d92d4e3f4739260fd9b48f0a91d9d7fac9130a Mon Sep 17 00:00:00 2001 From: JamesJJ Date: Thu, 15 Apr 2021 21:00:21 +0800 Subject: [PATCH] Env SUPPRESS_UNKNOWN_TO_OK (bool) to eliminate non-actionable alerts --- function/main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/function/main.go b/function/main.go index a98105a..7f04a84 100644 --- a/function/main.go +++ b/function/main.go @@ -10,9 +10,16 @@ import ( "log" "net/http" "os" + "strconv" "time" ) +var ( + SuppressableAlertsStateFromTo = map[string]string{ + "INSUFFICIENT_DATA": "OK", + } +) + func handleRequest(request events.SNSEvent) error { var cloudwatchAlarm events.CloudWatchAlarmSNSPayload @@ -22,6 +29,18 @@ func handleRequest(request events.SNSEvent) error { return nil // Non-retryable error } + if suppress, err := strconv.ParseBool(os.Getenv("SUPPRESS_UNKNOWN_TO_OK")); err == nil && suppress { + if SuppressableAlertsStateFromTo[cloudwatchAlarm.OldStateValue] == cloudwatchAlarm.NewStateValue { + log.Printf( + "Alarm suppressed for %s --> %s \"%s\"", + cloudwatchAlarm.OldStateValue, + cloudwatchAlarm.NewStateValue, + cloudwatchAlarm.AlarmName, + ) + return nil + } + } + log.Printf( "Alarm: %s --> %s \"%s\"", cloudwatchAlarm.OldStateValue,