website transaction monitor / simple web form

Richard Gross rich at vel.net
Sun Feb 9 07:09:51 CET 2003


Stanley,

Thanks for your approach.  I elected to try WWW::Mechanize and got
This far:

#!/usr/bin/perl -w

# Check Communigate Pro webmail for Nagios

use WWW::Mechanize;
use HTML::TokeParser;
use diagnostics;

my $browser = WWW::Mechanize->new();
$browser->get("http://webmail.vel.net/");

$browser->form(1);

$browser->field("Username", "test\@vel.net");
$browser->field("Password", "test06");
$browser->click("login");

$browser->follow("here");

$pattern = "INBOX";

$_ = $browser->{content};

if ( /$pattern/ ) { 
        print "INBOX";
        exit 0;
}
else
        {
        print "CRITICAL";
        exit -1;
        }

I wrote this for the purpose of seeing whether webmail was up or not.
It
Was easy to monitor for SMTP and POP3.   I'd love to figure out SMTP
transaction to a POP3 box. Anyways...

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.  

Been trying to figure it out, but kinda stumped right now.  But Perl is
an
Amazing beast.  So few lines of code to do something very useful.

So, any ideas are appreciated.

								richg

-----Original Message-----
From: Stanley Hopcroft [mailto:Stanley.Hopcroft at IPAustralia.Gov.AU] 
Sent: Friday, February 07, 2003 6:15 PM
To: Richard Gross
Cc: nagios-users at lists.sourceforge.net
Subject: Re: [Nagios-users] website transaction monitor / simple web
form

Dear Sir,

There are a number of approaches for dealing with HTTP transactions/web
forms.

They include your writing wrraper programs to Perl modules that are
congnizant of the transaction structure (ie what to send to what URL and
when).

These modules include

A CPAN

1 WWW::Mechanize

2 WWW::Automate

B SourceForge

1 HTTP::MonkeyWrench

C unpublished

1 Netsaint::Web_Trx

Here's an example plugin using the latter,


use constant Intro              =>
'http://external/atmoss/falcon.application_start' ;
use constant ConnectToSearch    =>
'http://external/atmoss/Falcon_Users_Cookies.Define_User' ;
use constant MultiSessConn      =>
'http://external/atmoss/Falcon_Users_Cookies.Run_Create' ;
use constant Search             =>
'http://external/atmoss/Falcon.Result' ;
use constant ResultAbstract     =>
'http://external/atmoss/falcon_details.show_tm_details' ;
use constant ResultDetails      =>
'http://external/atmoss/Falcon_Details.Show_TM_Details' ;
use constant DeleteSearches     =>
'http://external/atmoss/Falcon_Searches.Delete_All_Searches' ;

use constant Int                => 'Welcome to ATMOSS' ;
use constant ConnSrch           => 'Connect to Trade Mark Search' ;
use constant MltiSess           => 'Fill in one or more of the fields
below' ;
use constant Srch               => 'Your search request
retrieved\s+\d+\s+match(es)?' ;
use constant ResAbs             => 'Trade Mark\s+:\s+\d+' ;
use constant ResDet             => ResAbs ;
use constant DelSrch            => MltiSess ;

use constant MSC_f              => [p_Anon => 'REGISTERED', p_user_type
=> 'Connect to Existing Extract List', p_extID => 'Stanley Hopcroft',
p_password => 'It', p_JS => 'N'] ;
use constant Srch_v             => [p_tmno1 => 'tmno'] ;
use constant RA_v               => [p_tm_number => 'tmno'] ;
use constant RA_f               => [p_detail => 'QUICK', p_rec_all => 1,
p_rec_no => 1, p_search_no => 1, p_ExtDisp => 'D'] ;
use constant RD_v               => RA_v ;
use constant RD_f               => [p_Detail => 'DETAILED', p_rec_no =>
1, p_search_no => 1,  p_ExtDisp => 'D'];

use constant OraFault           => 'We were unable to process your
request at this time' ;

