diff --git a/check_json.pl b/check_json.pl index d8a43e9..ae96ce7 100755 --- a/check_json.pl +++ b/check_json.pl @@ -4,10 +4,13 @@ use warnings; use strict; use HTTP::Request::Common; use LWP::UserAgent; +use URI::URL; use JSON; use Nagios::Plugin; use Data::Dumper; +my $version = '0.7'; + my $np = Nagios::Plugin->new( usage => "Usage: %s -u|--url -a|--attributes " . "[ -c|--critical ] [ -w|--warning ] " @@ -18,11 +21,12 @@ my $np = Nagios::Plugin->new( . "[ -d|--divisor ] " . "[ -m|--metadata ] " . "[ -T|--contenttype ] " + . "[ -A|--auth ] " . "[ --ignoressl ] " . "[ -A|--hattrib ] " . "[ -C|--hcon ] " . "[ -h|--help ] ", - version => '0.51', + version => $version, blurb => 'Nagios plugin to check JSON attributes via http(s)', extra => "\nExample: \n" . "check_json.pl --url http://192.168.5.10:9332/local_stats --attributes '{shares}->{dead}' " @@ -96,6 +100,12 @@ $np->add_arg( . "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( spec => 'ignoressl', help => "--ignoressl\n Ignore bad ssl certificates", @@ -127,7 +137,7 @@ if ( not $np->opts->hattrib and $np->opts->hcon) { my $ua = LWP::UserAgent->new; $ua->env_proxy; -$ua->agent('check_json/0.5'); +$ua->agent('check_json/'. $version); $ua->default_header('Accept' => 'application/json'); $ua->default_header($np->opts->hattrib => $np->opts->hcon) if ( $np->opts->hattrib and $np->opts->hcon ); $ua->protocols_allowed( [ 'http', 'https'] ); @@ -138,6 +148,12 @@ if ($np->opts->ignoressl) { $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))}; my $response;