nagios Red hat linux

Send Nagios SMS Alert with Gnokii

Installing Gnokii

Requirements – intltool-0.35.0-2.i386.rpm

tar -xzvf gnokii-0.6.28.tar.gz
cd gnokii-0.6.28
./configure
make 
make install

cp -Rdp /usr/share/doc/gnokii/sample/gnokiirc /root/.gnokiirc
or 
cp -Rdp /usr/share/doc/gnokii/sample/gnokiirc /etc/gnokiirc

configure Gnokii for Wavecom GSM modem

#vim /root/.gnokiirc

[global]
port = /dev/ttyS0
model = AT
initlength = default
connection = serial
use_locking = no
serial_baudrate = 9600
smsc_timeout = 10

[xgnokii]
allow_breakage = 0

[gnokiid]
bindir = /usr/local/sbin/

[connect_script]

TELEPHONE = 12345678

[disconnect_script]

[logging]
debug = on
rlpdebug = off
xdebug = off

[phone_fake]
port = foobar
model = fake
connection = serial

Check modem is properly configured

gnokii --identify

sending SMS

echo "This is a test message" | gnokii --sendsms +94715770488

Sending SMS from Nagios

###Copy ginokiirc file to the nagios home directory
cp -Rdp /root/.gnokiirc /home/nagios/.gnokiirc
###Give permission to ginokii for run as root user always
chmod 4755 /usr/local/bin/gnokii

Add commands to file

vim /usr/local/nagios/etc/commands.cfg
# 'notify-by-sms' command definition
define command{
        command_name    notify-service-by-sms
        command_line    /usr/bin/printf "%b" "SysAdmin Nagios  Alert: "$NOTIFICATIONTYPE$"  Host: "$HOSTALIAS$"  Service: "$SERVICEDESC$"  State: $SERVICESTATE$" | /usr/local/bin/gnokii --sendsms $CONTACTPAGER$ -r
        }

# 'host-notify-by-sms' command definition
        define command{
        command_name    notify-host-by-sms
        command_line    /usr/bin/printf "%b" "SysAdmin Internal Nagios  Alert: "$NOTIFICATIONTYPE$"  Host: "$HOSTALIAS$"  State: $HOSTSTATE$" | /usr/local/bin/gnokii --sendsms $CONTACTPAGER$ -r
        }

Edit contacts in localhost file

vim /usr/local/nagios/etc/localhost.cfg

define contact{
        contact_name                    nagios-admin
        alias                           Nagios Admin
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-email,notify-service-by-sms
        host_notification_commands      notify-host-by-email,notify-host-by-sms
        email                           prabath@sysadmin.lk
        pager                           0715770488
        }

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *