Updated alert manager handling

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2021-12-24 14:15:39 +00:00
parent caea01d66a
commit 6c345c8aff
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78

View File

@ -2,6 +2,7 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
tTemplate "text/template"
@ -21,8 +22,12 @@ func HandleAlertmanagerPayloadPost(c *fiber.Ctx) error {
}
fmt.Println("Got alertmanager payload")
fmt.Printf("%d alerts recieved\n", len(payload.Alerts))
for _, alert := range payload.Alerts {
s, _ := json.MarshalIndent(alert, "", "\t")
fmt.Println(string(s))
message := ""
var rendered bytes.Buffer
@ -34,12 +39,20 @@ func HandleAlertmanagerPayloadPost(c *fiber.Ctx) error {
case "warning":
message = fmt.Sprintf("⚠️ %s", rendered.String())
case "notify":
message = fmt.Sprintf("🔥 @room - %s", rendered.String())
message = fmt.Sprintf("@room - %s", rendered.String())
}
} else {
message = fmt.Sprintf("✅ %s", rendered.String())
}
if serviceURL, ok := alert.Annotations["service_url"]; ok {
message += "<br>Service URL: " + serviceURL
}
if alert.GeneratorURL != "" {
message += "<br>URL: " + alert.GeneratorURL
}
_, err := matrixClient.SendMessageEvent(
id.RoomID(getRoom(c.Query("room", *defaultRoom))),
event.EventMessage,