April 2012
« Mar   May »

Nagios : Enabling FREE SMS notification [INDIA]

Here I found some good trick to enable Nagios sms notification free for Indian users using one of the sms free service offered by way2sms website. have a look at

Most of the cases I used to take tiny pieces of information from different blog sites and customize and modify it for my purpose. This website ( has the python script to send sms using way2sms. I’m thanking to that blog owner :-).

Action involved are,

1. Register new account with
2. Configure python script
3. Add the new nagios command for enabling sms notification for service and host failure.
4. Update the contact information.

1. Create an account with

Register your moble and this service company send you the login details over sms. You need this login information in python script to send sms. This script just does the normal web login to send sms.

2. Install python script

Create a script under “/usr/local/nagios/libexec/“. You may need to update the following fields in the script
br[“username”] = “” #YOUR MOBILE NUMBER HERE
br[“password”] = “” #YOUR PASSWORD HERE

Here is the script content.

#!/usr/bin/env python

import sys
import time
    import mechanize
except ImportError:
    print "Please install mechanize module for python"
    print "Install python-mechanize, if you are on a Ubuntu/Debian machine"
    from optparse import OptionParser
except ImportError:
    print "Error importing optparse module"

def SendSMS(mobile,text):
    print ">>> initializing.."
    br = mechanize.Browser()
    print ">>> connecting to way2sms..."
       br["username"] = ""  #YOUR MOBILE NUMBER HERE
       br["password"] = ""  #YOUR PASSWORD HERE
       print ">>> " + br.title()
       response = br.submit()
       print ">>> logged in.."
        print ">>> FATAL: Error occurred while login process!"
        print ">>> sending message...""")
        br["MobNo"]      = mobile
        br["textArea"]   = text
        response = br.submit()
        print ">>> submitting..."
        print ">>> logging out...""")
        print ">>> html seems to be changed!"
        print ">>> please modify the program to work with newly modified website!"

def main():
    parser = OptionParser()
    usage = "Usage: %prog -m [number] -t [text]"
    parser = OptionParser(usage=usage, version="%prog 1.0")
    parser.add_option("-m", "--number",  action="store", type="string",dest="number",  help="Mobile number to send sms")
    parser.add_option("-t", "--text", action="store", type="string", dest="text", help="Text to send")
    (options, args) = parser.parse_args()
    if options.number and options.text:
       print "Fatal: Required arguments are missing!"
       print "Use: -h / --help to get help."

if __name__ == "__main__":

Now you need to install python-mechanize in order to work this script. so you need to install python package installer program “eazy_install” which shipped with setuptools.

[root@nagios /]# wget
[root@nagios /]# tar -zxvf setuptools-0.6c11.tar.gz
[root@nagios /]# cd setuptools-0.6c11
[root@nagios setuptools-0.6c11]# python ./ install
[root@nagios setuptools-0.6c11]# easy_install mechanize

Now you need to verify the packages are correctly installed.

[root@nagios ~]# python  /usr/local/nagios/libexec/ -h
usage: Usage: -m [number] -t [text]

  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -m NUMBER, --number=NUMBER
                        Mobile number to send sms
  -t TEXT, --text=TEXT  Text to send
[root@nagios ~]#

Sending test sms

[root@nagios ~]# python  /usr/local/nagios/libexec/ -m 94977720 -t " Testing Nagios notification"
>>> initializing..
>>> connecting to way2sms...
>>> Free SMS, Send Free SMS, Send Free SMS to india, Free email alerts, email2SMS, SMS Alerts,Bill Reminders, EMI Reminders, Loan Reminders, TV Shows Reminders, Future SMS, Mobile Bill Reminders
>>> logged in..
>>> sending message...
>>> submitting...
>>> logging out...
[root@nagios ~]#

So your installation looks good.

3. Updating “/usr/local/nagios/etc/objects/commands.cfg” file
Open the file and append the following lines at the end of file

