[Nagiosplug-devel] multiple options with same argument.
shadih rahman
shadhin71 at gmail.com
Wed Jul 8 23:27:01 CEST 2009
All,
how do you parse multiple of same argument in Nagios::Plungin. I am
calling my check as this
perl check_htturl -H wind.columbia.edu -u username -p pass -P /login -q me
-q you
when I print -q it should print me&you but its not doing that. This is my
code. Please advise on this. Thanks
#!/usr/bin/perl -w
=head1 NAME
check_httpurl - Check httpurl with sequential query.
=head1 AUTHOR
Shadhin Rahman <sr2690 at columbia.edu>
=head1 SYNOPSYS
This particular plugin can do sequential query upon first query, ideal for
CAS type authentication check
=head1 REQUIRES
Perl5.004, strict, URI, Nagios::Plugin, HTTP::Request::Common,
LWP::UserAgent
=head1 EXPORTS
Nothing
=head1 DESCRIPTION
OK if response code is 200 and regex checks succeed, or
if response code is 200 and no regex checks were specified
UNKNOWN if HTTP response status code class is not recognized
WARNING if HTTP response status code is class 1xx or 3xx
CRITICAL if HTTP response status code is class 4xx or 5xx,
or if class is 200 and $matchregex not found
or if class is 200 and $errorregex is found
=cut
use warnings;
use strict;
no warnings qw( redefine prototype );
BEGIN {
use Nagios::Plugin;
use URI;
use HTTP::Request::Common;
use LWP::UserAgent;
} # END BEGIN
my( $usagemsg ) = <<USAGE;
Usage: %s -H <hostname> [-w <warning seconds>] [-c <critical seconds>][-v|d]
[-h]
USAGE
my( $blurb ) = <<BLURB;
This particular plugin can do sequential query upon first query, ideal for
CAS type authentication check
BLURB
my( $license ) = <<LICENSE;
Copyright (c) 2008 - 2009
LICENSE
Nagios::Plugin->new(
usage => "Usage: %s [ -v|--verbose ] [-H <host>] "
. "[ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]",
);
my( $plugin ) = Nagios::Plugin->new(
shortname => 'check_httpurl',
usage => $usagemsg,
version => '0.2',
blurb => $blurb,
license => $license,
);
=head2 Plugin Metadata
Metadata is documented in L<Nagios::Plugin> and L<Nagios::Plugin::Getopt>.
Other available options of interest include C<url>, C<extra>, and
C<timeout>.
=cut
$plugin->add_arg(
spec => 'hostname|H=s',
help => [
"Hostname to query",
"IP address to query",
],
label => [ 'HOSTNAME', 'IP' ],
required => 1,
);
$plugin->add_arg(
spec => 'ssl|S=s',
help => [
"confifrms ssl
transmission",
],
label => [ 'SSL' ],
required => 0,
);
$plugin->add_arg(
spec => 'username|u=s',
help => "username for authentication",
label => [ 'username' ],
required => 1,
);
$plugin->add_arg(
spec => 'password|p=s',
help => "password for authentication",
label => [ 'password' ],
required => 1,
);
$plugin->add_arg(
spec => 'url|P=s',
help => "path of the url",
label => [ 'path' ],
required => 1,
);
$plugin->add_arg(
spec => 'query|q=s',
help => "additional query to inject",
label => [ 'query' ],
required => 0,
);
$plugin->add_arg(
spec => 'regex|r=s',
help => "regex to match",
label => [ 'regex' ],
required => 0,
);
$plugin->getopts;
my ( $opts ) =$plugin->opts;
my ( $server, $username, $password, $path, $query, $regex );
$server=$opts->get('hostname');
$username = $opts->get('username');
$password=$opts->get('password');
$path=$opts->get('url');
if ( $query = $opts->get( 'query' ) ) {
$query=join ( '&', $opts->get('query') );
}
$regex=$opts->get('regex');
print $query ."\n";
--
Cordially,
Shadhin Rahman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20090708/2ab5cf94/attachment.html>
More information about the Devel
mailing list