nagios alert in mobile using way2sms script

899 views
Skip to first unread message

mukund parmar

unread,
Apr 21, 2012, 4:04:38 PM4/21/12
to VGLUG
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 ?

Tejas Barot

unread,
Apr 21, 2012, 10:58:20 PM4/21/12
to VGLUG
Hello Mukund,

As we already discuss I'll feel very happy to help you but So busy with work now-a-days.

You asked for help at the Right place, so some one will definitely help you out.

--
Thanks & Regards,
Tejas Barot
Linux Administrator,
Red Hat Certified Engineer,
Linux Blog:- http://www.tejasbarot.com
Open Source :- http://opensource.tejasbarot.com
Planet VGLUG :- http://planet-vglug.tejasbarot.com

Mobile Apps for All Linux User's Blog :-
Android, BlackBerry and iPhone :- http://www.tejasbarot.com/download-mobile-apps/

"If Your Home is Linux Home then Safety and Privacy is Guaranteed,
that's why my Privacy and Safety is always maintain when I stays at /root,
Live Happily and Stay Safely at Linux Home , Use Linux and Open Source" - Tejas Barot

Like My quote ? To Read and Submit More Linux Quotes :- http://linux-quotes.tejasbarot.com

Registered Linux User :- https://linuxcounter.net/user/507586.html

Sent on my BlackBerry® from Vodafone
--
Please read http://www.catb.org/~esr/faqs/smart-questions.html before posting.
You received this message because you are subscribed to the "Vibrant GNU/Linux User Group".
To stop receiving emails from this group, mail to VGLUG+un...@googlegroups.com
To post to this group, send email to VG...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/VGLUG

MUKUND PARMAR

unread,
Apr 22, 2012, 12:40:22 AM4/22/12
to vg...@googlegroups.com
okey thank you sir not to worry..

brijin

unread,
Jul 22, 2012, 11:58:28 PM7/22/12
to vg...@googlegroups.com
Hi,

   I am the author of that script. What kind of issue you are facing?

Thanks
Brijin

Vishal Joshi

unread,
Jul 23, 2012, 3:15:06 AM7/23/12
to vg...@googlegroups.com

On Mon, Jul 23, 2012 at 9:28 AM, brijin <bri...@gmail.com> wrote:
Hi,

   I am the author of that script. What kind of issue you are facing?

Hi Brijin,

Nice to see your post on this forum. Even i tried this script, but i had some issues. One thing i would like to ask you is that what if the way2sms site changes its login page url?

So what changes we need to make into your script if the url login changes?

Thanks for the support.
 
Thanks
Brijin


On Sunday, 22 April 2012 10:10:22 UTC+5:30, mukund parmar wrote:
okey thank you sir not to worry..

--
Please read http://www.catb.org/~esr/faqs/smart-questions.html before posting.
You received this message because you are subscribed to the "Vibrant GNU/Linux User Group".
To stop receiving emails from this group, mail to VGLUG+un...@googlegroups.com
To post to this group, send email to VG...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/VGLUG



Best regards,
Vishal Girish Joshi

Bris

unread,
Jul 24, 2012, 4:27:50 AM7/24/12
to vg...@googlegroups.com
Hi Vishal,

      Thanks! :-) Usually they don't change their internal URLs very frequently. Last change happened was around 6 months before.  Issues means, while integrating to Nagios or the script itself is having problems? Let me know if you need any help.  I'll recommend you to wrap this naked script inside a daemon (capable of keeping the way2sms session for atleast 10 minutes) if you are having a busy nagios setup. Other wise for each alert (frequent) it will repeat the login steps. Login ->sendsms ->logout

Thanks
Brijin


On Monday, 23 July 2012 12:45:06 UTC+5:30, VishalJoshi wrote:

On Mon, Jul 23, 2012 at 9:28 AM, brijin <bri...@gmail.com> wrote:
Hi,

   I am the author of that script. What kind of issue you are facing?

Hi Brijin,

Nice to see your post on this forum. Even i tried this script, but i had some issues. One thing i would like to ask you is that what if the way2sms site changes its login page url?

So what changes we need to make into your script if the url login changes?

Thanks for the support.
 
Thanks
Brijin


On Sunday, 22 April 2012 10:10:22 UTC+5:30, mukund parmar wrote:
okey thank you sir not to worry..

--
Please read http://www.catb.org/~esr/faqs/smart-questions.html before posting.
You received this message because you are subscribed to the "Vibrant GNU/Linux User Group".
To stop receiving emails from this group, mail to VGLUG+unsubscribe@googlegroups.com

To post to this group, send email to VG...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/VGLUG

Vishal Joshi

unread,
Jul 25, 2012, 3:11:16 AM7/25/12
to vg...@googlegroups.com

On Tue, Jul 24, 2012 at 1:57 PM, Bris <bri...@gmail.com> wrote:
Hi Vishal,

      Thanks! :-) Usually they don't change their internal URLs very frequently. Last change happened was around 6 months before.  Issues means, while integrating to Nagios or the script itself is having problems? Let me know if you need any help.  I'll recommend you to wrap this naked script inside a daemon (capable of keeping the way2sms session for atleast 10 minutes) if you are having a busy nagios setup. Other wise for each alert (frequent) it will repeat the login steps. Login ->sendsms ->logout

