diff --git a/check_json.pl b/check_json.pl index a113755..95553e4 100755 --- a/check_json.pl +++ b/check_json.pl @@ -9,7 +9,7 @@ use Nagios::Plugin; use Data::Dumper; my $np = Nagios::Plugin->new( - usage => "Usage: %s -u|--url -a|--attributes " + usage => "Usage: %s -u|--url -a|--attributes " . "[ -c|--critical ] [ -w|--warning ] " . "[ -p|--perfvars ] " . "[ -o|--outputvars ] " @@ -145,8 +145,8 @@ my $resultTmp; foreach my $attribute (sort keys %attributes){ my $check_value; - my $check_value_str = '$check_value = $json_response->'.$attribute; - + my $check_value_str = '$check_value = $json_response->{\'' . $attribute . '\'}'; + if ($np->opts->verbose) { (print Dumper ($check_value_str))}; eval $check_value_str; @@ -208,7 +208,7 @@ if ($np->opts->perfvars) { # make label ascii compatible $label =~ s/[^a-zA-Z0-9_-]//g ; my $perf_value; - $perf_value = eval '$json_response->'.$key; + $perf_value = $json_response->{$key}; if ($np->opts->verbose) { print Dumper ("JSON key: ".$label.", JSON val: " . $perf_value) }; if ( defined($perf_value) ) { # add threshold if attribute option matches key @@ -237,9 +237,9 @@ if ($np->opts->outputvars) { my $label = (split('->', $key))[-1]; # make label ascii compatible $label =~ s/[^a-zA-Z0-9_-]//g; - my $perf_value; - $perf_value = eval '$json_response->'.$key; - push(@statusmsg, "$label: $perf_value"); + my $output_value; + $output_value = $json_response->{$key}; + push(@statusmsg, "$label: $output_value"); } }