A bunch more work, potentially working, but need to deploy to test
--- a/Dockerfile Sun May 12 05:00:08 2019 -0500
+++ b/Dockerfile Tue May 14 21:38:27 2019 -0500
@@ -1,4 +1,4 @@
-FROM golang:stretch as build
+FROM golang:stretch AS build @@ -11,4 +11,3 @@
COPY --from=build /app/carrier /carrier
--- a/config/config.go Sun May 12 05:00:08 2019 -0500
+++ b/config/config.go Tue May 14 21:38:27 2019 -0500
@@ -9,8 +9,11 @@
UptimeRobotToken string `envconfig:"UPTIME_ROBOT_TOKEN" required:"true"`
- TwilioAccountSID string `envconfig:"TWILIO_ACCOUNT_SID" required:"true"`
- TwilioAuthToken string `envconfig:"TWILIO_AUTH_TOKEN" required:"true"`
+ TwilioWebhookToken string `envconfig:"TWILIO_WEBHOOK_TOKEN" required:"true"` + TwilioAccountSID string `envconfig:"TWILIO_ACCOUNT_SID" required:"true"` + TwilioAuthToken string `envconfig:"TWILIO_AUTH_TOKEN" required:"true"` + TwilioPhoneNumber string `envconfig:"TWILIO_PHONE_NUMBER" required:"true"` + TwilioRecipient string `envconfig:"TWILIO_RECIPIENT" required:"true"` --- a/go.mod Sun May 12 05:00:08 2019 -0500
+++ b/go.mod Tue May 14 21:38:27 2019 -0500
@@ -1,6 +1,7 @@
module bitbucket.org/pidgin/carrier
+ bitbucket.org/ckvist/twilio v0.0.0-20170512072134-13c593a1721b github.com/kelseyhightower/envconfig v1.3.0
github.com/sirupsen/logrus v1.4.1
--- a/go.sum Sun May 12 05:00:08 2019 -0500
+++ b/go.sum Tue May 14 21:38:27 2019 -0500
@@ -1,3 +1,5 @@
+bitbucket.org/ckvist/twilio v0.0.0-20170512072134-13c593a1721b h1:EgVTZyg+IROzDLG86gbfoLk4k6nwypmTHmjXDgYMzD4= +bitbucket.org/ckvist/twilio v0.0.0-20170512072134-13c593a1721b/go.mod h1:tZckALWIGoGfdoe/aKzxBL5qViz4qXogqZx1UViXWME= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kelseyhightower/envconfig v1.3.0 h1:IvRS4f2VcIQy6j4ORGIf9145T/AsUB+oY8LyvN8BXNM=
github.com/kelseyhightower/envconfig v1.3.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
--- a/server/server.go Sun May 12 05:00:08 2019 -0500
+++ b/server/server.go Tue May 14 21:38:27 2019 -0500
@@ -4,6 +4,8 @@
log "github.com/sirupsen/logrus"
+ "bitbucket.org/pidgin/carrier/uptimerobot" @@ -32,7 +34,7 @@
mux := http.NewServeMux()
mux.HandleFunc("/healthz", healthzHandler)
- mux.HandleFunc("/uptime-robot", uptimeRobotHandler)
+ mux.HandleFunc("/uptime-robot", uptimerobot.Handler) --- a/server/uptimerobot.go Sun May 12 05:00:08 2019 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-// monitorID=*monitorID*&monitorURL=*monitorURL*&monitorFriendlyName=*monitorFriendlyName*&alertType=*alertType*&alertTypeFriendlyName=*alertTypeFriendlyName*&alertDetails=*alertDetails*&alertDuration=*alertDuration*&monitorAlertContacts=*monitorAlertContacts*
-func uptimeRobotHandler(w http.ResponseWriter, r *http.Request) {
- if r.Method != http.MethodPost {
- w.WriteHeader(http.StatusMethodNotAllowed)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/uptimerobot/uptimerobot.go Tue May 14 21:38:27 2019 -0500
@@ -0,0 +1,83 @@
+ "bitbucket.org/ckvist/twilio/twirest" + "bitbucket.org/pidgin/carrier/config" + client *twirest.TwilioClient +func validate(r *http.Request) int { + if r.Method != http.MethodPost { + return http.StatusMethodNotAllowed + return http.StatusBadRequest + // check that we have a token + tokens, found := r.Form["token"] + if !found || len(tokens) == 0 { + return http.StatusBadRequest + // verify the first token + if tokens[0] != cfg.TwilioWebhookToken { + return http.StatusBadRequest +func sendSMS(content string) (twirest.TwilioResponse, error) { + client = twirest.NewClient(cfg.TwilioAccountSID, cfg.TwilioAuthToken) + msg := twirest.SendMessage{ + To: cfg.TwilioRecipient, + From: cfg.TwilioPhoneNumber, + return client.Request(msg) +func Handler(w http.ResponseWriter, r *http.Request) { + // validate that the request has everything we need/want + if status := validate(r); status != 0 { + // build the content of our sms + content := fmt.Sprintf( + r.PostForm["monitorFriendlyName"][0], + r.PostForm["alertTypeFriendlyName"][0], + resp, err := sendSMS(content) + w.WriteHeader(resp.Status.Http) + fmt.Fprintf(w, "%s", err) + w.WriteHeader(http.StatusOK) + fmt.Fprintf(w, "%s", resp.Status)