Nagios Notifications via SMS

Due to the possibility of either our exchange server becoming unavailable, or worse yet, something go wrong in the “core” of our network; it was decided that an alternate method of notifications needed to be setup.  SMS was the best option as it would be independent of the network and email.

I chose a tool called Gnokii and paired it with an older T-Mobile Motorola Razr connected to the Ubuntu server with a USB cable.  The first step was installing Gnokii:

sudo apt-get install gnokii

Configuring Gnokii took a little playing with, and it most likely will in your case.  Various options depend on which phone your using.  Open the ~/.gnokiirc and do the following: NOTE: file is truncated to show what values were changed.

[global]
# Set port to the physical port used to connect to your phone.

# Linux version is:

port = /dev/ttyS0
#
.....
# For the Linux USB cables you will need one of the following settings (or
# similiar)
# port = /dev/ttyUSB0
# port = /dev/tts/USB0
 port = /dev/ttyACM0
# the last one will work only with AT driver. The correct setting should be
# given in the dmesg output.
#
.....
# Set model to the model number of your ph ne. For the
# Symbian phones use:
# model = symbian
#nux USB cables you will need one of the following settings (or
# similiar)
# port = /dev/ttyUSB0
# port = /dev/tts/USB0
 port = /dev/ttyACM0
# the last one will work only with AT driver. The correct setting should be
# given in the dmesg output.
#
# For other non-Nokia phones and when you want to use AT
# mode use:
 model = AT
# If you can't figure out what to put here read the FAQ.
# If it still doesn't help, consult gnokii-ml or #gnokii at freenode.
#model = 6510
# There are few main models that should make use of the certain drivers.
# These are: 6110, 7110, 6510, 3110, 2110, 6160.

At this point, with the phone plugged in, you should be able to test message:

echo “Hello world!” | gnokii –sendsms +1541555555 -r

If you can successfully send a SMS message, copy the working .gnokiirc file to /etc/gnokiirc:

cp ~/.gnokiirc /etc/gnokiirc

Next, setting up Nagios to send notifications is pretty straight forward.  First things first, add the nagios user to the group that has access to the /dev/ttyS0 and /dev/ttyACM0 devices.

usermod -a -G dialout nagios

Setup the commands respectively (sorry about the poor text wrapping):

define command {
                command_name                          notify-service-by-sms
                command_line                          /usr/bin/printf
          "%.120s" "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ -
          $SERVICEOUTPUT$" | /usr/bin/gnokii --sendsms $CONTACTPAGER$
}

Make sure the contacts have a cell phone number in their pager option and add the notify-service-by-sms and notify-host-by-sms commands to the host_notification_commands and service_notification_commands options.

define contact {
                contact_name                          corypratt
                alias                                 Cory Pratt
                host_notification_options             d,u,r,f
                service_notification_options          w,u,c,r,f
                email                                 corypratt@emailmehere.com
                pager                                 15415555555
                host_notification_period              24x7
                service_notification_period           24x7
                host_notification_commands            notify-host-by-email
                service_notification_commands         notify-service-by-email,
                                              notify-service-by-sms
}

Wow. It's Quiet Here...

Be the first to start the conversation!

Leave a Reply:

Gravatar Image

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>