1
0
mirror of https://github.com/c-kr/check_json.git synced 2024-11-23 10:53:47 +01:00

Merge pull request #18 from AlanHodgson/master

Changes needed to make it work at all in my environment
This commit is contained in:
Christopher Kreft 2016-03-14 13:46:24 +01:00
commit c24e265ccc

View File

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