Andrews and Arnold sells me a VOIP service which also lets me send SMSes over HTTP.
I wanted to make Nagios send out notifications this way, in addition to the existing email-based notification.
First I need a Nagios command definition to send out the notifications:
define command {
command_name cqx-notify-service-by-sms
command_line /var/cqxmon/secret-aa-curl 0781234567 "$NOTIFICATIONTYPE$: $HOSTALIAS$/$SERVICEDISPLAYNAME$ is $SERVICESTATE$"
}
That will invoke my sender script to send a message to phone number 0781234567.
Then we need the sender script. It has my password hardcoded in it (ick! but that could be replaced with a < redirect).
#!/bin/bash
# DO NOT COMMIT THIS TO VERSION CONTROl!
TARGET=$1
shift
TMPFILE=$(mktemp)
echo $@ > $TMPFILE
curl --get --form-string username=0300300300 \
--form-string password=XYZ123 --form-string destination=$TARGET \
--form message=\<$TMPFILE \
http://sms.aa.net.uk/sms.cgi
rm $TMPFILE
The redirect via TMPFILE is because I was having trouble with spaces on the commandline that I couldn't seem to escape around.
Then I need to modify the Nagios contact definition for myself to call the cqx-notify-service-by-sms command in addition to the regular email notifier. In the contact definition for myself:
service_notification_commands cqx-notify-service-by-email, cqx-notify-service-by-smsThat will work for services. For hosts, you'll have to create a cqx-notify-host-by-sms command which does something similar, and add that to the contact notification_commands.
Nagios has a number of other contact fields that could be used to allow the target number to be configured per contact. I'll get round to that at some point; without making those changes, the above will only let you notify a single SMS number.
No comments:
Post a Comment