-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unable to output perfdata from traversed object #23
Comments
Got the same issues :
Check JSON status API UNKNOWN - No value received |
Got the same issue too. |
This happens because $json_response contains the structured JSON response, but the script tries to pull data out of it using the raw user-provided key. For example, it tries to look up $json_response->{'{foo}->{bar}'} instead of $json_response->{'foo'}->{'bar'}. I've created a patch that partially fixes it, but I'm holding off on actually making a pull request until I have '-o *' support working. |
I created a patch this morning and submitted a PR, without realizing this conversation had taken place. I haven't tested the patch with "*" though. |
I never got around implementing a way for -o to pull individual things out of arrays because I fixed it as much as I needed (to pull individual keys out of deeply-nested data from PaperCut), but feel free to take what you need from https://github.com/waoki/check_json. I can create a PR if that would be helpful. |
Neither of those two solutions work for me. They don't seem to be working with arrays. The only way I made it work was to change it to this:
E.g if you have something like:
Then The fun part is that this works for this prefvalue: |
I also think this behavior is weird, but maybe it's just me being tired or not understanding how perl works at all. I tried adding all perfdata keys to attributes, which – for reasons I don't understand – seems to work, but then:
Why does the actual value change when I change the value of |
It's been a while since I looked at it, but yes, that's the kind of structure I was thinking about. It looks like I started working on it, but then had to set it aside and never came back to it. I have these uncommitted changes sitting locally which look like initial work on the problem: diff --git a/check_json.pl b/check_json.pl
index 39ffecf..b37a944 100755
--- a/check_json.pl
+++ b/check_json.pl
@@ -256,7 +256,8 @@ if ($np->opts->perfvars) {
# recurse_json($json_data, \&callback);
# recurse_json($json_data, \&callback, $path);
-# Invokes &callback for every terminal node in $json_data.
+# Invokes &callback for every terminal node in $json_data, unless it
+# is an array of scalars. This is needed for pretty-printing.
# &callback is passed the name and the value of the leaf, i.e.
# callback($label, $value)
# If $path is defined, recurse_json prepends it to $label. When recursing,
@@ -273,6 +274,18 @@ sub recurse_json {
} elsif (ref($ptr) eq 'ARRAY') {
@k = keys(@$ptr);
}
+
+ # If it's an array, do we need to recurse? Unfortunately, we must check
+ # whole structure first so we can make the right decision.
+ if (ref($ptr) eq 'ARRAY') {
+ foreach my $i (@k) {
+ if (ref($ptr->[$i])) {
+ &callback($path, $ptr);
+ return;
+ }
+ }
+ }
+
foreach my $i (@k) {
my $p = $path;
if (defined($p) && $p ne '') {
@@ -342,8 +355,7 @@ if ($np->opts->outputvars) {
}
}
- # depending on desired behavior, this could just be ref($ptr)
- if (ref($ptr) eq 'HASH') {
+ if (ref($ptr)) {
recurse_json($ptr, sub {
push(@statusmsg, format_output(@_));
}, ''); |
I have same issue, anyone got the right fix? |
I am checking a value nested in an array (eg. the same thing that was broken and later fixed in issue #21 ) and the checking itself, complete with thresholds logic, seems to be working ok:
But I'm not able to get the same value in outputvars, and the scripts returns this warning:
And I cannot get the values in perfdata too, but this time without any warning:
The text was updated successfully, but these errors were encountered: