Skip to content

Commit

Permalink
Merge pull request #473 from damslo/feature/ms-teams-webhook
Browse files Browse the repository at this point in the history
Add MS Teams support for alerting webhook
  • Loading branch information
MuneebAijaz committed Dec 27, 2023
2 parents f83959f + 18bc739 commit f67e5fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/Alerting.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
```
Expand Down
25 changes: 25 additions & 0 deletions internal/pkg/alerts/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f67e5fb

Please sign in to comment.