Skip to content

Commit

Permalink
fix: Enhanced disk storage serialnumber support on Windows
Browse files Browse the repository at this point in the history
Closes #680
  • Loading branch information
g-bougard committed May 24, 2024
1 parent 17f77e5 commit d73f5c8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Inventory:
* fix #673: Fix support of network port type on MacOSX
* fix #675: Enhanced MSSQL database inventory on Windows by discovering installed
instances.
* fix #680: Enhanced disk storage serialnumber support on Windows

netdiscovery/netinventory:
* fix #642: Support snmp-retries configuration parameter to set snmp requests
Expand Down
12 changes: 8 additions & 4 deletions lib/GLPI/Agent/Task/Inventory/Win32/Storages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ sub _getDrives {
FirmwareRevision SerialNumber Size SCSIPort SCSILogicalUnit SCSITargetId
BusType FriendlyName DeviceId
/;
push @properties, qw(FirmwareVersion PhysicalLocation)
push @properties, qw(FirmwareVersion PhysicalLocation AdapterSerialNumber)
if $params{class} eq 'MSFT_PhysicalDisk';

foreach my $object (getWMIObjects(
Expand All @@ -154,12 +154,16 @@ sub _getDrives {
$drive->{DISKSIZE} = int($object->{Size} / 1_000_000)
if $object->{Size};

if ($object->{SerialNumber} && $object->{SerialNumber} !~ /^ +$/) {
# First use AdapterSerialNumber as SerialNumber
my $serial = trimWhitespace($object->{AdapterSerialNumber});
($serial) = $serial =~ /^(\S+)/ unless empty($serial);
$serial = trimWhitespace($object->{SerialNumber}) if empty($serial);
unless (empty($serial)) {
# Try to decode serial only for known case
if ($drive->{MODEL} =~ /VBOX HARDDISK ATA/) {
$drive->{SERIAL} = _decodeSerialNumber($object->{SerialNumber});
$drive->{SERIAL} = _decodeSerialNumber($serial);
} else {
$drive->{SERIAL} = $object->{SerialNumber};
$drive->{SERIAL} = $serial;
}
}

Expand Down
Binary file not shown.
Binary file not shown.
34 changes: 29 additions & 5 deletions t/tasks/inventory/windows/storages.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use Test::Exception;
use Test::MockModule;
use Test::More;
use UNIVERSAL::require;
use Data::Dumper;

use GLPI::Agent::Inventory;
use GLPI::Test::Utils;
Expand Down Expand Up @@ -330,6 +331,22 @@ my %tests = (
DISKSIZE => 63,
},
],
'latitude-7480' => [
{
DESCRIPTION => 'PCI Slot 12 : Bus 60 : Device 0 : Function 0 : Adapter 0',
DISKSIZE => 512110,
FIRMWARE => '20007A00',
INTERFACE => 'NVMe',
MANUFACTURER => undef,
MODEL => 'PC300 NVMe SK hynix 512GB',
NAME => 'PhysicalDisk0',
SCSI_COID => undef,
SCSI_LUN => undef,
SCSI_UNID => undef,
SERIAL => 'FJ68NXXXXXXXXXXXX',
TYPE => 'SSD'
}
],
);

plan tests => (2 * scalar keys %tests) + 1;
Expand Down Expand Up @@ -364,11 +381,18 @@ foreach my $test (sort keys %tests) {
);
push @storages, @{$storages};

cmp_deeply(
\@storages,
$tests{$test},
"$test: parsing"
);
if (ref($tests{$test}) eq 'ARRAY' && scalar(@{$tests{$test}})) {
cmp_deeply(
\@storages,
$tests{$test},
"$test: parsing"
);
} else {
my $dumper = Data::Dumper->new([\@storages], [$test])->Useperl(1)->Indent(1)->Quotekeys(0)->Sortkeys(1)->Pad(" ");
$dumper->{xpad} = " ";
print STDERR $dumper->Dump();
fail "$test: still no result integrated";
}
lives_ok {
$inventory->addEntry(section => 'STORAGES', entry => $_)
foreach @storages;
Expand Down

0 comments on commit d73f5c8

Please sign in to comment.