mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-22 16:03:44 +01:00
36 lines
1013 B
Go
36 lines
1013 B
Go
package twilio
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
|
"net/url"
|
|
)
|
|
|
|
type AlertProvider struct {
|
|
SID string `yaml:"sid"`
|
|
Token string `yaml:"token"`
|
|
From string `yaml:"from"`
|
|
To string `yaml:"to"`
|
|
}
|
|
|
|
func (provider *AlertProvider) IsValid() bool {
|
|
return len(provider.Token) > 0 && len(provider.SID) > 0 && len(provider.From) > 0 && len(provider.To) > 0
|
|
}
|
|
|
|
func (provider *AlertProvider) ToCustomAlertProvider(message string) *custom.AlertProvider {
|
|
return &custom.AlertProvider{
|
|
Url: fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages.json", provider.SID),
|
|
Method: "POST",
|
|
Body: url.Values{
|
|
"To": {provider.To},
|
|
"From": {provider.From},
|
|
"Body": {message},
|
|
}.Encode(),
|
|
Headers: map[string]string{
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
"Authorization": fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", provider.SID, provider.Token)))),
|
|
},
|
|
}
|
|
}
|