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; }