Render template
Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
parent
2a79d08e71
commit
eaba72fb23
@ -1,7 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
tTemplate "text/template"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/prometheus/alertmanager/template"
|
"github.com/prometheus/alertmanager/template"
|
||||||
@ -20,15 +22,20 @@ func HandleAlertmanagerPayloadPost(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
for _, alert := range payload.Alerts {
|
for _, alert := range payload.Alerts {
|
||||||
message := ""
|
message := ""
|
||||||
|
|
||||||
|
var rendered bytes.Buffer
|
||||||
|
at, _ := tTemplate.New("AlertMessage").Parse(alert.Annotations["description"])
|
||||||
|
at.Execute(&rendered, alert)
|
||||||
|
|
||||||
if alert.Status == "firing" {
|
if alert.Status == "firing" {
|
||||||
switch alert.Labels["severity"] {
|
switch alert.Labels["severity"] {
|
||||||
case "warning":
|
case "warning":
|
||||||
message = fmt.Sprintf("⚠️ %s", alert.Annotations["description"])
|
message = fmt.Sprintf("⚠️ %s", rendered.String())
|
||||||
case "notify":
|
case "notify":
|
||||||
message = fmt.Sprintf("@room - %s", alert.Annotations["description"])
|
message = fmt.Sprintf("@room - %s", rendered.String())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message = fmt.Sprintf("☑️ %s", alert.Annotations["description"])
|
message = fmt.Sprintf("☑️ %s", rendered.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := matrixClient.SendText(id.RoomID(getRoom(*defaultRoom)), message)
|
_, err := matrixClient.SendText(id.RoomID(getRoom(*defaultRoom)), message)
|
||||||
|
Loading…
Reference in New Issue
Block a user