NAME

Nagios::Plugin::WWW::Mechanize - Login to a web page as a user and get data as a Nagios plugin

SYNOPSIS

use Nagios::Plugin::WWW::Mechanize;
$np = Nagios::Plugin::WWW::Mechanize->new( 
  usage => "Checks number of mailing list users"
);
$np->getopts;

$np->get( "http://lists.opsview.org/lists/admin/opsview-users/members" );
$np->submit_form( form_name => "f", fields => { adminpw => "****" } );
$content = $np->content;
($number_of_users) = ($content =~ /(\d+) members total/);
$np->nagios_exit( CRITICAL, "Cannot get number of users" ) unless defined $number_of_users;

$np->add_perfdata(
  label => "users",
  value => $number_of_users,
);
$np->nagios_exit(
  OK,
  "Number of mailing list users: $number_of_users"
);

DESCRIPTION

This module ties Nagios::Plugin with WWW::Mechanize so that there's less code in your perl script and the most common work is done for you.

For example, the plugin will automatically call nagios_exit(CRITICAL, ...) if a page is unavailable or a submit_form fails. The plugin will also keep a track of the time for responses from the remote web server and output that as performance data.

INITIALISE

Nagios::Plugin::WWW::Mechanize->new( %opts )

Takes %opts. If $opts{mech} is specified and is an object, will check if it is a WWW::Mechanize object and die if not. If $opts{mech} is a hash ref, will pass those to a WWW::Mechanize->new() call. Will create a WWW::Mechanize object with autocheck => 0, otherwise any failures are exited immediately.

Also looks for $opts{include_time}. Defaults to 1 which means that performance data for time will be returned.

All other options are passed to Nagios::Plugin.

METHODS

mech

Returns the WWW::Mechanize object

get( @args )

Calls $self->mech->get( @args ). If $self->include_time is set, will start a timer before the get, calculate the duration, and adds it to a total timer.

If the mech->get call failed, will call nagios_exit with a CRITICAL error.

Returns the value from mech->get.

submit_form( @args )

Similar to get.

content

Shortcut for $self->mech->content.

nagios_exit

Override to add performance data for time if required

AUTHOR

Ton Voon, <ton.voon@opsera.com>

COPYRIGHT AND LICENSE

Copyright (C) 2006-2009 Opsera Limited. All rights reserved

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 116:

You forgot a '=back' before '=head1'

Around line 188:

You forgot a '=back' before '=head1'