1
0
mirror of https://github.com/c-kr/check_json.git synced 2024-11-23 19:03:49 +01:00

fix error if warning and/or critical not defined

Since warning and critical are not required params, we should check to see if they are defined first before looping over them.  Otherwise, we get an error in the output.
This commit is contained in:
Shaun S 2017-05-05 16:20:19 -07:00 committed by GitHub
parent 2e8e519493
commit 0ce9e7d42e

View File

@ -139,8 +139,14 @@ my $json_response = decode_json($response->content);
if ($np->opts->verbose) { (print Dumper ($json_response))}; if ($np->opts->verbose) { (print Dumper ($json_response))};
my @attributes = split(',', $np->opts->attributes); my @attributes = split(',', $np->opts->attributes);
my @warning = split(',', $np->opts->warning); my @warning;
my @critical = split(',', $np->opts->critical); if ($np->opts->warning) {
@warning = split(',', $np->opts->warning);
}
my @critical;
if ($np->opts->critical) {
@critical = split(',', $np->opts->critical);
}
my @divisor = $np->opts->divisor ? split(',',$np->opts->divisor) : () ; my @divisor = $np->opts->divisor ? split(',',$np->opts->divisor) : () ;
my %attributes = map { $attributes[$_] => { warning => $warning[$_] , critical => $critical[$_], divisor => ($divisor[$_] or 0) } } 0..$#attributes; my %attributes = map { $attributes[$_] => { warning => $warning[$_] , critical => $critical[$_], divisor => ($divisor[$_] or 0) } } 0..$#attributes;