<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>RE: [Nagios-users] website transaction monitor / simple web form</TITLE>
<META content="MSHTML 5.50.4919.2200" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff size=2>Here's
the final result for my WWW::Mechanize perl script:</FONT></SPAN></DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff
size=2>#!/usr/bin/perl -w</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff size=2>#
Check Communigate Pro webmail for Nagios</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff size=2>use
WWW::Mechanize;<BR>use diagnostics;</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff size=2>use
lib "/usr/local/nagios/libexec" ;<BR>use utils qw($TIMEOUT %ERRORS
&print_revision &support);</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff size=2>my
$browser = WWW::Mechanize->new();<BR>$browser->get("<A
href="http://webmail.vel.net/">http://webmail.vel.net/</A>");</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff
size=2>$browser->form(1);</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff
size=2>$browser->field("Username",
"test\@vel.net");<BR>$browser->field("Password",
"test06");<BR>$browser->click("login");</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff
size=2>$browser->follow("here");</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff
size=2>$pattern = "INBOX";</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff size=2>$_ =
$browser->{content};</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff size=2>if (
/$pattern/ ) { <BR> print
"INBOX";<BR> exit
$ERRORS{'OK'};<BR>}<BR>else<BR>
{<BR> print ("ERROR: No response from
webmail.vel.net\n");<BR> exit
$ERRORS{'CRITICAL'};<BR>
}</FONT></SPAN></DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff size=2>Hope
this helps someone. Thanks to Stanley for his input.</FONT></SPAN></DIV>
<DIV><SPAN class=794101319-10022003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN
class=794101319-10022003>
<FONT face=Arial color=#0000ff size=2>richg</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Richard Gross
<BR><B>Sent:</B> Saturday, February 08, 2003 10:10 PM<BR><B>To:</B> Stanley
Hopcroft<BR><B>Cc:</B> nagios-users@lists.sourceforge.net<BR><B>Subject:</B>
RE: [Nagios-users] website transaction monitor / simple web
form<BR><BR></FONT></DIV><!-- Converted from text/plain format -->
<P><FONT size=2>Stanley,</FONT> </P>
<P><FONT size=2>Thanks for your approach. I elected to try
WWW::Mechanize and got</FONT> <BR><FONT size=2>This far:</FONT> </P>
<P><FONT size=2>#!/usr/bin/perl -w</FONT> </P>
<P><FONT size=2># Check Communigate Pro webmail for Nagios</FONT> </P>
<P><FONT size=2>use WWW::Mechanize;</FONT> <BR><FONT size=2>use
HTML::TokeParser;</FONT> <BR><FONT size=2>use diagnostics;</FONT> </P>
<P><FONT size=2>my $browser = WWW::Mechanize->new();</FONT> <BR><FONT
size=2>$browser->get("<A
href="http://webmail.vel.net/">http://webmail.vel.net/</A>");</FONT> </P>
<P><FONT size=2>$browser->form(1);</FONT> </P>
<P><FONT size=2>$browser->field("Username", "test\@vel.net");</FONT>
<BR><FONT size=2>$browser->field("Password", "test06");</FONT> <BR><FONT
size=2>$browser->click("login");</FONT> </P>
<P><FONT size=2>$browser->follow("here");</FONT> </P>
<P><FONT size=2>$pattern = "INBOX";</FONT> </P>
<P><FONT size=2>$_ = $browser->{content};</FONT> </P>
<P><FONT size=2>if ( /$pattern/ ) { </FONT><BR><FONT
size=2> print "INBOX";</FONT>
<BR><FONT size=2> exit 0;</FONT>
<BR><FONT size=2>}</FONT> <BR><FONT size=2>else</FONT> <BR><FONT
size=2> {</FONT> <BR><FONT
size=2> print "CRITICAL";</FONT>
<BR><FONT size=2> exit -1;</FONT>
<BR><FONT size=2> }</FONT> </P>
<P><FONT size=2>I wrote this for the purpose of seeing whether webmail was up
or not. It</FONT> <BR><FONT size=2>Was easy to monitor for SMTP and
POP3. I'd love to figure out SMTP transaction to a POP3 box.
Anyways...</FONT> </P>
<P><FONT size=2>The above works for the way I have Communigate Pro
setup. I know everything is hard coded and I'm not taking any ARGV
things. My limited knowledge of Perl is preventing me on how to send
Nagios the results of OK or CRITICAL. </FONT></P>
<P><FONT size=2>Been trying to figure it out, but kinda stumped right
now. But Perl is an</FONT> <BR><FONT size=2>Amazing beast. So few
lines of code to do something very useful.</FONT> </P>
<P><FONT size=2>So, any ideas are appreciated.</FONT> </P>
<P>
<FONT size=2>richg</FONT> </P>
<P><FONT size=2>-----Original Message-----</FONT> <BR><FONT size=2>From:
Stanley Hopcroft [<A
href="mailto:Stanley.Hopcroft@IPAustralia.Gov.AU">mailto:Stanley.Hopcroft@IPAustralia.Gov.AU</A>]
</FONT><BR><FONT size=2>Sent: Friday, February 07, 2003 6:15 PM</FONT>
<BR><FONT size=2>To: Richard Gross</FONT> <BR><FONT size=2>Cc:
nagios-users@lists.sourceforge.net</FONT> <BR><FONT size=2>Subject: Re:
[Nagios-users] website transaction monitor / simple web form</FONT> </P>
<P><FONT size=2>Dear Sir,</FONT> </P>
<P><FONT size=2>There are a number of approaches for dealing with HTTP
transactions/web</FONT> <BR><FONT size=2>forms.</FONT> </P>
<P><FONT size=2>They include your writing wrraper programs to Perl modules
that are</FONT> <BR><FONT size=2>congnizant of the transaction structure (ie
what to send to what URL and</FONT> <BR><FONT size=2>when).</FONT> </P>
<P><FONT size=2>These modules include</FONT> </P>
<P><FONT size=2>A CPAN</FONT> </P>
<P><FONT size=2>1 WWW::Mechanize</FONT> </P>
<P><FONT size=2>2 WWW::Automate</FONT> </P>
<P><FONT size=2>B SourceForge</FONT> </P>
<P><FONT size=2>1 <A href="HTTP::MonkeyWrench">HTTP::MonkeyWrench</A></FONT>
</P>
<P><FONT size=2>C unpublished</FONT> </P>
<P><FONT size=2>1 Netsaint::Web_Trx</FONT> </P>
<P><FONT size=2>Here's an example plugin using the latter,</FONT> </P><BR>
<P><FONT size=2>use constant
Intro
=></FONT> <BR><FONT size=2>'<A
href="http://external/atmoss/falcon.application_start'">http://external/atmoss/falcon.application_start'</A>
;</FONT> <BR><FONT size=2>use constant ConnectToSearch
=></FONT> <BR><FONT size=2>'<A
href="http://external/atmoss/Falcon_Users_Cookies.Define_User'">http://external/atmoss/Falcon_Users_Cookies.Define_User'</A>
;</FONT> <BR><FONT size=2>use constant
MultiSessConn =></FONT> <BR><FONT size=2>'<A
href="http://external/atmoss/Falcon_Users_Cookies.Run_Create'">http://external/atmoss/Falcon_Users_Cookies.Run_Create'</A>
;</FONT> <BR><FONT size=2>use constant
Search
=></FONT> <BR><FONT size=2>'<A
href="http://external/atmoss/Falcon.Result'">http://external/atmoss/Falcon.Result'</A>
;</FONT> <BR><FONT size=2>use constant ResultAbstract
=></FONT> <BR><FONT size=2>'<A
href="http://external/atmoss/falcon_details.show_tm_details'">http://external/atmoss/falcon_details.show_tm_details'</A>
;</FONT> <BR><FONT size=2>use constant
ResultDetails =></FONT> <BR><FONT size=2>'<A
href="http://external/atmoss/Falcon_Details.Show_TM_Details'">http://external/atmoss/Falcon_Details.Show_TM_Details'</A>
;</FONT> <BR><FONT size=2>use constant DeleteSearches
=></FONT> <BR><FONT size=2>'<A
href="http://external/atmoss/Falcon_Searches.Delete_All_Searches'">http://external/atmoss/Falcon_Searches.Delete_All_Searches'</A>
;</FONT> </P>
<P><FONT size=2>use constant
Int
=> 'Welcome to ATMOSS' ;</FONT> <BR><FONT size=2>use constant
ConnSrch =>
'Connect to Trade Mark Search' ;</FONT> <BR><FONT size=2>use constant
MltiSess =>
'Fill in one or more of the fields</FONT> <BR><FONT size=2>below' ;</FONT>
<BR><FONT size=2>use constant
Srch
=> 'Your search request</FONT> <BR><FONT
size=2>retrieved\s+\d+\s+match(es)?' ;</FONT> <BR><FONT size=2>use constant
ResAbs
=> 'Trade Mark\s+:\s+\d+' ;</FONT> <BR><FONT size=2>use constant
ResDet
=> ResAbs ;</FONT> <BR><FONT size=2>use constant
DelSrch
=> MltiSess ;</FONT> </P>
<P><FONT size=2>use constant
MSC_f
=> [p_Anon => 'REGISTERED', p_user_type</FONT> <BR><FONT size=2>=>
'Connect to Existing Extract List', p_extID => 'Stanley Hopcroft',</FONT>
<BR><FONT size=2>p_password => 'It', p_JS => 'N'] ;</FONT> <BR><FONT
size=2>use constant
Srch_v
=> [p_tmno1 => 'tmno'] ;</FONT> <BR><FONT size=2>use constant
RA_v
=> [p_tm_number => 'tmno'] ;</FONT> <BR><FONT size=2>use constant
RA_f
=> [p_detail => 'QUICK', p_rec_all => 1,</FONT> <BR><FONT
size=2>p_rec_no => 1, p_search_no => 1, p_ExtDisp => 'D'] ;</FONT>
<BR><FONT size=2>use constant
RD_v
=> RA_v ;</FONT> <BR><FONT size=2>use constant
RD_f
=> [p_Detail => 'DETAILED', p_rec_no =></FONT> <BR><FONT size=2>1,
p_search_no => 1, p_ExtDisp => 'D'];</FONT> </P>
<P><FONT size=2>use constant
OraFault => 'We
were unable to process your</FONT> <BR><FONT size=2>request at this time'
;</FONT> </P>
<P><FONT size=2>use constant
URLS
=> [</FONT> <BR><FONT size=2> {Method => 'GET', Url =>
Intro, Qs_var
=> [], Qs_fixed</FONT> <BR><FONT size=2>=>
[], Exp => Int, Exp_Fault => OraFault},</FONT>
<BR><FONT size=2> {Method => 'GET', Url => ConnectToSearch,
Qs_var => [], Qs_fixed</FONT> <BR><FONT
size=2>=> [], Exp => ConnSrch,Exp_Fault => OraFault},</FONT>
<BR><FONT size=2> {Method => 'POST', Url =>
MultiSessConn, Qs_var => [],
Qs_fixed</FONT> <BR><FONT size=2>=> MSC_f,Exp => MltiSess,Exp_Fault
=> OraFault},</FONT> <BR><FONT size=2> {Method => 'POST', Url
=> Search, Qs_var
=> Srch_v, Qs_fixed</FONT> <BR><FONT size=2>=> [], Exp =>
Srch, Exp_Fault => OraFault},</FONT> <BR><FONT
size=2> {Method => 'GET', Url => ResultAbstract,
Qs_var => RA_v, Qs_fixed</FONT> <BR><FONT size=2>=>
RA_f, Exp => ResAbs,Exp_Fault => OraFault},</FONT> <BR><FONT
size=2> {Method => 'POST', Url => ResultDetails,
Qs_var => RD_v, Qs_fixed</FONT> <BR><FONT size=2>=>
RD_f, Exp => ResDet,Exp_Fault => OraFault},</FONT> <BR><FONT
size=2> {Method => 'POST', Url => DeleteSearches, Qs_var
=> [], Qs_fixed</FONT> <BR><FONT size=2>=>
[], Exp => DelSrch, Exp_Fault => OraFault},</FONT> <BR><FONT
size=2> ] ;</FONT> </P>
<P><FONT size=2>my (@tmarks, $tmno, $i) ;</FONT> </P>
<P><FONT size=2>@tmarks = @ARGV ? @ARGV : (3, 100092, 200099, 300006, 400075,
500067,</FONT> <BR><FONT size=2>600076, 700066, 800061) ;</FONT> <BR><FONT
size=2>$i = @ARGV == 1 ? 0 : int( rand($#tmarks) + 0.5 ) ;</FONT> <BR><FONT
size=2>$tmno = $tmarks[$i] ;</FONT> </P>
<P><FONT size=2>my $x = Netsaint::Web_Trx->new( URLS ) ;</FONT> </P>
<P><FONT size=2>my ($rc, $message) = $x->check( {tmno => $tmno},
debug => $debug) ;</FONT> </P>
<P><FONT size=2>print "ATMOSS $message\n" ;</FONT> <BR><FONT size=2>exit($rc ?
$ERRORS{'OK'} : $ERRORS{'CRITICAL'}) ;</FONT> </P><BR>
<P><FONT size=2>Easy Peasi: call the constructor with a ref to a hash
containing all the</FONT> <BR><FONT size=2>URLs and the data to be sent to
each URL, then call the check method.</FONT> </P>
<P><FONT size=2>The hard bit in this case - and it's a pretty big gotcha - is
_you_ have</FONT> <BR><FONT size=2>to work out the sequence of URLs sent and
the data supplied to each form</FONT> <BR><FONT size=2>(some of which is
invisible).</FONT> </P>
<P><FONT size=2>The CPAN modules may be a better bet but this works well for
me.</FONT> </P>
<P><FONT size=2>On Fri, Feb 07, 2003 at 11:31:33AM -0800, Richard Gross
wrote:</FONT> <BR><FONT size=2>> Wondering what can be done to use Nagios
to check</FONT> <BR><FONT size=2>> a simple webform? Maybe some
modifiction of the wget that</FONT> <BR><FONT size=2>> checked the hp
switches? The opening page has:</FONT> <BR><FONT size=2>>
</FONT><BR><FONT
size=2>>
<h4><b>Welcome to CommuniGate Pro,<br></FONT> <BR><FONT
size=2>>
the <span class="orange">test.net</span> Messaging</FONT>
<BR><FONT size=2>> Server!</b> </h4></FONT> <BR><FONT
size=2>>
<form method=post enctype="multipart/form-data"></FONT> <BR><FONT
size=2>>
<table border=0 cellspacing=0 cellpadding=0 width="100%"></FONT>
<BR><FONT
size=2>>
<tr bgcolor="#003333" class="contrast"> </FONT><BR><FONT
size=2>>
<th NOWRAP align=CENTER> Registered Users </th></FONT> <BR><FONT
size=2>>
</tr></FONT> <BR><FONT
size=2>>
</table></FONT> <BR><FONT
size=2>>
<br></FONT> <BR><FONT
size=2>>
<table border=0 cellspacing=0 cellpadding=2></FONT> <BR><FONT
size=2>>
<tr> </FONT><BR><FONT
size=2>>
<th NOWRAP align=LEFT><font class="colfont"</FONT> <BR><FONT
size=2>> color="#cc6600">Login </FONT><BR><FONT
size=2>>
Name</font></th></FONT> <BR><FONT
size=2>>
<th NOWRAP align=LEFT><font class="colfont"</FONT> <BR><FONT
size=2>> color="cc6600">Password</font></th></FONT>
<BR><FONT
size=2>>
<td></td></FONT> <BR><FONT
size=2>>
</tr></FONT> <BR><FONT
size=2>>
<tr valign=TOP> </FONT><BR><FONT
size=2>>
<td></FONT> <BR><FONT
size=2>>
<input name="Username" type=text size=20</FONT> <BR><FONT size=2>>
maxlength=255></FONT> <BR><FONT
size=2>>
</td></FONT> <BR><FONT
size=2>>
<td></FONT> <BR><FONT
size=2>>
<input name="Password" type=password size=10</FONT> <BR><FONT size=2>>
maxlength=99></FONT> <BR><FONT
size=2>>
</td></FONT> <BR><FONT
size=2>>
<td></FONT> <BR><FONT
size=2>>
<input name="login" type=submit value="Enter"></FONT>
<BR><FONT
size=2>>
</td></FONT> <BR><FONT
size=2>>
</tr></FONT> <BR><FONT
size=2>>
<tr> </FONT><BR><FONT
size=2>>
<td colspan=2></td></FONT> <BR><FONT
size=2>>
<td></td></FONT> <BR><FONT
size=2>>
</tr></FONT> <BR><FONT
size=2>>
</table></FONT> <BR><FONT
size=2>>
<p> </FONT><BR><FONT
size=2>>
</form></FONT> <BR><FONT size=2>> </FONT><BR><FONT size=2>> and
would like to supply a username and password to this form,</FONT> <BR><FONT
size=2>> then check for a text string INBOX would be all that's
required.</FONT> <BR><FONT size=2>> </FONT><BR><FONT size=2>> I did try
the command:</FONT> <BR><FONT size=2>> </FONT><BR><FONT size=2>> wget -r
--http-user=chris@test.net --http-passwd=chris06</FONT> <BR><FONT size=2>>
<A href="http://webmail.test.net">http://webmail.test.net</A> but only got
back the index page...</FONT> <BR><FONT size=2>> </FONT><BR><FONT
size=2>> Not really sure how to proceed from here.</FONT> <BR><FONT
size=2>> </FONT><BR><FONT size=2>>
richg</FONT> <BR><FONT size=2>>
</FONT><BR><FONT size=2>></FONT> </P>
<P><FONT size=2>Yours sincerely. </FONT></P>
<P><FONT size=2>-- </FONT><BR><FONT
size=2>------------------------------------------------------------------------</FONT>
<BR><FONT size=2>Stanley Hopcroft</FONT> <BR><FONT
size=2>------------------------------------------------------------------------</FONT>
</P>
<P><FONT size=2>'...No man is an island, entire of itself; every man is a
piece of the</FONT> <BR><FONT size=2>continent, a part of the main. If a clod
be washed away by the sea,</FONT> <BR><FONT size=2>Europe is the less, as well
as if a promontory were, as well as if a</FONT> <BR><FONT size=2>manor of thy
friend's or of thine own were. Any man's death diminishes</FONT> <BR><FONT
size=2>me, because I am involved in mankind; and therefore never send to
know</FONT> <BR><FONT size=2>for whom the bell tolls; it tolls for
thee...'</FONT> </P>
<P><FONT size=2>from Meditation 17, J Donne.</FONT>
</P></BLOCKQUOTE></BODY></HTML>