From aa8425ab2b7a70582629c4f3a57c5be711e33eb9 Mon Sep 17 00:00:00 2001 From: stefan Date: Tue, 26 Jul 2022 14:35:51 +0200 Subject: [PATCH 1/2] Fix perf_vars and output_vars to contain correct values --- check_json.pl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/check_json.pl b/check_json.pl index 3e6ad6a..4db0484 100755 --- a/check_json.pl +++ b/check_json.pl @@ -236,15 +236,19 @@ my $label = (split('->', $key))[-1]; # make label ascii compatible $label =~ s/[^a-zA-Z0-9_-]//g ; + my $perf_value; - $perf_value = $json_response->{$key}; + my $perf_value_str = '$perf_value = $json_response->'.$key; + # $perf_value = $json_response->{$key}; + eval $perf_value_str; + if ($np->opts->verbose) { print Dumper ("JSON key: ".$label.", JSON val: " . $perf_value) }; if ( defined($perf_value) ) { # add threshold if attribute option matches key if ($attributes{$key}) { push(@statusmsg, "$label: $attributes{$key}{'check_value'}"); $np->add_perfdata( - label => lc $label, + label => lc $label value => $attributes{$key}{'check_value'}, threshold => $np->set_thresholds( warning => $attributes{$key}{'warning'}, critical => $attributes{$key}{'critical'}), ); @@ -267,8 +271,12 @@ # make label ascii compatible $label =~ s/[^a-zA-Z0-9_-]//g; my $output_value; - $output_value = $json_response->{$key}; - push(@statusmsg, "$label: $output_value"); + my $output_value_str = '$output_value = $json_response->'.$key; + eval $output_value_str; + # $output_value = $json_response->{$key}; + if ( defined($output_value) ){ + push(@statusmsg, "$label: $output_value"); + } } } From 8344937687177d23e12ff946f557c05a18f7c3e8 Mon Sep 17 00:00:00 2001 From: stefan Date: Tue, 26 Jul 2022 14:45:57 +0200 Subject: [PATCH 2/2] Fix fat finger error when saving :-( --- check_json.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_json.pl b/check_json.pl index 4db0484..16fa33d 100755 --- a/check_json.pl +++ b/check_json.pl @@ -248,7 +248,7 @@ if ($attributes{$key}) { push(@statusmsg, "$label: $attributes{$key}{'check_value'}"); $np->add_perfdata( - label => lc $label + label => lc $label, value => $attributes{$key}{'check_value'}, threshold => $np->set_thresholds( warning => $attributes{$key}{'warning'}, critical => $attributes{$key}{'critical'}), );