From 330e69f41733a4bc3c5ec92ec1aada000725cc63 Mon Sep 17 00:00:00 2001 From: Damian Slowinski Date: Tue, 6 Jun 2023 15:31:54 +0200 Subject: [PATCH] add Microsoft Teams webhook support --- internal/pkg/alerts/alert.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/internal/pkg/alerts/alert.go b/internal/pkg/alerts/alert.go index e0924459..77fffefd 100644 --- a/internal/pkg/alerts/alert.go +++ b/internal/pkg/alerts/alert.go @@ -33,6 +33,8 @@ func SendWebhookAlert(msg string) { if alert_sink == "slack" { sendSlackAlert(webhook_url, webhook_proxy, msg) + } else if alert_sink == "teams" { + sendTeamsAlert(webhook_url, webhook_proxy, msg) } else { msg = strings.Replace(msg, "*", "", -1) sendRawWebhookAlert(webhook_url, webhook_proxy, msg) @@ -73,6 +75,28 @@ func sendSlackAlert(webhookUrl string, proxy string, msg string) []error { return nil } +func sendTeamsAlert(webhookUrl string, proxy string, msg string) []error { + attachment := Attachment{ + Text: msg, + } + + request := gorequest.New().Proxy(proxy) + resp, _, err := request. + Post(webhookUrl). + RedirectPolicy(redirectPolicy). + Send(attachment). + End() + + if err != nil { + return err + } + if resp.StatusCode != 200 { + return []error{fmt.Errorf("error sending msg. status: %v", resp.Status)} + } + + return nil +} + // function to send alert to webhook service as text func sendRawWebhookAlert(webhookUrl string, proxy string, msg string) []error { request := gorequest.New().Proxy(proxy)