From db0bbef0305c3910877e8d4b3aa6a87663286b57 Mon Sep 17 00:00:00 2001 From: locutus304 Date: Thu, 11 Dec 2014 10:32:39 -0600 Subject: [PATCH] Update check_json.pl Added "metadata" option to enable sending additional RESTful request parameters to server. --- check_json.pl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/check_json.pl b/check_json.pl index 0f48b3d..02f9a6f 100755 --- a/check_json.pl +++ b/check_json.pl @@ -2,6 +2,7 @@ use warnings; use strict; +use HTTP::Request::Common; use LWP::UserAgent; use JSON; use Nagios::Plugin; @@ -14,6 +15,7 @@ my $np = Nagios::Plugin->new( . "[ -o|--outputvars ] " . "[ -t|--timeout ] " . "[ -d|--divisor ] " + . "[ -m|--metadata ] " . "[ -T|--contenttype ] " . "[ --ignoressl ] " . "[ -h|--help ] ", @@ -73,6 +75,12 @@ $np->add_arg( . "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( spec => 'contenttype|T=s', default => 'application/json', @@ -104,7 +112,12 @@ if ($np->opts->ignoressl) { 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->header("content-type") =~ $np->opts->contenttype)) {