<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.4418.33">
<TITLE>RE: [Nagios-users] website transaction monitor / simple web form</TITLE>
</HEAD>
<BODY>
<!-- 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>

</BODY>
</HTML>