diff --git a/README.md b/README.md index 92814a8..96b71dc 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Performance data is also enhanced to extract performance data compliant to Nagio Usage: ``` -check_json -u|--url -a|--attribute [ -c|--critical ] [ -w|--warning ] [ -p|--perfvars ] [ -t|--timeout ] [ -d|--divisor ] [ -h|--help ] +check_json -u|--url -a|--attribute [ -c|--critical ] [ -w|--warning ] [ -p|--perfvars ] [ -t|--timeout ] [ -d|--divisor ] [ -T|--contenttype ] [ -h|--help ] ``` Example: @@ -22,3 +22,9 @@ Result: Check JSON status API OK - dead_shares: 2, live_shares: 12, clients_connected: 234 | dead_shares=2;5;10 live_shares=12 clients_connected=234 ``` +Requirements +============ + +Perl JSON package + +* Debian : libjson-perl diff --git a/check_json.pl b/check_json.pl index 638e880..2566382 100755 --- a/check_json.pl +++ b/check_json.pl @@ -13,6 +13,7 @@ my $np = Nagios::Plugin->new( . "[ -p|--perfvars ] " . "[ -t|--timeout ] " . "[ -d|--divisor ] " + . "[ -T|--contenttype ] " . "[ -h|--help ] ", version => '0.2', blurb => 'Nagios plugin to check JSON attributes via http(s)', @@ -52,12 +53,20 @@ $np->add_arg( . 'http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT ' . 'for the threshold format. ', ); + $np->add_arg( spec => 'perfvars|p=s', help => '-p, --perfvars . CSV list of fields from JSON response to include in perfdata ' . '{shares}->{dead},{shares}->{live}', ); +$np->add_arg( + spec => 'contenttype|T=s', + default => 'application/json', + help => '-T, --contenttype . content-type accepted if different from application/json ', +); + + ## Parse @ARGV and process standard arguments (e.g. usage, help, version) $np->getopts; if ($np->opts->verbose) { (print Dumper ($np))}; @@ -75,7 +84,7 @@ if ($np->opts->verbose) { (print Dumper ($ua))}; my $response = ($ua->get($np->opts->url)); if ($response->is_success) { - if (!($response->header("content-type") =~ 'application/json')) { + if (!($response->header("content-type") =~ $np->opts->contenttype)) { $np->nagios_exit(UNKNOWN,"Content type is not JSON: ".$response->header("content-type")); } } else {