Skip to content

Commit

Permalink
fix: Renamed glpi_version option to glpi-version
Browse files Browse the repository at this point in the history
Enhanced glpi-version configuration support to remove storage interface check
if current glpi version is at least 10.0.4
  • Loading branch information
g-bougard committed Nov 28, 2024
1 parent f417aac commit 17523b8
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 14 deletions.
6 changes: 4 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ core:
* fix #789: Avoid warning on commandline about possible confusion when reading quoted
configuration value including a dash from configuration file
* fix #790: Fix server URL parsing when it doesn't include scheme
* Add glpi_version configuration support to handle inventory_format dependent features
* Add glpi-version configuration support to handle inventory_format dependent features
* Handle /now request as an event. If inventory task run is triggered, it will now
always by default generate a full inventory. /now supports a query string with the
following possible values:
Expand All @@ -26,6 +26,8 @@ inventory:
* Fix rare windows perl error during drives, ipv6 network or videos inventory
* Always keep disabled network interface on windows if it includes "vpn" string
in description
* Add glpi-version configuration support to handle inventory_format dependent features
- Remove check alerting on invalid storage interface for GLPI >= 10.0.4

netdiscovery/netinventory:
* fix #768: Added Aerohive devices support
Expand All @@ -40,7 +42,7 @@ deploy:
esx:
* Support reporting of ESX virtualmachines ip and operating system. It requires
inventory_format schema v1.1.36 on server-side included in GLPI v10.0.17.
* Add --glpi_version option support to glpi-esx script
* Add --glpi-version option support to glpi-esx script