define command{
    command_name    notify-host-by-sms
    command_line    /usr/local/nagios/libexec/  -m $CONTACTPAGER$ -t "Type: $NOTIFICATIONTYPE$\
                    Host: $HOSTNAME$ \
                    State: $HOSTSTATE$ \
                    Address: $HOSTADDRESS$ \
                    Info: $HOSTOUTPUT$ Time: $LONGDATETIME$"

define command{
    command_name    notify-service-by-sms
    command_line    /usr/local/nagios/libexec/  -m $CONTACTPAGER$  -t "Type: $NOTIFICATIONTYPE$\
                    Host: $HOSTNAME$ \
                    Service: $SERVICEDESC$ \
                    State: $SERVICESTATE$ \
                    Date/Time: $LONGDATETIME$ Additional Info:$SERVICEOUTPUT$"

4. Update your contact information (/usr/local/nagios/etc/objects/contacts.cfg)

You may need to add 3 lines in it.

service_notification_commands notify-service-by-email,notify-service-by-sms
host_notification_commands notify-host-by-email,notify-service-by-sms
pager 9744209638

My sample contact will look like this.

define contact{
contact_name    liju
use             generic-contact
alias           Liju Mathew
service_notification_commands notify-service-by-email,notify-service-by-sms
host_notification_commands notify-host-by-email,notify-service-by-sms
pager 94000000

[root@nagios ~]# service nagios restart
Running configuration check…done.
Stopping nagios: done.
Starting nagios: done.
[root@nagios ~]#

Then simply restart Nagios service. For the testing purpose you may set one incorrect service name which was not defined in nrpe commands list. So that you get a notification sms and have the test easily.

Cool !!! Now you have ABSOLUTELY FREE nagios sms alert facility.

You may also use this script for sending sms if any critical systems/process reached the threshold limit like backup failure, intruder detention found etc. etc.

nJnoy 🙂

16 comments to Nagios : Enabling FREE SMS notification [INDIA]

  • Vivek I S

    Hi Dude… this is really very useful info.. crisp & clear.. thnx..

  • Troy

    Hi Liju,
    Very clear and precise..worked like a charm..thanks.

    • rajesh

      hi troy,
      i followed above guidlines. Every thing is working fine. i can send mail from command line using [ python /usr/local/nagios/libexec/ -m 99XXXXXXXX -t “this is test”.]
      Now i want sms should be delivered if MySql goes down or ” ping” stops or ssh down.
      how to do that ? You reply awaiting !!!!!!!

  • Pallav

    I think website has changed

    mine saying html has changed

  • rajesh

    i followed above guideline but i got an error when i see the log file. Below are the log msg
    #/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    Nagios Core 3.4.1
    Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
    Copyright (c) 1999-2009 Ethan Galstad
    Last Modified: 05-11-2012
    License: GPL


    #service nagios restart

    Reading configuration data…
    Read main config file okay…
    Processing object config file ‘/usr/local/nagios/etc/objects/commands.cfg’…
    Error: Invalid command object directive ‘Address:’.
    Error: Could not add object property in file ‘/usr/local/nagios/etc/objects/commands.cfg’ on line 257.
    Error processing object config files!

    and if i commented ( Address: $HOSTADDRESS$\) in command.cfg file.
    nagios restart successfully but in browser it shows below msg.


    Error: Could not read object configuration data!

    Here are some things you should check in order to resolve this error:

    Verify configuration options using the -v command-line option to check for errors.
    Check the Nagios log file for messages relating to startup or status data errors.

    Please help on this.

  • pls allow this service for bangladesh

  • This is very good documentation.

  • Nikhil


    Thanks for the useful script..

    The script works correctly if I run it directly (not through nagios).
    But through nagios, it gives “Fatal error”. The error is because of line

    Can you please help in resolving it. Is it because of some administrative permissions to user ‘nagios’.


    • Hello Nikhil

      Ensure that you script has copied under “nagios’s libexec ” directory and others has execute permission.

      Keep in mind that you may need to install certain modules required for run this scripts.

      [root@nagios ~]# ls -la /usr/local/nagios/libexec/
      -rwxr-xr-x 1 root root 2320 Apr 11 2012 /usr/local/nagios/libexec/
      [root@nagios ~]#

  • akshay

    I used your script but it gives me error. Stating ”
    >>> html seems to be changed!
    >>> please modify the program to work with newly modified website!

    I intentionally put then the incorrect password, even then it says

    >>> html seems to be changed!
    >>> please modify the program to work with newly modified website!

    but in actual it should say, if the password is incorrect

    >>> FATAL: Error occurred while login process!

    So, can you please resolve this and help me?

  • Deepak I

    I get this error.. .what am I doing wrong???

    >>> initializing..
    >>> Debug: ON
    >>> connecting to way2sms…
    Debug information
    Traceback (most recent call last):
    File “/usr/local/nagios/libexec/”, line 83, in do
    response =
    File “/usr/lib/python2.4/site-packages/mechanize/”, line 203, in open
    return self._mech_open(url, data, timeout=timeout)
    File “/usr/lib/python2.4/site-packages/mechanize/”, line 255, in _mech_open
    raise response
    httperror_seek_wrapper: HTTP Error 403: request disallowed by robots.txt

    >>> FATAL: Error occured while performing process!

  • Sreejith

    connecting to way2sms…
    >>> FATAL: Error occurred while login process!

  • rahul

    >>> FATAL: Error occurred while login process!

    this error is coming, can you please suggest!!!!

Leave a Reply

You can use these HTML tags

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