Project

General

Profile

Actions

Bug #13866

closed

Invalid json in Rudder inventory hooks fails to log the problem

Added by François ARMAND over 5 years ago. Updated almost 2 years ago.

Status:
Released
Priority:
N/A
Category:
Web - Nodes & inventories
Target version:
Severity:
Major - prevents use of part of Rudder | no simple workaround
UX impact:
User visibility:
Operational - other Techniques | Rudder settings | Plugins
Effort required:
Priority:
74
Name check:
Reviewed
Fix check:
Checked
Regression:

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;
}
Actions #1

Updated by Vincent MEMBRÉ over 5 years ago

  • Target version changed from 4.1.17 to 4.1.18
Actions #2

Updated by François ARMAND over 5 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 = '';
Actions #3

Updated by Benoît PECCATTE over 5 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
Actions #4

Updated by Vincent MEMBRÉ over 5 years ago

  • Target version changed from 4.1.18 to 4.1.19
  • Priority changed from 41 to 40
Actions #5

Updated by Alexis Mousset about 5 years ago

  • Target version changed from 4.1.19 to 4.1.20
Actions #6

Updated by François ARMAND about 5 years ago

  • Translation missing: en.field_tag_list set to Sponsored
  • Priority changed from 40 to 72
Actions #7

Updated by François ARMAND about 5 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
Actions #8

Updated by François ARMAND about 5 years ago

  • Assignee set to Benoît PECCATTE
  • Priority changed from 82 to 81
Actions #9

Updated by François ARMAND about 5 years ago

  • Target version changed from 4.3.10 to 4.3.11
Actions #10

Updated by Vincent MEMBRÉ about 5 years ago

  • Target version changed from 4.3.11 to 4.3.12
  • Priority changed from 81 to 79
Actions #11

Updated by Vincent MEMBRÉ almost 5 years ago

  • Target version changed from 4.3.12 to 4.3.13
  • Priority changed from 79 to 78
Actions #12

Updated by Vincent MEMBRÉ almost 5 years ago

  • Target version changed from 4.3.13 to 4.3.14
Actions #13

Updated by Benoît PECCATTE almost 5 years ago

  • Status changed from New to In progress
  • Priority changed from 78 to 77
Actions #14

Updated by Benoît PECCATTE almost 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
Actions #15

Updated by Vincent MEMBRÉ almost 5 years ago

  • Target version changed from 4.3.14 to 587
  • Priority changed from 77 to 76
Actions #17

Updated by Vincent MEMBRÉ almost 5 years ago

  • Target version changed from 587 to 4.3.14
  • Priority changed from 76 to 75
Actions #18

Updated by Alexis Mousset almost 5 years ago

  • Target version changed from 4.3.14 to 5.0.13
Actions #19

Updated by Vincent MEMBRÉ over 4 years ago

  • Target version changed from 5.0.13 to 5.0.14
  • Priority changed from 75 to 73
Actions #20

Updated by Vincent MEMBRÉ over 4 years ago

  • Fix check set to To do
Actions #21

Updated by Vincent MEMBRÉ over 4 years ago

  • Name check set to To do
Actions #22

Updated by Benoît PECCATTE over 4 years ago

  • Priority changed from 73 to 72
Actions #23

Updated by Benoît PECCATTE over 4 years ago

  • Pull Request changed from https://github.com/Normation/rudder-packages/pull/1957 to https://github.com/Normation/rudder-packages/pull/2100
Actions #24

Updated by Benoît PECCATTE over 4 years ago

  • Status changed from Pending technical review to Pending release
Actions #25

Updated by Alexis Mousset over 4 years ago

  • Name check changed from To do to Reviewed
Actions #26

Updated by Nicolas CHARLES over 4 years ago

  • Priority changed from 72 to 71
  • Fix check changed from To do to Checked
Actions #27

Updated by Vincent MEMBRÉ over 4 years ago

  • Status changed from Pending release to Released

This bug has been fixed in Rudder 5.0.14 which was released today.

Actions #28

Updated by Alexis Mousset almost 2 years ago

  • Priority changed from 71 to 74
Actions

Also available in: Atom PDF