Project

General

Profile

Bug #13866

Invalid json in Rudder inventory hooks fails to log the problem

Added by François ARMAND about 1 year ago. Updated about 1 month 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;
}

Associated revisions

Revision 63687869 (diff)
Added by Benoît PECCATTE about 2 months ago

Fixes #13866: Invalid json in Rudder inventory hooks fails to log the problem

History

#1

Updated by Vincent MEMBRÉ 12 months ago

  • Target version changed from 4.1.17 to 4.1.18
#2

Updated by François ARMAND 12 months 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 = '';
#3

Updated by Benoît PECCATTE 11 months 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
#4

Updated by Vincent MEMBRÉ 11 months ago

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

Updated by Alexis MOUSSET 10 months ago

  • Target version changed from 4.1.19 to 4.1.20
#6

Updated by François ARMAND 10 months ago

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

Updated by François ARMAND 10 months 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
#8

Updated by François ARMAND 9 months ago

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

Updated by François ARMAND 9 months ago

  • Target version changed from 4.3.10 to 4.3.11
#10

Updated by Vincent MEMBRÉ 8 months ago

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

Updated by Vincent MEMBRÉ 6 months ago

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

Updated by Vincent MEMBRÉ 6 months ago

  • Target version changed from 4.3.13 to 4.3.14
#13

Updated by Benoît PECCATTE 6 months ago

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

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

Updated by Vincent MEMBRÉ 5 months ago

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

Updated by Vincent MEMBRÉ 5 months ago

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

Updated by Alexis MOUSSET 5 months ago

  • Target version changed from 4.3.14 to 5.0.13
#19

Updated by Vincent MEMBRÉ 3 months ago

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

Updated by Benoît PECCATTE about 2 months ago

  • Priority changed from 73 to 72
#23

Updated by Benoît PECCATTE about 2 months ago

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

Updated by Benoît PECCATTE about 2 months ago

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

Updated by Nicolas CHARLES about 1 month ago

  • Priority changed from 72 to 71
#27

Updated by Vincent MEMBRÉ about 1 month ago

  • Status changed from Pending release to Released

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

Also available in: Atom PDF