From 0ce9e7d42e2179b850bb624715c94675f8b41e14 Mon Sep 17 00:00:00 2001 From: Shaun S Date: Fri, 5 May 2017 16:20:19 -0700 Subject: [PATCH] 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. --- check_json.pl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/check_json.pl b/check_json.pl index fb253c9..2330f63 100755 --- a/check_json.pl +++ b/check_json.pl @@ -139,8 +139,14 @@ my $json_response = decode_json($response->content); if ($np->opts->verbose) { (print Dumper ($json_response))}; my @attributes = split(',', $np->opts->attributes); -my @warning = split(',', $np->opts->warning); -my @critical = split(',', $np->opts->critical); +my @warning; +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 %attributes = map { $attributes[$_] => { warning => $warning[$_] , critical => $critical[$_], divisor => ($divisor[$_] or 0) } } 0..$#attributes;