can not add plugins without making change on modules.conf files
support.os
support.os at smart-rx.com
Tue Mar 23 11:38:10 GMT 2021
Hello,
We are installing the ocsinventory client on debian (more specifically we repackage and install ocsinventory-agent-2.8 on a debian 8 chroot).
Our problem is that we now need to provide a plugin to list the usb devices connected to the machine.
But adding a plugin on ocsinventory-agent requires modifying the configuration file "/etc/ocsinventory/modules.conf" provided by the ocsinventory-agent package.
In order to repackage the agent, we have considered 2 solutions that require modifying the " UnixAgent\lib\Ocsinventory\Agent\Hooks.pm" file :
1. Comment out the line "last ;" in the new function when browsing the folder list $self->{config}->{etcdir}
a. With this we can load modules.conf files from '/etc/ocsinventory' AND '/usr/local/etc/ocsinventory' AND '/etc/ocsinventory-agent' AND $ENV{HOME}.'/.ocsinventory'
b. Not verif good but simple
2. Add a loop that looks for a sub-folder "modules.conf.d" in the folder containing the "modules.conf" file to load additional configuration files.
In the end, we choose the second solution, so the function « new » look like this now :
sub new {
my (undef, $context) = @_;
my $self = {};
$self->{accountinfo} = $context->{accountinfo};
$self->{accountconfig} = $context->{accountconfig};
my $logger = $self->{logger}=$context->{logger};
$self->{config} = $context->{config};
$self->{dontuse} = 1;
my $modulefile;
foreach (@{$self->{config}->{etcdir}}) {
$modulefile = $_.'/modules.conf';
if (-f $modulefile) {
if (do $modulefile) {
$logger->debug("Turns hooks on for $modulefile");
# Check and load additionnal files from modules.conf.d directory
if (-d $_.'/modules.conf.d') {
my $pluginsdir = $_.'/modules.conf.d';
my $dh;
if ( opendir($dh, $pluginsdir) ){
my @dots = readdir($dh);
foreach (@dots) {
next unless (-f $pluginsdir."/".$_);
next unless ($pluginsdir."/".$_ =~ m/\.conf$/);
if ( -f $pluginsdir."/".$_ ){
my $modulepluginfile = $pluginsdir."/".$_;
if (do $modulepluginfile) {
$logger->debug("Turns hooks plugins on for $modulepluginfile");
$self->{dontuse} = 0;
} else {
$logger->debug("Failed to load `$modulepluginfile': $?");
}
}
}
}
closedir $dh;
}
$self->{dontuse} = 0;
last;
} else {
$logger->debug("Failed to load `$modulefile': $?");
}
}
}
if ($self->{dontuse}) {
$logger->debug("No modules will be used.");
} else {
my $ocsAgentServerUri;
# to avoid a warning if $self->{config}->{server} is not defined
if ($self->{config}->{server}) {
$ocsAgentServerUri = "http://".$self->{config}->{server}.$self->{config}->{remotedir};
}
if ($self->{config}->{debug}) {
$::debug = 2;
}
}
# Create objects for modules
foreach my $package (searchModules(\%Ocsinventory::Agent::Modules::)){
my $module = new $package($context);
my $name = $module->{structure}->{name};
# Store the reference in a key to access modules easily
$self->{modules}->{$name}=$module;
}
bless $self;
}
In few month we will move to Debian 10 and we hope used the default ocsinventory-agent.
More information about the pkg-perl-maintainers
mailing list