Project

General

Profile

Actions

Bug #13866

closed

Invalid json in Rudder inventory hooks fails to log the problem

Added by François ARMAND over 2 years ago. Updated over 1 year ago.

Status:
Released
Priority:
N/A
Category:
Web - Nodes & inventories
Target version:
Severity:
Major - prevents use of part of Rudder | no simple workaround
User visibility:
Operational - other Techniques | Rudder settings | Plugins
Effort required:
Priority:
71
Tags:

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 2 years ago

  • Target version changed from 4.1.17 to 4.1.18
Actions #2

Updated by François ARMAND over 2 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 2 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 2 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 over 2 years ago

  • Target version changed from 4.1.19 to 4.1.20
Actions #6

Updated by François ARMAND over 2 years ago

  • Tags set to Sponsored
  • Priority changed from 40 to 72
Actions #7

Updated by François ARMAND over 2 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 2 years ago

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

Updated by François ARMAND about 2 years ago

  • Target version changed from 4.3.10 to 4.3.11
Actions #10

Updated by Vincent MEMBRÉ about 2 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 2 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 2 years ago

  • Target version changed from 4.3.13 to 4.3.14
Actions #13

Updated by Benoît PECCATTE almost 2 years ago

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

Updated by Benoît PECCATTE almost 2 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 2 years ago

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

Updated by Vincent MEMBRÉ almost 2 years ago

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

Updated by Alexis MOUSSET almost 2 years ago

  • Target version changed from 4.3.14 to 5.0.13
Actions #19

Updated by Vincent MEMBRÉ over 1 year ago

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

Updated by Benoît PECCATTE over 1 year ago

  • Priority changed from 73 to 72
Actions #23

Updated by Benoît PECCATTE over 1 year 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 1 year ago

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

Updated by Nicolas CHARLES over 1 year ago

  • Priority changed from 72 to 71
Actions #27

Updated by Vincent MEMBRÉ over 1 year ago

  • Status changed from Pending release to Released

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

Actions

Also available in: Atom PDF