Swatto / promtotwilio

Send text messages for Prometheus alerts using Twilio
MIT License
33 stars 21 forks source link

Sending to multiple numbers? #2

Closed valexandersaulys closed 6 years ago

valexandersaulys commented 6 years ago

Is there any reason this can't be set up to send to multiple numbers?

Curious if it would be a simple thing or require some source code edits.

Thanks in advance!

Swatto commented 6 years ago

Sorry for the late answer. It would require some source code edits.

bilalunalnet commented 1 year ago

If anyone needs something similar, you can achieve it buy updating options_with_handler.go file like this;

diff --git a/options_with_handler.go b/options_with_handler.go
index 3225beb..6454dcc 100644
--- a/options_with_handler.go
+++ b/options_with_handler.go
@@ -89,12 +89,14 @@ func sendMessage(o *options, alert []byte) {
                if err == nil {
                        body = "\"" + body + "\"" + " alert starts at " + parsedStartsAt.Format(time.RFC1123)
                }
-
-               message, err := twilio.NewMessage(c, o.Sender, o.Receiver, twilio.Body(body))
-               if err != nil {
-                       log.Error(err)
-               } else {
-                       log.Infof("Message %s", message.Status)
+               receivers := strings.Split(o.Receiver, ",")
+               for _, receiver := range receivers {
+                       message, err := twilio.NewMessage(c, o.Sender, receiver, twilio.Body(body))
+                       if err != nil {
+                               log.Error(err)
+                       } else {
+                               log.Infof("Message %s", message.Status)
+                       }
                }
        } else {
                log.Error("Bad format")