SMS notification commands


#1

Hi, I need to be able to send notifications via SMS in the event that the email servers are unavailable, or the internet connection is down. There is a server on the same network as the Nagios host that has a modem installed and uses SMS Tools 3 to send messages. To send a message all I need to do is place a file in a certain directory on that server, in a simple format, and it does the rest.

So, I created a script called ‘notify-by-sms’ in /usr/local/nagios/libexec which is as follows:

TMPFILE=mktemp notify.XXXXXX
echo -e $1 > $TMPFILE
scp $TMPFILE sms-server:/var/spool/sms/outgoing/
rm $TMPFILE

The script is owned by the user nagios and is executable. To run it I just need to pass it a string like “To: \n\n” as the only parameter. If I run it from the command line while logged in as nagios it works fine.

I have the following in commands.cfg which I adapted from notify-service-by-email and notify-host-by-email:

‘notify-host-by-sms’ command definition

define command{
command_name notify-host-by-sms
command_line /usr/local/nagios/libexec/notify-by-sms “To: $CONTACTPAG
ER$\n\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTN
AME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Tim
e: $LONGDATETIME$\n”
}

‘notify-service-by-sms’ command definition

define command{
command_name notify-service-by-sms
command_line /usr/local/nagios/libexec/notify-by-sms “To: $CONTACTPAG
ER$\n\n***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $
SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n
\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$”

    }

The ‘command_line’ is all on one line.

I see the following in /usr/local/nagios/var/nagios.log, as an example (I have replaced some things with <…>):

[1196327641] SERVICE NOTIFICATION: ;;SyncServer;CRITICAL;notify-service-by-sms;CRITICAL - Error Fetching ](http://)/sync/ds [503] Service Temporarily Unavailable

however the sms is not received. It does not even appear in the log on the SMS server which indicates the script isn’t running or isn’t able to scp the file to that server. I am using public key authentication to negate the need for a SSH password to be entered.

Any ideas what the problem could be, when it runs manually from the command line but not through the nagios daemon?

Thank you,
Nick