really need a help from tejash barot ..
was follow folowings steps
1. Create an account with
way2sms.com
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/send_sms.py“. 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. between comma only
"
#!/usr/bin/env python
import sys
import time
try:
import mechanize
except ImportError:
print "Please install mechanize module for python"
print "Install python-mechanize, if you are on a Ubuntu/Debian
machine"
sys.exit(1)
try:
from optparse import OptionParser
except ImportError:
print "Error importing optparse module"
sys.exit(1)
def SendSMS(mobile,text):
print ">>> initializing.."
br = mechanize.Browser()
print ">>> connecting to way2sms..."
try:
br.open("
http://site3.way2sms.com/entry.jsp")
br.select_form(name="loginform")
br["username"] = "" #YOUR MOBILE NUMBER HERE
br["password"] = "" #YOUR PASSWORD HERE
br.form.method="POST"
br.form.action="
http://site1.way2sms.com/Login1.action"
print ">>> " + br.title()
response = br.submit()
response.get_data()
print ">>> logged in.."
except:
print ">>> FATAL: Error occurred while login process!"
sys.exit(1)
try:
print ">>> sending message..."
br.open("
http://site1.way2sms.com/jsp/InstantSMS.jsp")
br.select_form(name="InstantSMS")
br["MobNo"] = mobile
br["textArea"] = text
br.form.method="POST"
br.form.action="
http://site1.way2sms.com/quicksms.action"
response = br.submit()
print ">>> submitting..."
print ">>> logging out..."
br.open("
http://site1.way2sms.com/jsp/logout.jsp")
br.close()
except:
print ">>> html seems to be changed!"
print ">>> please modify the program to work with newly
modified website!"
sys.exit(1)
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:
SendSMS(options.number,options.text)
else:
print "Fatal: Required arguments are missing!"
print "Use: -h / --help to get help."
if __name__ == "__main__":
main()
"
for that we required python-mechanize i install that..success fully
Now you need to verify the packages are correctly installed.
[root@nagios ~]# python /usr/local/nagios/libexec/send_sms.py -h
usage: Usage: send_sms.py -m [number] -t [text]
options:
--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/send_sms.py -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/send_sms.py -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/send_sms.py -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
email
li...@serveridol.com
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 ~]#
i follows following steps from
http://www.serveridol.com/2012/04/07/nagios-enabling-sms-notification-freely/
i success fully send sms in my mobile but nagios alerts not getting in
my mobile ?
why ?