diff --git a/docs/Alerting.md b/docs/Alerting.md index 3b411121..1477e498 100644 --- a/docs/Alerting.md +++ b/docs/Alerting.md @@ -1,5 +1,6 @@ # Alerting on Reload + Reloader can alert when it triggers a rolling upgrade on Deployments or StatefulSets. Webhook notification alert would be sent to the configured webhook server with all the required information. ## Enabling the feature @@ -8,7 +9,7 @@ In-order to enable this feature, you need to update the `reloader.env.secret` se ```yaml 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 ``` diff --git a/internal/pkg/alerts/alert.go b/internal/pkg/alerts/alert.go index e0924459..43b4c067 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,29 @@ 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, + } + + 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)