From 83e8488af9a7796280fb96f8db4a02e5977584cd Mon Sep 17 00:00:00 2001 From: Masafumi Yabu Date: Thu, 14 Dec 2023 18:05:48 +0900 Subject: [PATCH] feat: add dedup key to supress duplicate alerts --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index 77ea11a..fc12f30 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "bytes" "context" + "crypto/sha256" "fmt" "log" "net/http" @@ -57,6 +58,7 @@ func main() { Details: details, } event.Payload = payload + event.DedupKey = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprintf("%s-%s", hostName, unitName)))) var retryErr error retryWaitDuration := time.Second @@ -65,6 +67,7 @@ func main() { time.Sleep(retryWaitDuration) retryWaitDuration *= 2 } + if _, err := pagerduty.ManageEventWithContext(context.Background(), event); err != nil { log.Printf("failed to send to pagerduty: %+v", err) retryErr = err