packaging:
* Update Windows MSI packing building process to use:
Expand Down
2 changes: 2 additions & 0 deletions bin/glpi-agent
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ GetOptions(
'force|f',
'full',
'full-inventory-postpone=i',
'glpi-version=s',
'help|h',
'html',
'json',
Expand Down Expand Up @@ -339,6 +340,7 @@ glpi-agent [options] [--server server|--local path]
--vardir=PATH use specified path as storage folder for agent
persistent datas
--glpi-version=<VERSION> set targeted glpi version to enable supported features
--version print the version and exit
--no-win32-ole-workaround [win32 only] disable win32 work-around
used to better handle Win32::OLE apis.
Expand Down
6 changes: 3 additions & 3 deletions bin/glpi-esx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ GetOptions(
'dump',
'dumpfile=s',
'json',
'glpi_version=s',
'glpi-version=s',
) or pod2usage(-verbose => 0);

pod2usage(-verbose => 0, -exitstatus => 0) if $options->{help};
Expand All @@ -53,7 +53,7 @@ if ($options->{version}) {
}

my $config = GLPI::Agent::Config->new(
options => { map { $_ => $options->{$_} } qw{debug tag json glpi_version} }
options => { map { $_ => $options->{$_} } qw{debug tag json glpi-version} }
);

my $logger = GLPI::Agent::Logger->new(config => $config);
Expand Down Expand Up @@ -208,7 +208,7 @@ glpi-esx --host <host> --user <user> --password <password> --path <directory or
--stdout dump inventory on stdout (enabled by default if no path is set)
--tag tag tag for the inventoried machine
--json use json as format for generated inventories
--glpi_version VERSION set targeted glpi version to enable supported features
--glpi-version VERSION set targeted glpi version to enable supported features
Advanced options:
--dump also dump esx host full info datas in a *-hostfullinfo.dump file
Expand Down
3 changes: 3 additions & 0 deletions bin/glpi-inventory
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ GetOptions(
'additional-content=s',
'backend-collect-timeout=s',
'credentials=s@',
'glpi_version=s',
'html',
'json',
'no-category=s',
Expand Down Expand Up @@ -73,6 +74,7 @@ my $inventory = GLPI::Agent::Task::Inventory->new(
html => $options->{html},
json => $options->{json},
basevardir => File::Temp->newdir(CLEANUP => 1),
glpi => $options->{"glpi-version"},
),
logger => GLPI::Agent::Logger->new(config => $config),
datadir => $setup{datadir},
Expand Down Expand Up @@ -109,6 +111,7 @@ glpi-inventory [options]
-t --tag=TAG mark the machine with given tag
--backend-collect-timeout=TIME timeout for inventory modules
execution (30)
--glpi-version=VERSION set targeted glpi version to enable supported features
--additional-content=FILE additional inventory content file
--assetname-support=1|2 [unix/linux only] set the asset name depending on the given value:
- 1 (the default), the short hostname is used as asset name
Expand Down
2 changes: 1 addition & 1 deletion bin/glpi-netinventory
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ glpi-netinventory [options] [--host <host>|--file <file>]
--retries SNMP requets maximum retries (0)
--backend-collect-timeout <TIME>
base expiration timeout, in seconds (180)
--glpi_version VERSION set targeted glpi version to enable supported features
--glpi-version VERSION set targeted glpi version to enable supported features
--type <TYPE> force device type
--threads <COUNT> number of inventory threads (1)
--control output control messages
Expand Down
1 change: 1 addition & 0 deletions contrib/windows/glpi-agent-packaging.pl
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ sub _tree2xml {
$result .= $ident ." ". qq[ <RegistryValue Name="delaytime" Type="string" Value="[DELAYTIME]" />\n];
$result .= $ident ." ". qq[ <RegistryValue Name="backend-collect-timeout" Type="string" Value="[BACKEND_COLLECT_TIMEOUT]" />\n];
$result .= $ident ." ". qq[ <RegistryValue Name="full-inventory-postpone" Type="string" Value="[FULL_INVENTORY_POSTPONE]" />\n];
$result .= $ident ." ". qq[ <RegistryValue Name="glpi-version" Type="string" Value="[GLPI_VERSION]" />\n];
$result .= $ident ." ". qq[ <RegistryValue Name="no-task" Type="string" Value="[NO_TASK]" />\n];
$result .= $ident ." ". qq[ <RegistryValue Name="no-category" Type="string" Value="[NO_CATEGORY]" />\n];
$result .= $ident ." ". qq[ <RegistryValue Name="no-compression" Type="string" Value="[NO_COMPRESSION]" />\n];
Expand Down
6 changes: 6 additions & 0 deletions contrib/windows/packaging/MSI_main-v2.wxs.tt
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@
<SetProperty Id="CMDLINE_FULL_INVENTORY_POSTPONE" Before="AppSearch" Value="[FULL_INVENTORY_POSTPONE]" />
<SetProperty Id="FULL_INVENTORY_POSTPONE" After="AppSearch" Value="[CMDLINE_FULL_INVENTORY_POSTPONE]"><![CDATA[CMDLINE_FULL_INVENTORY_POSTPONE<>"" OR CMDLINE_CONFIG="reset"]]></SetProperty>

<Property Id="GLPI_VERSION" Secure="yes">
<RegistrySearch Id="GlpiVersion" Root="HKLM" Key="[%agent_regpath%]" Name="glpi-version" Type="raw"/>
</Property>
<SetProperty Id="CMDLINE_GLPI_VERSION" Before="AppSearch" Value="[GLPI_VERSION]" />
<SetProperty Id="GLPI_VERSION" After="AppSearch" Value="[CMDLINE_GLPI_VERSION]"><![CDATA[CMDLINE_GLPI_VERSION<>"" OR CMDLINE_CONFIG="reset"]]></SetProperty>

<!-- Configuration defaults after handling command line and registry checks -->
<SetProperty Id="DEBUG" Action="DEBUG_Default" After="LaunchConditions" Value="0"><![CDATA[NOT DEBUG OR (DEBUG<>"1" AND DEBUG<>"2")]]></SetProperty>
<SetProperty Id="LOGGER" Action="LOGGER_Default" After="LaunchConditions" Value="file"><![CDATA[NOT LOGGER]]></SetProperty>
Expand Down
5 changes: 4 additions & 1 deletion lib/GLPI/Agent/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ my $default = {
'conf-reload-interval' => 0,
'debug' => undef,
'delaytime' => 3600,
'glpi_version' => undef,
'glpi-version' => undef,
'remote-scheduling' => 0,
'remote-workers' => 1,
'force' => undef,
Expand Down Expand Up @@ -419,6 +419,7 @@ sub getTargets {
path => $path,
html => $self->{html},
json => $self->{json},
glpi => $self->{"glpi-version"},
);
}
}
Expand All @@ -433,6 +434,7 @@ sub getTargets {
basevardir => $params{vardir},
url => $url,
tag => $self->{tag},
glpi => $self->{"glpi-version"},
);
}
}
Expand All @@ -449,6 +451,7 @@ sub getTargets {
logger => $params{logger},
delaytime => $self->{delaytime},
basevardir => $params{vardir},
glpi => $self->{"glpi-version"},
);
}

Expand Down
21 changes: 18 additions & 3 deletions lib/GLPI/Agent/Inventory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package GLPI::Agent::Inventory;
use strict;
use warnings;

use version;

