add Microsoft Teams webhook support

This commit is contained in:
Damian Slowinski
2023-06-06 15:31:54 +02:00
parent 306a988ace
commit 330e69f417
+24
View File
@@ -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)