1
0
mirror of https://github.com/c-kr/check_json.git synced 2024-11-23 10:53:47 +01:00

Update check_json.pl

Added "metadata" option to enable sending additional RESTful request parameters to server.
This commit is contained in:
locutus304 2014-12-11 10:32:39 -06:00
parent b327672da1
commit db0bbef030

View File

@ -2,6 +2,7 @@
use warnings; use warnings;
use strict; use strict;
use HTTP::Request::Common;
use LWP::UserAgent; use LWP::UserAgent;
use JSON; use JSON;
use Nagios::Plugin; use Nagios::Plugin;
@ -14,6 +15,7 @@ my $np = Nagios::Plugin->new(
. "[ -o|--outputvars <fields> ] " . "[ -o|--outputvars <fields> ] "
. "[ -t|--timeout <timeout> ] " . "[ -t|--timeout <timeout> ] "
. "[ -d|--divisor <divisor> ] " . "[ -d|--divisor <divisor> ] "
. "[ -m|--metadata <content> ] "
. "[ -T|--contenttype <content-type> ] " . "[ -T|--contenttype <content-type> ] "
. "[ --ignoressl ] " . "[ --ignoressl ] "
. "[ -h|--help ] ", . "[ -h|--help ] ",
@ -73,6 +75,12 @@ $np->add_arg(
. "CSV list of fields output in status message, same syntax as perfvars" . "CSV list of fields output in status message, same syntax as perfvars"
); );
$np->add_arg(
spec => 'metadata|m=s',
help => "-m|--metadata \'{\"name\":\"value\"}\'\n "
. "RESTful request metadata in JSON format"
);
$np->add_arg( $np->add_arg(
spec => 'contenttype|T=s', spec => 'contenttype|T=s',
default => 'application/json', default => 'application/json',
@ -104,7 +112,12 @@ if ($np->opts->ignoressl) {
if ($np->opts->verbose) { (print Dumper ($ua))}; if ($np->opts->verbose) { (print Dumper ($ua))};
my $response = ($ua->get($np->opts->url)); my $response;
if ($np->opts->metadata) {
$response = $ua->request(GET $np->opts->url, 'Content-type' => 'application/json', 'Content' => $np->opts->metadata );
} else {
$response = $ua->request(GET $np->opts->url);
}
if ($response->is_success) { if ($response->is_success) {
if (!($response->header("content-type") =~ $np->opts->contenttype)) { if (!($response->header("content-type") =~ $np->opts->contenttype)) {