use Config;
use Digest::SHA;
use English qw(-no_match_vars);
Expand Down Expand Up @@ -111,8 +113,11 @@ my %checks = (
},
STORAGES => {
STATUS => qr/^(up|down)$/,
# TODO Remove this check if GLPI >= 10.0.4
INTERFACE => qr/^(SCSI|HDC|IDE|USB|1394|SATA|SAS|ATAPI)$/
INTERFACE => {
# Check can be ignored since GLPI 10.0.4
not_since => version->parse('10.0.4'),
regexp => qr/^(SCSI|HDC|IDE|USB|1394|SATA|SAS|ATAPI)$/
}
},
VIRTUALMACHINES => {
STATUS => qr/^(running|blocked|idle|paused|shutdown|crashed|dying|off)$/
Expand Down Expand Up @@ -142,6 +147,7 @@ sub new {
logger => $params{logger} || GLPI::Agent::Logger->new(),
fields => \%fields,
_format => '',
_glpi_version => version->parse('0'),
content => {
HARDWARE => {
VMSYSTEM => "Physical" # Default value
Expand All @@ -152,6 +158,9 @@ sub new {
};
bless $self, $class;

$self->{_glpi_version} = version->parse($params{glpi})
if $params{glpi};

$self->setTag($params{tag});
$self->{last_state_file} = $params{statedir} . '/last_state.json'
if $params{statedir};
Expand Down Expand Up @@ -354,7 +363,13 @@ sub addEntry {
# sanitize value
my $value = getSanitizedString($entry->{$field});
# check value if appliable
if ($checks->{$field}) {
if (ref($checks->{$field}) eq 'HASH') {
if ($checks->{$field}->{regexp} && $checks->{$field}->{not_since} > $self->{_glpi_version}) {
$self->{logger}->debug(
"invalid value $value for field $field for section $section"
) unless $value =~ $checks->{$field}->{regexp};
}
} elsif ($checks->{$field}) {
$self->{logger}->debug(
"invalid value $value for field $field for section $section"
) unless $value =~ $checks->{$field};
Expand Down
7 changes: 7 additions & 0 deletions lib/GLPI/Agent/Target.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sub new {
maxDelay => $params{maxDelay} || 3600,
errMaxDelay => $errMaxDelay,
initialDelay => $params{delaytime},
_glpi => $params{glpi} // '',
_events => [],
_next_event => {},
};
Expand Down Expand Up @@ -454,6 +455,12 @@ sub _needToReloadState {
return $self->{storage}->modified(name => 'target');
}

sub getTaskVersion {
my ($self) = @_;

return $self->{_glpi};
}

1;
__END__
Expand Down
4 changes: 2 additions & 2 deletions lib/GLPI/Agent/Target/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ sub getTaskVersion {

$task = lc($task);

return '' unless $task && $self->{_server_task_support} && $self->{_server_task_support}->{$task};
return $self->{_server_task_support}->{$task}->{version} // '';
return $self->{_glpi} unless $task && $self->{_server_task_support} && $self->{_server_task_support}->{$task};
return $self->{_server_task_support}->{$task}->{version} // $self->{_glpi} // '';
}

1;
Expand Down
3 changes: 2 additions & 1 deletion lib/GLPI/Agent/Task/ESX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ sub createInventory {

# Set known glpi version to enable or disable supported features
my $glpi_version = $self->{target}->isType('server') ? $self->{target}->getTaskVersion('inventory') : '';
$glpi_version = $self->{config}->{glpi_version} if empty($glpi_version);
$glpi_version = $self->{config}->{'glpi-version'} if empty($glpi_version);
$host->enableFeaturesForGlpiVersion($glpi_version);

my $inventory = GLPI::Agent::Inventory->new(
datadir => $self->{datadir},
logger => $self->{logger},
glpi => $glpi_version,
tag => $tag,
# deviceid can be set and so reused from previous netscan
deviceid => $deviceid
Expand Down
1 change: 1 addition & 0 deletions lib/GLPI/Agent/Task/Inventory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ sub run {
deviceid => $self->{deviceid},
datadir => $self->{datadir},
logger => $self->{logger},
glpi => $self->{target}->getTaskVersion('inventory'),
tag => $tag
);

Expand Down
2 changes: 1 addition & 1 deletion lib/GLPI/Agent/Task/NetInventory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ sub _queryDevice {
}

my $glpi_version = $self->{target}->isType('server') ? $self->{target}->getTaskVersion('inventory') : '';
$glpi_version = $self->{config}->{'glpi_version'} if empty($glpi_version);
$glpi_version = $self->{config}->{'glpi-version'} if empty($glpi_version);

my $result = getDeviceFullInfo(
id => $device->{ID},
Expand Down

0 comments on commit 17523b8

Please sign in to comment.