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

Added divisor, fixed help text

This commit is contained in:
Christopher Kreft 2013-04-28 20:30:44 +02:00
parent 45d107edc1
commit 59754e1b8c

View File

@ -15,8 +15,7 @@ my $np = Nagios::Plugin->new(
blurb => 'Nagios plugin to check JSON attributes via http(s)',
extra => "\nExample: \n"
. "check_json.pl -U http://192.168.5.10:9332/local_stats -a '{shares}->{dead}' -w :5 -c :10",
url => 'url',
license => 'GPLv2',
url => 'https://github.com/c-kr/check_json',
plugin => 'check_json',
timeout => 15,
);
@ -32,6 +31,10 @@ $np->add_arg(
help => '-a, --attribute {shares}->{dead}',
required => 1,
);
$np->add_arg(
spec => 'divisor|D=i',
help => '-D, --divisor 1000000',
);
$np->add_arg(
spec => 'warning|w=s',
help => '-w, --warning INTEGER:INTEGER . See '
@ -52,7 +55,7 @@ $np->getopts;
## GET URL
my $ua = LWP::UserAgent->new;
$ua->agent('Redirect Bot');
$ua->agent('check_json/0.1');
$ua->protocols_allowed( [ 'http', 'https'] );
$ua->parse_head(0);
$ua->timeout($np->opts->timeout);
@ -60,7 +63,7 @@ $ua->timeout($np->opts->timeout);
my $response = ($ua->get($np->opts->URL));
if ($response->is_success) {
if ($response->header("content-type") ne 'application/json') {
if (!($response->header("content-type") =~ 'application/json')) {
$np->nagios_exit(UNKNOWN,"Content type is not JSON: ".$response->header("content-type"));
}
} else {
@ -79,6 +82,10 @@ if (!defined $value) {
$np->nagios_exit(UNKNOWN, "No value received");
}
if (defined $np->opts->divisor) {
$value = $value/$np->opts->divisor;
}
$np->add_perfdata(
label => 'value',
value => $value,