Nagios::Plugin::WWW::Mechanize - Login to a web page as a user and get data as a Nagios plugin
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" );
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.
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.
Returns the WWW::Mechanize object
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.
Similar to get.
Shortcut for $self->mech->content.
Override to add performance data for time if required
Ton Voon, <ton.voon@opsera.com>
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:
You forgot a '=back' before '=head1'
To install Nagios::Plugin::WWW::Mechanize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nagios::Plugin::WWW::Mechanize
CPAN shell
perl -MCPAN -e shell install Nagios::Plugin::WWW::Mechanize
For more information on module installation, please visit the detailed CPAN module installation guide.