Getting Nagios to do SMS Notifications
A couple of weeks ago I discovered that I wasn’t getting any notifications from Nagios. Turned out there was a problem with Postfix running on my server, which meant that mails weren’t delivered only queued. Since I only use emails as notification mechanism in Nagios it was pretty obvious that I was never gonna know about it. So something had to be done.
I’ve also had a plan to include SMS (text notification using mobile phones) as a notification method, but I never got around to configuring it. Know I had a pretty good reason to get it going. So I’ve spend a couple of hours today getting it done. I’ll explain how I got it working in this post.
First I needed a way to send SMS messages. The easiest way is to get a provider that allows you to interface via HTTP. This allows you to do a simple HTTP GET or POST and thereby send a message. I found these guys CPSMS. They have an HTTP gateway, and are pretty cheap. No setup fee, no monhtly fee, totally pay as you go. You buy messges in portions. Minimum is 1000 which yields a cost of 0,30 DKR per message.
Second I needed a script that nagios could execute. I found this on NagiosExchange and modified it. It’s pretty easy, you just replace the line that executes curl with this:
`curl -s -d username=$username -d password=$password -d from=$sender -d recipient=$number -d message="$message" -k https://www.cpsms.dk/sms/`
Third configure Nagios to use this new command. I used this blog post from Barry O’Donnovan. Very easy. I modified the templates a bit. In misccommands.cfg I used:
# 'host-notify-by-sms' command definitiondefine command{
command_name host-notify-by-sms
command_line /root/bin/notify_sms -n $CONTACTPAGER$
-m "$HOSTNAME$ is $HOSTSTATE$: $HOSTOUTPUT$"
}#'notify-by-sms' command definition
define command{
command_name notify-by-sms
command_line /root/bin/notify_sms $CONTACTPAGER$
-m "$NOTIFICATIONTYPE$: $SERVICEDESC$@$HOSTNAME$: $SERVICESTATE$ ($SERVICEOUTPUT$)"
}
I added a new contact in contacts for me with my mobile phone number. Primarily I did this to control the level of notifications I want to receive. I have a normal email contact for me that delivers all notifications, and my new mobile phone contact only receives critical and recovery notifications.
A quick Nagios reload and you’re laughing. Now I’m just hoping I won’t be flooding my phone with messages
And I better go buy some more messages at CPSMS to be on the safe side. Their 10 free demo messages probably won’t last for long.
Leave a Reply
You must be logged in to post a comment.
I work for 

