In my last article I have discuses how to
install Gnokii for sending/receiving SMS from your computer. Today I'll explain how we are using Gnokii + Nagios for sending SMS notifications to our cell phones. Its a great way to get notify of the problems while on road.
I assume that you have working Nagios and its monitoring the devices in your infrastructure and sending notifications via Email and you are looking how to get these problem notifications on your phones.
Gnokii is also working and you can send SMS from CLI.
Lets cut it short and back to actual business.
In my setup we have Nagios and Gnokii install on same host running Centos 5.4, but it can easily be followed for any other Linux distro or even with setup where Gnokii is install on separate host.
1. Make sure you can send SMS from CLI with "gnokii --sendsms +92xxxxx" using root or the user under which Nagios process is running normally its 'nagios' user, sending under nagios user requires to add nagios to groups which have permission to access the device files.
a) So add nagios to 'uucp' group (you can do this with usermod command)
Gnokii also acquire a lock under /var/lock
b) So add nagios user to 'lock' group also.
su to nagios user and send sms from CLI using gnokii --sendsms, when it works move forward for defining commands.
2. Define command for send notification via SMS in commands.cfg
# 'notify-service-by-sms' command definition
define command{
command_name notify-service-by-sms
command_line /usr/bin/printf "%.120s" "*** Nagios Alert*** $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" | /usr/local/bin/gnokii --sendsms $CONTACTPAGER$
}
# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/bin/printf "%.120s" "*** Nagios Alert*** $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$" | /usr/local/bin/gnokii --sendsms $CONTACTPAGER$
}
3. Modify contacts.cfg and add or modify a contact by calling new commands
define contact{
contact_name askarali
use generic-contact
alias Askar Ali Khan
email emailaddress
pager +92xxxxxx
service_notification_commands notify-service-by-email,notify-service-by-sms
host_notification_commands notify-host-by-email,notify-host-by-sms
}
The key in the contact detail is the service/host notifications commands
service_notification_commands notify-service-by-email,notify-service-by-sms
host_notification_commands notify-host-by-email,notify-host-by-sms
I have configured a contact so that he can receive notifications via Email 'notify-service-by-email' as well as via SMS 'notify-service-by-sms'
That's all, finally reload nagios, before reload better to run syntax check
'nagios -v PathTo nagios.cfg'
and then reload
/etc/init.d/nagios reload
Now Nagios will send SMS notifications on your phone whenever there is problem with any host/service which being monitor with Nagios.
I hope this could help.