Skip to content

Commit 330e69f

Browse files
author
Damian Slowinski
committed
add Microsoft Teams webhook support
1 parent 306a988 commit 330e69f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

internal/pkg/alerts/alert.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func SendWebhookAlert(msg string) {
3333

3434
if alert_sink == "slack" {
3535
sendSlackAlert(webhook_url, webhook_proxy, msg)
36+
} else if alert_sink == "teams" {
37+
sendTeamsAlert(webhook_url, webhook_proxy, msg)
3638
} else {
3739
msg = strings.Replace(msg, "*", "", -1)
3840
sendRawWebhookAlert(webhook_url, webhook_proxy, msg)
@@ -73,6 +75,28 @@ func sendSlackAlert(webhookUrl string, proxy string, msg string) []error {
7375
return nil
7476
}
7577

78+
func sendTeamsAlert(webhookUrl string, proxy string, msg string) []error {
79+
attachment := Attachment{
80+
Text: msg,
81+
}
82+
83+
request := gorequest.New().Proxy(proxy)
84+
resp, _, err := request.
85+
Post(webhookUrl).
86+
RedirectPolicy(redirectPolicy).
87+
Send(attachment).
88+
End()
89+
90+
if err != nil {
91+
return err
92+
}
93+
if resp.StatusCode != 200 {
94+
return []error{fmt.Errorf("error sending msg. status: %v", resp.Status)}
95+
}
96+
97+
return nil
98+
}
99+
76100
// function to send alert to webhook service as text
77101
func sendRawWebhookAlert(webhookUrl string, proxy string, msg string) []error {
78102
request := gorequest.New().Proxy(proxy)

0 commit comments

Comments
 (0)