Nagios Alert via SMS


In our previous post, we have seen how to configure sms gateway server on your environment. With the help of the sms gateway server, we can able to receive the nagios alert. Please follow the below steps.

Assumption:

– Nagios server and clients are configured and running
– Mobile tethering is enabled and support unlimited SMS
– Ozeki NG SMS gateway server is running

All above three assumptions have been explained in this blog previously. Kindly do visit and start monitoring your infrastructure efficiently.

Step 1: Install SMS plugin in nagios server

[root@server.local ~]# vi /usr/local/nagios/libexec/nagios_sms.sh

Copy and paste the below lines

#!/bin/bash
url1="http://127.0.0.1:9501/api?action=sendmessage&username=admin&password= abc123&recipient=0123456789&messagetype=SMS:TEXT&messagedata="
url2="$@"
url2+=$(php -r "echo rawurlencode('$(sed "s/'/\\\\'/g" <<< )');")
url=$url1+$url2
wget -O- "$url"

where,

http://127.0.0.1:9501 — the computer Ozeki NG SMS Gateway has been installed
username=admin — username you use to log into Ozeki NG SMS Gateway
password=abc123 — password of the user
recipient=0123456789 — recipient’s phone number

Step 2: Define command for nagios sms plugin

[root@server.local ~]# vi /usr/local/nagios/etc/objects/commands.cfg

Copy and paste the below lines

# 'notify-service-by-sms' command definition
define command{
command_name notify-service-by-sms
command_line /usr/local/nagios/libexec/nagios_sms.sh "--Nagios Service Notification-- Host: $HOSTNAME$, State: $HOSTSTATE$ Service $SERVICEDESC$ Description: $SERVICESTATE$ Time: $LONGDATETIME$"

}

# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/local/nagios/libexec/nagios_sms.sh "--Nagios Host Notification-- Host: $HOSTNAME$, State: $HOSTSTATE$, Time: $LONGDATETIME$"
}

Save and Exit (:wq!)

Step 3: Define contacts

[root@server.local ~]# vi /usr/local/nagios/etc/objects/contacts.cfg

Copy and insert the below lines in nagiosadmin template

service_notification_commands notify-service-by-sms
host_notification_commands notify-host-by-sms

It looks like below changes;

define contact{
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
service_notification_commands notify-service-by-sms
host_notification_commands notify-host-by-sms
email nagios@localhost
}

Save and Exit (:wq!)

Step 4: Restart the nagios

[root@server.local ~]# /etc/init.d/nagios restart

That’s it.. Now nagios alerts are triggered to SMS gateway server and finally recipient start receiving alerts.

Cool šŸ™‚

SMS Gateway Server ā€“ Ozeki NG


== From Wiki ==

An SMS gateway allows a computer to send or receive Short Message Service (SMS) transmissions to or from a telecommunications network. Most messages are eventually routed into the mobile phone networks. Many SMS gateways support media conversion from email and other formats

Refer the previous post to configure your mobile as modem.

Step 1: Install prerequisites

[root@server ~]# yum -y update

[root@server ~]# yum -y install glib2-devel libpng-devel libjpeg-devel giflib-devel libtiff-devel libexif-devel libX11-devel fontconfig-devel gettext make gcc-c++

# build libgdiplus

[root@server ~]# wget http://download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.9.tar.bz2

[root@server ~]# bunzip2 libgdiplus-2.10.9.tar.bz2

[root@server ~]# tar -xzvf libgdiplus-2.10.9.tar

[root@server ~]# cd libgdiplus-2.10.9

[root@server libgdiplus]# ./configure --prefix=/usr/local

[root@server libgdiplus]# make

[root@server libgdiplus]# make install

# build mono

[root@server ~]# wget http://download.mono-project.com/sources/mono/mono-3.0.0.tar.bz2

[root@server ~]# bunzip2 mono-3.0.0.tar.bz2

[root@server ~]# tar -xzvf mono-3.0.0.tar

[root@server ~]# cd mono-3.0.0

[root@server mono-3.0.0]# ./configure --prefix=/usr/local

[root@server mono-3.0.0]# make

[root@server mono-3.0.0]# make install

Step 2: Download and install the Ozeki NG application package

[root@server ~]# cd /var/lib

[root@server ~]# wget http://ozekisms.com/attachments/524/OzekiNG_SMS_Gateway-3.15.6.tgz

[root@server ~]# tar -xzvf OzekiNG_SMS_Gateway-3.15.6.tgz

[root@server ~]# ln -s OzekiNG_SMS_Gateway-3.15.6 /var/lib/ozeking

Step 3: Test Ozeki NG

Check whether the Ozeki NG application is functioning properly. To do this you should issue the following commands:

[root@server ~]# cd OzekiNG_SMS_Gateway-3.15.6

[root@server OzekiNG_SMS_Gateway-3.15.6]# /usr/local/mono OzekiNG.exe /run

After above execution command, you can open the Ozeki NG configuration webpage by typing the following URL in your browser

http://127.0.0.1:9501/ or http://ip-address:9501/

Ozeki NG default password is admin / abc123

Step 4: Ozeki NG services

First you should copy the ozeking init script to your init.d directory. So that you can use this script to start and to stop the service

[root@server ~]# cp /var/lib/ozeking/distributions/Fedora/init.d/ozeking /etc/init.d/

To Start:

[root@server ~]# /etc/init.d/ozeking start

[root@server ~]# chkconfig --level 35 ozeking on

To Stop:

[root@server ~]# /etc/init.d/ozeking stop

How to use your mobile as modem


Tethering is connecting your phone to a laptop or similar data device using a data cable, usually for the purpose of connecting to the Internet on the laptop, via the phone’s wireless connection to the cell phone network.

Here Iā€™m going to use my Moto G mobile as modem for my laptop.

To use Moto G as modem, you need to first enable the USB tethering. To do this follow the below steps.

– Go to Settings

– Touch to More

– Go to Tethering & Mobile Hotspot

– Check the box for USB Tethering

If you enabled WiFi then USB tethering option will not be enabled.

Once the tethering is enabled, your mobile works as a modem to use internet from PC.

Nowadays Moto G Tethering works with popular linux distributions such as CentOS, Ubuntu etc.