1Nagios::Plugin::WWW::MeUcshearniCzoen(t3r)ibuted Perl DoNcaugmieonst:a:tPiloungin::WWW::Mechanize(3)
2
3
4
6 Nagios::Plugin::WWW::Mechanize - Login to a web page as a user and get
7 data as a Nagios plugin
8
10 use Nagios::Plugin::WWW::Mechanize;
11 $np = Nagios::Plugin::WWW::Mechanize->new(
12 usage => "Checks number of mailing list users"
13 );
14 $np->getopts;
15
16 $np->get( "http://lists.opsview.org/lists/admin/opsview-users/members" );
17 $np->submit_form( form_name => "f", fields => { adminpw => "****" } );
18 $content = $np->content;
19 ($number_of_users) = ($content =~ /(\d+) members total/);
20 $np->nagios_exit( CRITICAL, "Cannot get number of users" ) unless defined $number_of_users;
21
22 $np->add_perfdata(
23 label => "users",
24 value => $number_of_users,
25 );
26 $np->nagios_exit(
27 OK,
28 "Number of mailing list users: $number_of_users"
29 );
30
32 This module ties Nagios::Plugin with WWW::Mechanize so that there's
33 less code in your perl script and the most common work is done for you.
34
35 For example, the plugin will automatically call nagios_exit(CRITICAL,
36 ...) if a page is unavailable or a submit_form fails. The plugin will
37 also keep a track of the time for responses from the remote web server
38 and output that as performance data.
39
41 Nagios::Plugin::WWW::Mechanize->new( %opts )
42 Takes %opts. If $opts{mech} is specified and is an object, will
43 check if it is a WWW::Mechanize object and die if not. If
44 $opts{mech} is a hash ref, will pass those to a
45 WWW::Mechanize->new() call. Will create a WWW::Mechanize object
46 with autocheck => 0, otherwise any failures are exited immediately.
47
48 Also looks for $opts{include_time}. Defaults to 1 which means that
49 performance data for time will be returned.
50
51 All other options are passed to Nagios::Plugin.
52
54 mech
55 Returns the WWW::Mechanize object
56
57 get( @args )
58 Calls $self->mech->get( @args ). If $self->include_time is set,
59 will start a timer before the get, calculate the duration, and adds
60 it to a total timer.
61
62 If the mech->get call failed, will call nagios_exit with a CRITICAL
63 error.
64
65 Returns the value from mech->get.
66
67 submit_form( @args )
68 Similar to get.
69
70 content
71 Shortcut for $self->mech->content.
72
73 nagios_exit
74 Override to add performance data for time if required
75
77 Ton Voon, <ton.voon@opsera.com>
78
80 Copyright (C) 2006-2009 Opsera Limited. All rights reserved
81
82 This library is free software; you can redistribute it and/or modify it
83 under the same terms as Perl itself, either Perl version 5.8.4 or, at
84 your option, any later version of Perl 5 you may have available.
85
87 Hey! The above document had some coding errors, which are explained
88 below:
89
90 Around line 116:
91 You forgot a '=back' before '=head1'
92
93 Around line 188:
94 You forgot a '=back' before '=head1'
95
96
97
98perl v5.32.1 2021-01-27 Nagios::Plugin::WWW::Mechanize(3)