diff --git a/check_json.pl b/check_json.pl index fb253c9..dd22e1b 100755 --- a/check_json.pl +++ b/check_json.pl @@ -19,6 +19,7 @@ my $np = Nagios::Plugin->new( . "[ -m|--metadata ] " . "[ -T|--contenttype ] " . "[ --ignoressl ] " + . "[ -x|--xauth ] " . "[ -h|--help ] ", version => '0.5', blurb => 'Nagios plugin to check JSON attributes via http(s)', @@ -99,20 +100,29 @@ $np->add_arg( help => "--ignoressl\n Ignore bad ssl certificates", ); +$np->add_arg( + spec => 'xauth|x=s', + help => "-x|--xauth\n Use X-Auth-Token in header", +); + + ## Parse @ARGV and process standard arguments (e.g. usage, help, version) $np->getopts; if ($np->opts->verbose) { (print Dumper ($np))}; ## GET URL my $ua = LWP::UserAgent->new; - $ua->env_proxy; $ua->agent('check_json/0.5'); -$ua->default_header('Accept' => 'application/json'); +$ua->default_header('Accept' => 'application/json' ); $ua->protocols_allowed( [ 'http', 'https'] ); $ua->parse_head(0); $ua->timeout($np->opts->timeout); +if ($np->opts->xauth) { + $ua->default_header('Accept' => 'application/json', 'X-Auth-Token' => $np->opts->xauth ); +} + if ($np->opts->ignoressl) { $ua->ssl_opts(verify_hostname => 0, SSL_verify_mode => 0x00); }