2

I want nagios to send sms message by twilio to more than one [person].

How can I do this?

I have used this code but it sends the sms to only one phone number:

define command {
        command_name    notify-by-page
        command_line    curl --data-urlencode "From=YOURTWILIONUMBER" --data-urlencode "To=YOURCELL" --data-urlencode "Body=[Nagios] $NOTIFICATIONTYPE$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" https://SID:TOKEN@api.twilio.com/2010-04-01/Accounts/SID/SMS/Messages >> /tmp/sms
}
define command {
        command_name    host-notify-by-page
        command_line    curl --data-urlencode "From=YOURTWILIONUMBER" --data-urlencode "To=YOURCELL" --data-urlencode "Body=[Nagios] $HOSTSTATE$ alert for $HOSTNAME$" https://SID:TOKEN@api.twilio.com/2010-04-01/Accounts/SID/SMS/Messages >> /tmp/sms
}
maxshuty
  • 9,708
  • 13
  • 64
  • 77

1 Answers1

3

You'll have to make a separate POST request to the Twilio API for each phone number you want to send an SMS to. In this case, I would write a Bash script to send all the messages and then have nagios call that Bash script.

Here's an example script:

#!/bin/bash
curl --data-urlencode "From=YOURTWILIONUMBER" --data-urlencode "To=YOURCELL" --data-urlencode "Body=${1}" https://SID:TOKEN@api.twilio.com/2010-04-01/Accounts/SID/SMS/Messages >> /tmp/sms
curl --data-urlencode "From=YOURTWILIONUMBER" --data-urlencode "To=ANOTHERCELL" --data-urlencode "Body=${1}" https://SID:TOKEN@api.twilio.com/2010-04-01/Accounts/SID/SMS/Messages >> /tmp/sms

You'll notice I'm accepting the body as the message as the first argument of the script. Then your nagios config would look like this:

define command {
        command_name    notify-by-page
        command_line    /path/to/script.sh "[Nagios] $NOTIFICATIONTYPE$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"
}
define command {
        command_name    host-notify-by-page
        command_line    /path/to/script.sh "[Nagios] $HOSTSTATE$ alert for $HOSTNAME$"
}

Disclaimer: I work for Twilio.

rickyrobinett
  • 1,224
  • 10
  • 13