use constant URLS               => [
  {Method => 'GET',  Url => Intro,           Qs_var => [],      Qs_fixed
=> [], Exp => Int,     Exp_Fault => OraFault},
  {Method => 'GET',  Url => ConnectToSearch, Qs_var => [],      Qs_fixed
=> [], Exp => ConnSrch,Exp_Fault => OraFault},
  {Method => 'POST', Url => MultiSessConn,   Qs_var => [],      Qs_fixed
=> MSC_f,Exp => MltiSess,Exp_Fault => OraFault},
  {Method => 'POST', Url => Search,          Qs_var => Srch_v,  Qs_fixed
=> [], Exp => Srch,    Exp_Fault => OraFault},
  {Method => 'GET',  Url => ResultAbstract,  Qs_var => RA_v,    Qs_fixed
=> RA_f, Exp => ResAbs,Exp_Fault => OraFault},
  {Method => 'POST', Url => ResultDetails,   Qs_var => RD_v,    Qs_fixed
=> RD_f, Exp => ResDet,Exp_Fault => OraFault},
  {Method => 'POST', Url => DeleteSearches,  Qs_var => [],      Qs_fixed
=> [], Exp => DelSrch, Exp_Fault => OraFault},
        ] ;

my (@tmarks, $tmno, $i) ;

@tmarks = @ARGV ? @ARGV : (3, 100092, 200099, 300006, 400075, 500067,
600076, 700066, 800061) ;
$i = @ARGV == 1 ? 0 : int( rand($#tmarks) + 0.5 ) ;
$tmno = $tmarks[$i] ;

my $x = Netsaint::Web_Trx->new( URLS ) ;

my ($rc, $message) =  $x->check( {tmno => $tmno}, debug => $debug) ;

print "ATMOSS $message\n" ;
exit($rc ? $ERRORS{'OK'} : $ERRORS{'CRITICAL'}) ;


Easy Peasi: call the constructor with a ref to a hash containing all the
URLs and the data to be sent to each URL, then call the check method.

The hard bit in this case - and it's a pretty big gotcha - is _you_ have
to work out the sequence of URLs sent and the data supplied to each form
(some of which is invisible).

The CPAN modules may be a better bet but this works well for me.

On Fri, Feb 07, 2003 at 11:31:33AM -0800, Richard Gross wrote:
> Wondering what can be done to use Nagios to check
> a simple webform?  Maybe some modifiction of the wget that
> checked the hp switches?  The opening page has:
> 
>             <h4><b>Welcome to CommuniGate Pro,<br>
>               the <span class="orange">test.net</span> Messaging
> Server!</b> </h4>
>             <form method=post enctype="multipart/form-data">
>               <table border=0 cellspacing=0 cellpadding=0
width="100%">
>                 <tr bgcolor="#003333" class="contrast"> 
>                   <th NOWRAP align=CENTER> Registered Users </th>
>                 </tr>
>               </table>
>               <br>
>               <table border=0 cellspacing=0 cellpadding=2>
>                 <tr> 
>                   <th NOWRAP align=LEFT><font class="colfont"
> color="#cc6600">Login 
>                     Name</font></th>
>                   <th NOWRAP align=LEFT><font class="colfont"
> color="cc6600">Password</font></th>
>                   <td></td>
>                 </tr>
>                 <tr valign=TOP> 
>                   <td>
>                     <input name="Username" type=text size=20
> maxlength=255>
>                   </td>
>                   <td>
>                     <input name="Password" type=password size=10
> maxlength=99>
>                   </td>
>                   <td>
>                     <input name="login"    type=submit value="Enter">
>                   </td>
>                 </tr>
>                 <tr> 
>                   <td colspan=2></td>
>                   <td></td>
>                 </tr>
>               </table>
>               <p> 
>             </form>
> 
> and would like to supply a username and password to this form,
> then check for a text string INBOX  would be all that's required.
> 
> I did try the command:
> 
> wget -r --http-user=chris at test.net --http-passwd=chris06
> http://webmail.test.net but only got back the index page...
> 
> Not really sure how to proceed from here.
> 
> 							richg
> 
>

Yours sincerely. 

-- 
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------

'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'

from Meditation 17, J Donne.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20030208/ad81cd47/attachment.html>


More information about the Users mailing list