From f6d603b6e7a2682f7932aa3008c43fdafbb75ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Szewczak?= Date: Thu, 24 May 2018 09:33:44 +0100 Subject: [PATCH] added x-auth option --- check_json.pl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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); }