1
0
mirror of https://github.com/c-kr/check_json.git synced 2024-11-23 19:03:49 +01:00

Added ability to add an additional header via -A and -C

I needed to pass an auth token to the server, so I added a parameter for attribute and content of an additional header such as:

 -A "authorization" -C "Basic AUTHKEYREDACTED" 

...to represent the header:
"authorization: Basic AUTHKEYREDACTED"
This commit is contained in:
bchabot 2017-08-30 15:30:18 -04:00 committed by GitHub
parent 2e8e519493
commit a59fc0a279

View File

@ -19,8 +19,10 @@ my $np = Nagios::Plugin->new(
. "[ -m|--metadata <content> ] " . "[ -m|--metadata <content> ] "
. "[ -T|--contenttype <content-type> ] " . "[ -T|--contenttype <content-type> ] "
. "[ --ignoressl ] " . "[ --ignoressl ] "
. "[ -A|--hattrib <value> ] "
. "[ -C|--hcon <value> ] "
. "[ -h|--help ] ", . "[ -h|--help ] ",
version => '0.5', version => '0.51',
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}' "
@ -99,6 +101,17 @@ $np->add_arg(
help => "--ignoressl\n Ignore bad ssl certificates", help => "--ignoressl\n Ignore bad ssl certificates",
); );
$np->add_arg(
spec => 'hattrib|A=s',
help => "-A, --header-attrib STRING \n "
. "Additional Header attribute.",
);
$np->add_arg(
spec => 'hcon|C=s',
help => "-C, --header-content STRING \n "
. "Additional Header content.",
);
## Parse @ARGV and process standard arguments (e.g. usage, help, version) ## Parse @ARGV and process standard arguments (e.g. usage, help, version)
$np->getopts; $np->getopts;
if ($np->opts->verbose) { (print Dumper ($np))}; if ($np->opts->verbose) { (print Dumper ($np))};
@ -109,6 +122,7 @@ my $ua = LWP::UserAgent->new;
$ua->env_proxy; $ua->env_proxy;
$ua->agent('check_json/0.5'); $ua->agent('check_json/0.5');
$ua->default_header('Accept' => 'application/json'); $ua->default_header('Accept' => 'application/json');
$ua->default_header($np->opts->hattrib => $np->opts->hcon);
$ua->protocols_allowed( [ 'http', 'https'] ); $ua->protocols_allowed( [ 'http', 'https'] );
$ua->parse_head(0); $ua->parse_head(0);
$ua->timeout($np->opts->timeout); $ua->timeout($np->opts->timeout);