From 1cf1f9c2982b83d46d3d8d21bc1fd6b0c83d6222 Mon Sep 17 00:00:00 2001 From: Alan Hodgson Date: Wed, 16 Dec 2015 10:12:56 -0800 Subject: [PATCH 1/3] Escape @host in text string. --- check_json.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_json.pl b/check_json.pl index a113755..abdb764 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 ] " From f3233fb247099a6072397f13c007f22a9aa00826 Mon Sep 17 00:00:00 2001 From: Alan Hodgson Date: Wed, 16 Dec 2015 10:53:38 -0800 Subject: [PATCH 2/3] Fully specify hash reference to find $attribute. --- check_json.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check_json.pl b/check_json.pl index abdb764..5d16d81 100755 --- a/check_json.pl +++ b/check_json.pl @@ -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; From 34d7d3a1b0545fca84eeb959d05823689dde1f19 Mon Sep 17 00:00:00 2001 From: Alan Hodgson Date: Wed, 16 Dec 2015 11:27:40 -0800 Subject: [PATCH 3/3] Fix output and performance output values. --- check_json.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/check_json.pl b/check_json.pl index 5d16d81..95553e4 100755 --- a/check_json.pl +++ b/check_json.pl @@ -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"); } }