mirror of
https://github.com/c-kr/check_json.git
synced 2024-11-23 19:03:49 +01:00
Add support for supplying basic auth parameters in a separate argument
This commit is contained in:
parent
2e8e519493
commit
baeddb24e4
@ -4,6 +4,7 @@ use warnings;
|
|||||||
use strict;
|
use strict;
|
||||||
use HTTP::Request::Common;
|
use HTTP::Request::Common;
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
|
use URI::URL;
|
||||||
use JSON;
|
use JSON;
|
||||||
use Nagios::Plugin;
|
use Nagios::Plugin;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
@ -18,9 +19,10 @@ my $np = Nagios::Plugin->new(
|
|||||||
. "[ -d|--divisor <divisor> ] "
|
. "[ -d|--divisor <divisor> ] "
|
||||||
. "[ -m|--metadata <content> ] "
|
. "[ -m|--metadata <content> ] "
|
||||||
. "[ -T|--contenttype <content-type> ] "
|
. "[ -T|--contenttype <content-type> ] "
|
||||||
|
. "[ -A|--auth <username:password> ] "
|
||||||
. "[ --ignoressl ] "
|
. "[ --ignoressl ] "
|
||||||
. "[ -h|--help ] ",
|
. "[ -h|--help ] ",
|
||||||
version => '0.5',
|
version => '0.6',
|
||||||
blurb => 'Nagios plugin to check JSON attributes via http(s)',
|
blurb => 'Nagios plugin to check JSON attributes via http(s)',
|
||||||
extra => "\nExample: \n"
|
extra => "\nExample: \n"
|
||||||
. "check_json.pl --url http://192.168.5.10:9332/local_stats --attributes '{shares}->{dead}' "
|
. "check_json.pl --url http://192.168.5.10:9332/local_stats --attributes '{shares}->{dead}' "
|
||||||
@ -94,6 +96,12 @@ $np->add_arg(
|
|||||||
. "Content-type accepted if different from application/json ",
|
. "Content-type accepted if different from application/json ",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$np->add_arg(
|
||||||
|
spec => 'auth|A=s',
|
||||||
|
help => '-A, --auth realm:username:password',
|
||||||
|
required => 0,
|
||||||
|
);
|
||||||
|
|
||||||
$np->add_arg(
|
$np->add_arg(
|
||||||
spec => 'ignoressl',
|
spec => 'ignoressl',
|
||||||
help => "--ignoressl\n Ignore bad ssl certificates",
|
help => "--ignoressl\n Ignore bad ssl certificates",
|
||||||
@ -107,7 +115,7 @@ if ($np->opts->verbose) { (print Dumper ($np))};
|
|||||||
my $ua = LWP::UserAgent->new;
|
my $ua = LWP::UserAgent->new;
|
||||||
|
|
||||||
$ua->env_proxy;
|
$ua->env_proxy;
|
||||||
$ua->agent('check_json/0.5');
|
$ua->agent('check_json/0.6');
|
||||||
$ua->default_header('Accept' => 'application/json');
|
$ua->default_header('Accept' => 'application/json');
|
||||||
$ua->protocols_allowed( [ 'http', 'https'] );
|
$ua->protocols_allowed( [ 'http', 'https'] );
|
||||||
$ua->parse_head(0);
|
$ua->parse_head(0);
|
||||||
@ -117,6 +125,12 @@ if ($np->opts->ignoressl) {
|
|||||||
$ua->ssl_opts(verify_hostname => 0, SSL_verify_mode => 0x00);
|
$ua->ssl_opts(verify_hostname => 0, SSL_verify_mode => 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($np->opts->auth) {
|
||||||
|
my @credentials = split(':', $np->opts->auth);
|
||||||
|
my $url = url $np->opts->url;
|
||||||
|
$ua->credentials($url->host . ':' . $url->port, $credentials[0], $credentials[1], $credentials[2]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($np->opts->verbose) { (print Dumper ($ua))};
|
if ($np->opts->verbose) { (print Dumper ($ua))};
|
||||||
|
|
||||||
my $response;
|
my $response;
|
||||||
|
Loading…
Reference in New Issue
Block a user