diff --git a/alerting/provider/twilio/twilio.go b/alerting/provider/twilio/twilio.go index 544397fb..ccb83770 100644 --- a/alerting/provider/twilio/twilio.go +++ b/alerting/provider/twilio/twilio.go @@ -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,9 +112,17 @@ 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 { - message = fmt.Sprintf("RESOLVED: %s - %s", ep.DisplayName(), alert.GetDescription()) + 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 { - message = fmt.Sprintf("TRIGGERED: %s - %s", ep.DisplayName(), alert.GetDescription()) + 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},