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