Updated alert manager handling
Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
parent
caea01d66a
commit
6c345c8aff
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
tTemplate "text/template"
|
tTemplate "text/template"
|
||||||
|
|
||||||
@ -21,8 +22,12 @@ func HandleAlertmanagerPayloadPost(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Got alertmanager payload")
|
fmt.Println("Got alertmanager payload")
|
||||||
|
fmt.Printf("%d alerts recieved\n", len(payload.Alerts))
|
||||||
|
|
||||||
for _, alert := range payload.Alerts {
|
for _, alert := range payload.Alerts {
|
||||||
|
s, _ := json.MarshalIndent(alert, "", "\t")
|
||||||
|
fmt.Println(string(s))
|
||||||
|
|
||||||
message := ""
|
message := ""
|
||||||
|
|
||||||
var rendered bytes.Buffer
|
var rendered bytes.Buffer
|
||||||
@ -34,12 +39,20 @@ func HandleAlertmanagerPayloadPost(c *fiber.Ctx) error {
|
|||||||
case "warning":
|
case "warning":
|
||||||
message = fmt.Sprintf("⚠️ %s", rendered.String())
|
message = fmt.Sprintf("⚠️ %s", rendered.String())
|
||||||
case "notify":
|
case "notify":
|
||||||
message = fmt.Sprintf("🔥 @room - %s", rendered.String())
|
message = fmt.Sprintf("@room - %s", rendered.String())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message = fmt.Sprintf("✅ %s", rendered.String())
|
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(
|
_, err := matrixClient.SendMessageEvent(
|
||||||
id.RoomID(getRoom(c.Query("room", *defaultRoom))),
|
id.RoomID(getRoom(c.Query("room", *defaultRoom))),
|
||||||
event.EventMessage,
|
event.EventMessage,
|
||||||
|
Loading…
Reference in New Issue
Block a user