Skip to content

Commit e13d549

Browse files
committed
Fixes #403: Extend Rudder specific inventory with client side data
1 parent a533aec commit e13d549

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

lib/FusionInventory/Agent/Inventory.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ my %fields = (
7777
CMD/ ],
7878
REGISTRY => [ qw/NAME REGVALUE HIVE/ ],
7979
REMOTE_MGMT => [ qw/ID TYPE/ ],
80-
RUDDER => [ qw/AGENT UUID HOSTNAME SERVER_ROLES AGENT_CAPABILITIES/ ],
80+
RUDDER => [ qw/AGENT UUID HOSTNAME SERVER_ROLES AGENT_CAPABILITIES CUSTOM_PROPERTIES/ ],
8181
SLOTS => [ qw/DESCRIPTION DESIGNATION NAME STATUS/ ],
8282
SOFTWARES => [ qw/COMMENTS FILESIZE FOLDER FROM HELPLINK INSTALLDATE
8383
NAME NO_REMOVE RELEASE_TYPE PUBLISHER

lib/FusionInventory/Agent/Task/Inventory/Generic/Rudder.pm

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use English qw(-no_match_vars);
77

88
use FusionInventory::Agent::Tools;
99

10+
use JSON::PP;
11+
1012
sub isEnabled {
1113
return -r getUuidFile();
1214
}
@@ -42,19 +44,65 @@ sub doInventory {
4244
# Get agent capabilities
4345
my @agentCapabilities = _listAgentCapabilities();
4446

47+
my $customProperties = _getCustomProperties(logger => $logger);
48+
4549
my $rudder = {
4650
HOSTNAME => $hostname,
4751
UUID => $Uuid,
4852
AGENT => \@agents,
4953
SERVER_ROLES => { SERVER_ROLE => \@serverRoles },
5054
AGENT_CAPABILITIES => { AGENT_CAPABILITY => \@agentCapabilities },
55+
CUSTOM_PROPERTIES => $customProperties,
5156
};
5257

5358
$inventory->addEntry(
5459
section => 'RUDDER', entry => $rudder
5560
);
5661
}
5762

63+
sub _getCustomProperties {
64+
my (%params) = @_;
65+
my $logger = $params{logger};
66+
67+
my $custom_properties_dir = ($OSNAME eq 'MSWin32') ? 'C:\Program Files\Rudder\hooks.d' : '/var/rudder/hooks.d';
68+
my $custom_properties;
69+
if (-d "$custom_properties_dir") {
70+
my @custom_propertes_list = ();
71+
opendir(DIR, $custom_properties_dir); # or die $!;
72+
# List each file in the custom_properties directory, each files being a script
73+
my @ordered_script_list = sort readdir(DIR);
74+
while (my $file = shift @ordered_script_list) {
75+
my $script_file = $custom_properties_dir . "/" . $file;
76+
if (-f $script_file) {
77+
next if ($file =~ m/^\./);
78+
# Ignore non-executable file, or folders
79+
next unless -x $script_file;
80+
my $properties = qx($script_file);
81+
my $exit_code = $? >> 8;
82+
if ($exit_code > 0) {
83+
$logger->error("Script $script_file failed to run properly, with exit code $exit_code");
84+
next;
85+
}
86+
87+
# check that it is valid JSON
88+
eval {
89+
my $coder = JSON::PP->new;
90+
my $propertiesData = $coder->decode($properties);
91+
push @custom_propertes_list, $coder->encode($propertiesData);
92+
};
93+
if ($@) {
94+
$logger->error("Script $script_file didn't return valid JSON entry, error is:$@");
95+
}
96+
}
97+
98+
}
99+
closedir(DIR);
100+
$custom_properties = "[". join(",", @custom_propertes_list) . "]";
101+
}
102+
return $custom_properties;
103+
}
104+
105+
58106
sub _listServerRoles {
59107
my $server_roles_dir = ($OSNAME eq 'MSWin32') ? 'C:\Program Files\Rudder\etc\server-roles.d' : '/opt/rudder/etc/server-roles.d';
60108
my @server_roles;

0 commit comments

Comments
 (0)