Bug #13866
closedInvalid json in Rudder inventory hooks fails to log the problem
Description
We have an agent where an inventory hook is configured. The hook does not work, but there is no obvious message about the problem and we are not able to understand why.
The error does appear with "-i", but the provided information are not sufficient to understand what the problem is because we don't have the corresponding JSON file:
rudder info: Executing 'no timeout' ... '/opt/rudder/bin/run-inventory --local=/var/rudder/tmp/inventory/agent1-a5cedc3c-fc2c-4937-9d31-c072883b1ad3.ocs' notice: Q: "...-inventory --lo": [info] FusionInventory instance: builtin - Perl instance: system Q: "...-inventory --lo": [info] running task Inventory Q: "...-inventory --lo": [error] Script /var/rudder/hooks.d/mount.sh didn't return valid JSON entry, error is:malformed JSON string, neither array, object, number, string or atom, at character offset 25 (before "] }\n") at /opt/rudder/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/Generic/Rudder.pm line 125. Q: "...-inventory --lo": [info] Inventory saved in /var/rudder/tmp/inventory/agent1-a5cedc3c-fc2c-4937-9d31-c072883b1ad3.ocs
=> perhaps we should have a log info or something for each inventory hook with a problem so that people can find easely that it was ignored by design
=> when an inventory hook has a problem, the corresponding JSON should be put somewhere so that the user can try to understand what goes wrong in his script.
Workaround for the second point: change file /opt/rudder/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/Generic/Rudder.pm around line 125 like that:
if ($@) { $logger->error("Script $script_file didn't return valid JSON entry, error is:$@") if $logger; # add that line $logger->error("JSON in error is: $properties") if $logger; }
Updated by Vincent MEMBRÉ almost 6 years ago
- Target version changed from 4.1.17 to 4.1.18
Updated by François ARMAND almost 6 years ago
The problem seems to lie in `Rudder.pm`.
Following script works as expected:
#!/bin/bash JSON_RESULT=$(/opt/admin/bin/osqueryi --json "SELECT device, device_alias, path, flags FROM mounts WHERE type = 'xfs' OR type like '%ext%';" | jq '{"mounts": .}') echo $JSON_RESULT
This one doesn't:
#!/bin/bash command_exists () { command -v $1 >/dev/null 2>&1; } if command_exists osqueryi && command_exists jq; then JSON_RESULT=$(/opt/admin/bin/osqueryi --json "SELECT device, device_alias, path, flags FROM mounts WHERE type = 'xfs' OR type like '%ext%';" | jq '{"mounts": .}') echo $JSON_RESULT fi
With that error:
Q: "...-inventory --lo": [error] Script /var/rudder/hooks.d/mounts.sh didn't return valid JSON entry, error is:malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at /opt/rudder/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/Generic/Rudder.pm line 127. Q: "...-inventory --lo": [error] JSON in error is:
=> variable `$properties` is empty
if ($@) { $logger->error("Script $script_file didn't return valid JSON entry, error is:$@") if $logger; #print Dumper($properties); $logger->error("JSON in error is: $properties") if $logger; }
And with that log, we can see it is already empty here:
Rudder.pm
...
eval {
my $package = "JSON::PP";
$package->require();
if ($EVAL_ERROR) {
print STDERR
"Failed to load JSON module: ($EVAL_ERROR)\n";
next;
}
my $coder = JSON::PP->new;
print Dumper($properties);
my $propertiesData = $coder->decode($properties);
push custom_properties_list, $coder->encode($propertiesData);
};
if ($
) {
$logger->error("Script $script_file didn't return valid JSON entry, error is:$@") if $logger;
print Dumper($properties);
$logger->error("JSON in error is: $properties") if $logger;
}
...
Gives output:
Q: "...-inventory --lo": [error] Script /var/rudder/hooks.d/mounts.sh didn't return valid JSON entry, error is:malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at /opt/rudder/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/Generic/Rudder.pm line 127. Q: "...-inventory --lo": [error] JSON in error is: Q: "...-inventory --lo": $VAR1 = ''; Q: "...-inventory --lo": $VAR1 = '';
Updated by Benoît PECCATTE almost 6 years ago
- Severity set to Major - prevents use of part of Rudder | no simple workaround
- User visibility set to Infrequent - complex configurations | third party integrations
- Priority changed from 0 to 41
Updated by Vincent MEMBRÉ almost 6 years ago
- Target version changed from 4.1.18 to 4.1.19
- Priority changed from 41 to 40
Updated by Alexis Mousset almost 6 years ago
- Target version changed from 4.1.19 to 4.1.20
Updated by François ARMAND almost 6 years ago
- Translation missing: en.field_tag_list set to Sponsored
- Priority changed from 40 to 72
Updated by François ARMAND almost 6 years ago
- Target version changed from 4.1.20 to 4.3.10
- User visibility changed from Infrequent - complex configurations | third party integrations to Operational - other Techniques | Rudder settings | Plugins
- Priority changed from 72 to 82
Updated by François ARMAND almost 6 years ago
- Assignee set to Benoît PECCATTE
- Priority changed from 82 to 81
Updated by François ARMAND over 5 years ago
- Target version changed from 4.3.10 to 4.3.11
Updated by Vincent MEMBRÉ over 5 years ago
- Target version changed from 4.3.11 to 4.3.12
- Priority changed from 81 to 79
Updated by Vincent MEMBRÉ over 5 years ago
- Target version changed from 4.3.12 to 4.3.13
- Priority changed from 79 to 78
Updated by Vincent MEMBRÉ over 5 years ago
- Target version changed from 4.3.13 to 4.3.14
Updated by Benoît PECCATTE over 5 years ago
- Status changed from New to In progress
- Priority changed from 78 to 77
Updated by Benoît PECCATTE over 5 years ago
- Status changed from In progress to Pending technical review
- Assignee changed from Benoît PECCATTE to Alexis Mousset
- Pull Request set to https://github.com/Normation/rudder-packages/pull/1957
Updated by Vincent MEMBRÉ over 5 years ago
- Target version changed from 4.3.14 to 587
- Priority changed from 77 to 76
Updated by Vincent MEMBRÉ over 5 years ago
- Target version changed from 587 to 4.3.14
- Priority changed from 76 to 75
Updated by Alexis Mousset over 5 years ago
- Target version changed from 4.3.14 to 5.0.13
Updated by Vincent MEMBRÉ about 5 years ago
- Target version changed from 5.0.13 to 5.0.14
- Priority changed from 75 to 73
Updated by Benoît PECCATTE about 5 years ago
- Pull Request changed from https://github.com/Normation/rudder-packages/pull/1957 to https://github.com/Normation/rudder-packages/pull/2100
Updated by Benoît PECCATTE about 5 years ago
- Status changed from Pending technical review to Pending release
Applied in changeset rudder-packages|636878694765963209c062defa029c176e12a84d.
Updated by Alexis Mousset about 5 years ago
- Name check changed from To do to Reviewed
Updated by Nicolas CHARLES about 5 years ago
- Priority changed from 72 to 71
- Fix check changed from To do to Checked
Updated by Vincent MEMBRÉ about 5 years ago
- Status changed from Pending release to Released
This bug has been fixed in Rudder 5.0.14 which was released today.