mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-24 17:04:42 +01:00
fix(alerting): Improve ntfy alert
This commit is contained in:
parent
bcb565ba37
commit
080563bd4f
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/TwiN/gatus/v4/alerting/alert"
|
"github.com/TwiN/gatus/v4/alerting/alert"
|
||||||
"github.com/TwiN/gatus/v4/client"
|
"github.com/TwiN/gatus/v4/client"
|
||||||
@ -69,19 +70,19 @@ type Body struct {
|
|||||||
// buildRequestBody builds the request body for the provider
|
// buildRequestBody builds the request body for the provider
|
||||||
func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *alert.Alert, result *core.Result, resolved bool) []byte {
|
func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *alert.Alert, result *core.Result, resolved bool) []byte {
|
||||||
var message, tag string
|
var message, tag string
|
||||||
if len(alert.GetDescription()) > 0 {
|
|
||||||
message = endpoint.DisplayName() + " - " + alert.GetDescription()
|
|
||||||
} else {
|
|
||||||
message = endpoint.DisplayName()
|
|
||||||
}
|
|
||||||
if resolved {
|
if resolved {
|
||||||
tag = "white_check_mark"
|
tag = "white_check_mark"
|
||||||
|
message = "An alert has been resolved after passing successfully " + strconv.Itoa(alert.SuccessThreshold) + " time(s) in a row"
|
||||||
} else {
|
} else {
|
||||||
tag = "x"
|
tag = "x"
|
||||||
|
message = "An alert has been triggered due to having failed " + strconv.Itoa(alert.FailureThreshold) + " time(s) in a row"
|
||||||
|
}
|
||||||
|
if len(alert.GetDescription()) > 0 {
|
||||||
|
message += " with the following description: " + alert.GetDescription()
|
||||||
}
|
}
|
||||||
body, _ := json.Marshal(Body{
|
body, _ := json.Marshal(Body{
|
||||||
Topic: provider.Topic,
|
Topic: provider.Topic,
|
||||||
Title: "Gatus",
|
Title: "Gatus: " + endpoint.DisplayName(),
|
||||||
Message: message,
|
Message: message,
|
||||||
Tags: []string{tag},
|
Tags: []string{tag},
|
||||||
Priority: provider.Priority,
|
Priority: provider.Priority,
|
||||||
|
Loading…
Reference in New Issue
Block a user