mirror of
https://github.com/c-kr/check_json.git
synced 2024-11-23 10:53:47 +01:00
Merge pull request #5 from rodo/master
Add option -T|contenttype to specify alternative content-type
This commit is contained in:
commit
1cd13015dc
@ -9,7 +9,7 @@ Performance data is also enhanced to extract performance data compliant to Nagio
|
||||
|
||||
Usage:
|
||||
```
|
||||
check_json -u|--url <URL> -a|--attribute <attribute> [ -c|--critical <threshold> ] [ -w|--warning <threshold> ] [ -p|--perfvars <fields> ] [ -t|--timeout <timeout> ] [ -d|--divisor <divisor> ] [ -h|--help ]
|
||||
check_json -u|--url <URL> -a|--attribute <attribute> [ -c|--critical <threshold> ] [ -w|--warning <threshold> ] [ -p|--perfvars <fields> ] [ -t|--timeout <timeout> ] [ -d|--divisor <divisor> ] [ -T|--contenttype <content-type> ] [ -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
|
||||
|
@ -13,6 +13,7 @@ my $np = Nagios::Plugin->new(
|
||||
. "[ -p|--perfvars <fields> ] "
|
||||
. "[ -t|--timeout <timeout> ] "
|
||||
. "[ -d|--divisor <divisor> ] "
|
||||
. "[ -T|--contenttype <content-type> ] "
|
||||
. "[ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user