Hi Brijin,

Thanks for the reply. Kindly check the error i m facing.

######################################


>>> 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...
>>> html seems to be changed!
>>> please modify the program to work with newly modified website!

 
Thanks
Brijin
To stop receiving emails from this group, mail to VGLUG+un...@googlegroups.com

To post to this group, send email to VG...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/VGLUG

Bris

unread,
Jul 25, 2012, 10:22:16 AM7/25/12
to vg...@googlegroups.com
Hi Vishal,

   I think its not actually logged in. Something happened at the login step. Are you sure you are able to login using your login ID and password through way2sms.com? I have the same code running @http://dev.brijin.in without any issues. Can you modify the login block like below? Only change is "response.get_data() " to "print response.get_data()". Try to redirect the output to some file with html extension and open it with any web browser, then we can come to know what exactly is the issue.  Don't forget to remove the script output from the html file. 


+++++++++++++++++
       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()
       print response.get_data()  #(printing the output to terminal, the home page html)
       print ">>> logged in.."

+++++++++++++++++

Vishal Joshi

unread,
Jul 26, 2012, 6:00:04 AM7/26/12
to vg...@googlegroups.com
On Wed, Jul 25, 2012 at 7:52 PM, Bris <bri...@gmail.com> wrote:
Hi Vishal,

   I think its not actually logged in. Something happened at the login step. Are you sure you are able to login using your login ID and password through way2sms.com? I have the same code running @http://dev.brijin.in without any issues. Can you modify the login block like below? Only change is "response.get_data() " to "print response.get_data()". Try to redirect the output to some file with html extension and open it with any web browser, then we can come to know what exactly is the issue.  Don't forget to remove the script output from the html file. 


+++++++++++++++++
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()
print response.get_data() #(printing the output to terminal, the home page html) print ">>> logged in.."

+++++++++++++++++


Hi Brijin,

As you told to add a print command, i added and re-run the script saving it to html format.

It is giving some error. After logging in, it says that the requested URL /jsp/DashBoard.jsp was not found on this server.

Thanks in advance.
 
To stop receiving emails from this group, mail to VGLUG+un...@googlegroups.com

To post to this group, send email to VG...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/VGLUG

Vishal Joshi

unread,
Jul 27, 2012, 7:23:00 AM7/27/12
to vg...@googlegroups.com
On Thu, Jul 26, 2012 at 3:30 PM, Vishal Joshi <visha...@gmail.com> wrote:

On Wed, Jul 25, 2012 at 7:52 PM, Bris <bri...@gmail.com> wrote:
Hi Vishal,

   I think its not actually logged in. Something happened at the login step. Are you sure you are able to login using your login ID and password through way2sms.com? I have the same code running @http://dev.brijin.in without any issues. Can you modify the login block like below? Only change is "response.get_data() " to "print response.get_data()". Try to redirect the output to some file with html extension and open it with any web browser, then we can come to know what exactly is the issue.  Don't forget to remove the script output from the html file. 

Hiii Brijin,

When i run the script, it gives me below result.. Please let me know if the output is valid or not!

###################################

[root@nagios libexec]# python send_sms.py -m 9768797123 -t "Nagios SMS Testing"

>>> 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...
>>> html seems to be changed!
>>> please modify the program to work with newly modified website!

###########################################

Please let me know if the SMSes are being delivered or not?


 

Bris

unread,
Jul 30, 2012, 2:55:56 AM7/30/12
to vg...@googlegroups.com
Hi Vishal,

    From where you are executing the program? Are you behind any proxy or something?! This script is nothing but it will automate the quick sms feature of way2sms.com. Actually it is happening through pragmatic browsing.  ;-)  I think they have delivery reporting available on their website, if its there we can tie it up with our script. If you are looking for a professional solution, there are many  websites who are  providing bulk SMS packages with nicely written APIs :-D . A simple gsm modem + Kannel will be another solution (I have a working setup).

Thanks
Brijin

GOPI HC

unread,
Jul 30, 2012, 3:01:55 AM7/30/12
to vg...@googlegroups.com
Dear Vishal,


Check your Login details.

Because i got same error then i found that login problem.


Regards
Gopi

To stop receiving emails from this group, mail to VGLUG+un...@googlegroups.com

Vishal Joshi

unread,
Jul 30, 2012, 4:13:13 AM7/30/12
to vg...@googlegroups.com
On Mon, Jul 30, 2012 at 12:31 PM, GOPI HC <gop...@gmail.com> wrote:
Dear Vishal,


Check your Login details.

Because i got same error then i found that login problem.

Hi Gopi,

Thanks. But it seems i have logged in to way2sms.com through this script. Please see the below text...


[root@nagios libexec]# python send_sms.py -m 9768797123 -t "Nagios SMS Testing"
>>> 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..  <<<<<<<<<<<<<<<<< This seems to be logged in.
>>> sending message...  

Bris

unread,
Jul 31, 2012, 2:32:21 AM7/31/12
to vg...@googlegroups.com

   That's just a fancy output

       print ">>> logged in.."
Reply all
Reply to author
Forward
0 new messages