From 330e69f41733a4bc3c5ec92ec1aada000725cc63 Mon Sep 17 00:00:00 2001 From: Damian Slowinski Date: Tue, 6 Jun 2023 15:31:54 +0200 Subject: [PATCH 1/3] 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) From daccf7e0508aec780291a4da2cba21649cdabba5 Mon Sep 17 00:00:00 2001 From: Damian Slowinski Date: Tue, 6 Jun 2023 15:55:01 +0200 Subject: [PATCH 2/3] add Microsoft Teams webhook support --- internal/pkg/alerts/alert.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/pkg/alerts/alert.go b/internal/pkg/alerts/alert.go index 77fffefd..43b4c067 100644 --- a/internal/pkg/alerts/alert.go +++ b/internal/pkg/alerts/alert.go @@ -75,6 +75,7 @@ func sendSlackAlert(webhookUrl string, proxy string, msg string) []error { return nil } +// function to send alert to Microsoft Teams webhook func sendTeamsAlert(webhookUrl string, proxy string, msg string) []error { attachment := Attachment{ Text: msg, From 78995cf451a3fbfe3e65b52713f1992524f02794 Mon Sep 17 00:00:00 2001 From: Damian Slowinski Date: Tue, 6 Jun 2023 16:15:39 +0200 Subject: [PATCH 3/3] update Readme --- docs/Alerting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Alerting.md b/docs/Alerting.md index f9ed7b64..c3d79087 100644 --- a/docs/Alerting.md +++ b/docs/Alerting.md @@ -4,7 +4,7 @@ Reloader can alert when it triggers a rolling upgrade on Deployments or Stateful #### Enabling the feature In-order to enable this feature, you need to update the reloader.env.secret section of values.yaml providing the information needed for alert.
      ALERT_ON_RELOAD: [ true/false ] Default: false 
-      ALERT_SINK: [ slack/webhook ] Default: webhook
+      ALERT_SINK: [ slack/teams/webhook ] Default: webhook
       ALERT_WEBHOOK_URL: Required if ALERT_ON_RELOAD is true
       ALERT_ADDITIONAL_INFO: Any additional information to be added to alert