mirror of
https://github.com/TwiN/gatus.git
synced 2025-06-27 13:11:48 +02:00
fix(alerting): Support Twilio overrides for text-twilio-triggered
and text-twilio-resolved
(#1120)
* Make twilio alert provider translatable * Update alerting/provider/twilio/twilio.go --------- Co-authored-by: Imre Laszlo <imre.laszlo@matrixonline.hu> Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
parent
04692d15ba
commit
d9d5815488
@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/TwiN/gatus/v5/alerting/alert"
|
||||
"github.com/TwiN/gatus/v5/client"
|
||||
@ -27,6 +28,9 @@ type Config struct {
|
||||
Token string `yaml:"token"`
|
||||
From string `yaml:"from"`
|
||||
To string `yaml:"to"`
|
||||
|
||||
TextTwilioTriggered string `yaml:"text-twilio-triggered,omitempty"` // String used in the SMS body and subject (optional)
|
||||
TextTwilioResolved string `yaml:"text-twilio-resolved,omitempty"` // String used in the SMS body and subject (optional)
|
||||
}
|
||||
|
||||
func (cfg *Config) Validate() error {
|
||||
@ -58,6 +62,12 @@ func (cfg *Config) Merge(override *Config) {
|
||||
if len(override.To) > 0 {
|
||||
cfg.To = override.To
|
||||
}
|
||||
if len(override.TextTwilioTriggered) > 0 {
|
||||
cfg.TextTwilioTriggered = override.TextTwilioTriggered
|
||||
}
|
||||
if len(override.TextTwilioResolved) > 0 {
|
||||
cfg.TextTwilioResolved = override.TextTwilioResolved
|
||||
}
|
||||
}
|
||||
|
||||
// AlertProvider is the configuration necessary for sending an alert using Twilio
|
||||
@ -102,10 +112,18 @@ func (provider *AlertProvider) Send(ep *endpoint.Endpoint, alert *alert.Alert, r
|
||||
func (provider *AlertProvider) buildRequestBody(cfg *Config, ep *endpoint.Endpoint, alert *alert.Alert, result *endpoint.Result, resolved bool) string {
|
||||
var message string
|
||||
if resolved {
|
||||
if len(cfg.TextTwilioResolved) > 0 {
|
||||
message = strings.Replace(strings.Replace(cfg.TextTwilioResolved, "{endpoint}", ep.DisplayName(), 1), "{description}", alert.GetDescription(), 1)
|
||||
} else {
|
||||
message = fmt.Sprintf("RESOLVED: %s - %s", ep.DisplayName(), alert.GetDescription())
|
||||
}
|
||||
} else {
|
||||
if len(cfg.TextTwilioTriggered) > 0 {
|
||||
message = strings.Replace(strings.Replace(cfg.TextTwilioTriggered, "{endpoint}", ep.DisplayName(), 1), "{description}", alert.GetDescription(), 1)
|
||||
} else {
|
||||
message = fmt.Sprintf("TRIGGERED: %s - %s", ep.DisplayName(), alert.GetDescription())
|
||||
}
|
||||
}
|
||||
return url.Values{
|
||||
"To": {cfg.To},
|
||||
"From": {cfg.From},
|
||||
|
Loading…
x
Reference in New Issue
Block a user