glpi-project / glpi-agent

GLPI Agent
GNU General Public License v2.0
212 stars 51 forks source link

Disk manufacturer's serial number #680

Closed mostafa0017 closed 3 weeks ago

mostafa0017 commented 1 month ago

Bug reporting acknowledgment

Yes, I read it

Professional support

Yes, I know

Describe the bug

Some manufacturers on some disks store or present their actual (manufacturer acknowledged serial number) under AdapterSerialNumber instead of SerialNumber This is observed on Crucial P3, PC300 NVMe SK hynix, Samsung SSD 980.

To reproduce

PS C:\Windows\system32> Get-PhysicalDisk | Select FriendlyName, MediaType, AdapterSerialNumber, SerialNumber | fl

FriendlyName : PC300 NVMe SK hynix 512GB MediaType : SSD AdapterSerialNumber : FJ68NXXXXXXXXXXXX _0000 > This SN is Manufacturer acknowledged both on their Application/Tool and their website. SerialNumber : ACE4_2E61_9000_7804. > this is unrecognizable.

Expected behavior

To gather the correct SN from the manufacturer's perspective.

Operating system

Windows

GLPI Agent version

1.8

GLPI version

10.0.x (See additional context below)

GLPIInventory plugin or other plugin version

GLPI Inventory v1.3.5

Additional context

No response

g-bougard commented 1 month ago

Hi @mostafa0017

can you share for such kind of computer some outputs ?

I need the storages section of the json output from the following command run in an administrative console and from the glpi-agent installation folder:

glpi-inventory --partial storage

I also need the output of the following commands run in an administrative console:

wmic /namespace:\\root\microsoft\windows\storage path MSFT_PhysicalDisk get /format:list
wmic path Win32_DiskDrive get /format:list
g-bougard commented 1 month ago

And can you eventually test by replacing perl\agent\GLPI\Agent\Task\Inventory\Win32\Storages.pm with this one: Win32-Storages.pm.zip

Here is the diff against the current code for that updated module:

diff --git a/lib/GLPI/Agent/Task/Inventory/Win32/Storages.pm b/lib/GLPI/Agent/Task/Inventory/Win32/Storages.pm
index 84061078d..ee9cfa96d 100644
--- a/lib/GLPI/Agent/Task/Inventory/Win32/Storages.pm
+++ b/lib/GLPI/Agent/Task/Inventory/Win32/Storages.pm
@@ -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(
@@ -154,12 +154,15 @@ 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 = 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;
             }
         }
mostafa0017 commented 1 month ago

Here are the commands' outputs:

[info] New inventory from MOSTAFAFIKRY-2024-05-24-14-06-42 for local0
{
   "action": "inventory",
   "content": {
      "bios": {
         "bdate": "2024-01-29",
         "bmanufacturer": "Dell Inc.",
         "bversion": "1.36.0",
         "mmanufacturer": "Dell Inc.",
         "mmodel": "00F6D3",
         "msn": "/43MC3M2/CN129637C61B2A/",
         "skunumber": "07A0",
         "smanufacturer": "Dell Inc.",
         "smodel": "Latitude 7480",
         "ssn": "43MC3M2"
      },
      "hardware": {
         "chassis_type": "Notebook",
         "memory": 16224,
         "name": "MOSTAFAFIKRY",
         "uuid": "DE31C1C2-ABCF-4E63-A84B-10273AA54BC3",
         "vmsystem": "Physical",
         "winlang": "1033",
         "winowner": "New",
         "winprodid": "00330-50807-68617-AAOEM",
         "winprodkey": "REDACTED",
         "workgroup": "WORKGROUP"
      },
      "storages": [
         {
            "description": "PCI Slot 12 : Bus 60 : Device 0 : Function 0 : Adapter 0",
            "disksize": 512110,
            "firmware": "20007A00",
            "interface": "NVME",
            "model": "PC300 NVMe SK hynix 512GB",
            "name": "PhysicalDisk0",
            "serial": "ACE4_2E61_9000_7804.",
            "type": "SSD"
         }
      ],
      "versionclient": "GLPI-Inventory_v1.8"
   },
   "deviceid": "MOSTAFAFIKRY-2024-05-24-14-06-42",
   "itemtype": "Computer",
   "partial": true
}
[info] Inventory dumped on standard output
AdapterSerialNumber=FJ68NXXXXXXXXXXXX   _0000 > I replaced the actual digits with place holders of the same length but the rest of the serialnumber is visible
AllocatedSize=512110190592
BusType=17
CannotPoolReason={7}
CanPool=FALSE
Description=
DeviceId=0
EnclosureNumber=
FirmwareVersion=20007A00
FriendlyName=PC300 NVMe SK hynix 512GB
HealthStatus=0
IsIndicationEnabled=
IsPartial=TRUE
LogicalSectorSize=512
Manufacturer=
MediaType=4
Model=PC300 NVMe SK hynix 512GB
ObjectId={1}\\MOSTAFAFIKRY\root/Microsoft/Windows/Storage/Providers_v2\SPACES_PhysicalDisk.ObjectId="{3cda69c1-37ba-11ec-9257-806e6f6e6963}:PD:{47048133-b200-fe70-f0d5-690ac0db3e9a}"
OperationalDetails=
OperationalStatus={2}
OtherCannotPoolReasonDescription=
PartNumber=
PassThroughClass=
PassThroughIds=
PassThroughNamespace=
PassThroughServer=
PhysicalLocation=PCI Slot 12 : Bus 60 : Device 0 : Function 0 : Adapter 0
PhysicalSectorSize=4096
SerialNumber=ACE4_2E61_9000_7804.
Size=512110190592
SlotNumber=
SoftwareVersion=
SpindleSpeed=0
StoragePoolUniqueId=
SupportedUsages={1,2,3,4,5}
UniqueId=eui.ACE42E6190007804
UniqueIdFormat=8
Usage=1
VirtualDiskFootprint=0
Availability=
BytesPerSector=512
Capabilities={3,4}
CapabilityDescriptions={"Random Access","Supports Writing"}
Caption=PC300 NVMe SK hynix 512GB
CompressionMethod=
ConfigManagerErrorCode=0
ConfigManagerUserConfig=FALSE
CreationClassName=Win32_DiskDrive
DefaultBlockSize=
Description=Disk drive
DeviceID=\\.\PHYSICALDRIVE0
ErrorCleared=
ErrorDescription=
ErrorMethodology=
FirmwareRevision=20007A00
Index=0
InstallDate=
InterfaceType=SCSI
LastErrorCode=
Manufacturer=(Standard disk drives)
MaxBlockSize=
MaxMediaSize=
MediaLoaded=TRUE
MediaType=Fixed hard disk media
MinBlockSize=
Model=PC300 NVMe SK hynix 512GB
Name=\\.\PHYSICALDRIVE0
NeedsCleaning=
NumberOfMediaSupported=
Partitions=6
PNPDeviceID=SCSI\DISK&VEN_NVME&PROD_PC300_NVME_SK_HY\5&6FF0B86&0&000000
PowerManagementCapabilities=
PowerManagementSupported=
SCSIBus=0
SCSILogicalUnit=0
SCSIPort=0
SCSITargetId=0
SectorsPerTrack=63
SerialNumber=ACE4_2E61_9000_7804.
Signature=
Size=512105932800
Status=OK
StatusInfo=
SystemCreationClassName=Win32_ComputerSystem
SystemName=MOSTAFAFIKRY
TotalCylinders=62260
TotalHeads=255
TotalSectors=1000206900
TotalTracks=15876300
TracksPerCylinder=255
mostafa0017 commented 1 month ago

I tried the provided file, and it did indeed report the correct "Adapterserialnumber" FJ68NXXXXXXXXXXXX _0000, I seem to notice that they always end with a trailing _0000 maybe it can be regex trimmed by the agent? Anyway, I can definitely live with this result, so no biggie.

g-bougard commented 1 month ago

Hi @mostafa0017

I think I can strip out that weird suffix. I just hope it always has the same pattern.

mostafa0017 commented 1 month ago

Sometimes it's a tab, sometimes it's a space then followed by _0000 or _0001 (so the consistent thing is that there is a space or a tab then an _000) maybe anything that starts with a space or a tab can be trimmed ? (Disk manufacturers usually use Serialnumbers that have no spaces).

g-bougard commented 1 month ago

Totally agree and this is my plan ;-)

g-bougard commented 1 month ago

Next nightly build should work as expected.

mostafa0017 commented 1 month ago

Apparently some disks (same model if you can believe it !!!) present the value under SerialNumber instead of AdapterSerialNumber (leaving the AdapterSerialNumber value empty) while exhibiting the same space/tab followed by a _000 behaviour like so:

wmic /namespace:\\root\microsoft\windows\storage path MSFT_PhysicalDisk get /format:list
AdapterSerialNumber=
AllocatedSize=500106813440
BusType=8
CannotPoolReason={7}
CanPool=FALSE
Description=
DeviceId=0
EnclosureNumber=
FirmwareVersion=P9CR30A
FriendlyName=CT500P3SSD8
HealthStatus=0
IsIndicationEnabled=
IsPartial=TRUE
LogicalSectorSize=512
Manufacturer=
MediaType=4
Model=CT500P3SSD8
ObjectId={1}\\TAWFI\root/Microsoft/Windows/Storage/Providers_v2\SPACES_PhysicalDisk.ObjectId="{88606147-e43d-11ee-9544-806e6f6e6963}:PD:{0d7aaffd-96bf-8ec9-a5bb-750808ae210c}"
OperationalDetails=
OperationalStatus={2}
OtherCannotPoolReasonDescription=
PartNumber=
PassThroughClass=
PassThroughIds=
PassThroughNamespace=
PassThroughServer=
PhysicalLocation=Integrated : Bus 0 : Device 23 : Function 0 : Adapter 0 : Port 3 : Target 0 : LUN 0
PhysicalSectorSize=512
SerialNumber=2331XXXXXXXX        _00000001.
Size=500107862016
SlotNumber=
SoftwareVersion=
SpindleSpeed=0
StoragePoolUniqueId=
SupportedUsages={1,2,3,4,5}
UniqueId=C0A9CT500P3SSD8                             00012331XXXXXXXX
UniqueIdFormat=8
Usage=1
VirtualDiskFootprint=0
wmic path Win32_DiskDrive get /format:list
Availability=
BytesPerSector=512
Capabilities={3,4,10}
CapabilityDescriptions={"Random Access","Supports Writing","SMART Notification"}
Caption=NVMe CT500P3SSD8
CompressionMethod=
ConfigManagerErrorCode=0
ConfigManagerUserConfig=FALSE
CreationClassName=Win32_DiskDrive
DefaultBlockSize=
Description=Disk drive
DeviceID=\\.\PHYSICALDRIVE0
ErrorCleared=
ErrorDescription=
ErrorMethodology=
FirmwareRevision=P9CR30A
Index=0
InstallDate=
InterfaceType=SCSI
LastErrorCode=
Manufacturer=(Standard disk drives)
MaxBlockSize=
MaxMediaSize=
MediaLoaded=TRUE
MediaType=Fixed hard disk media
MinBlockSize=
Model=NVMe CT500P3SSD8
Name=\\.\PHYSICALDRIVE0
NeedsCleaning=
NumberOfMediaSupported=
Partitions=4
PNPDeviceID=SCSI\DISK&VEN_NVME&PROD_CT500P3SSD8\4&3D57599&0&030000
PowerManagementCapabilities=
PowerManagementSupported=
SCSIBus=3
SCSILogicalUnit=0
SCSIPort=0
SCSITargetId=0
SectorsPerTrack=63
SerialNumber=2331XXXXXXXX        _00000001.
Signature=
Size=500105249280
Status=OK
StatusInfo=
SystemCreationClassName=Win32_ComputerSystem
SystemName=TAWFI
TotalCylinders=60801
TotalHeads=255
TotalSectors=976768065
TotalTracks=15504255
TracksPerCylinder=255
C:\Windows\system32>"C:\Program Files\GLPI-Agent\glpi-inventory.bat" --partial storage
[info] New inventory from TAWFIK-2024-06-02-15-33-25 for local0
{
   "action": "inventory",
   "content": {
      "bios": {
         "bdate": "2023-07-05",
         "bmanufacturer": "Dell Inc.",
         "bversion": "1.26.0",
         "mmanufacturer": "Dell Inc.",
         "mmodel": "07WDVW",
         "msn": "/F6DS2Z2/CNCMK009960C2D/",
         "skunumber": "08E1",
         "smanufacturer": "Dell Inc.",
         "smodel": "Latitude 7400",
         "ssn": "F6DS2Z2"
      },
      "hardware": {
         "chassis_type": "Notebook",
         "memory": 8002,
         "name": "TAWFIK",
         "uuid": "4C4C4544-0036-4410-8053-C6C04F325A32",
         "vmsystem": "Physical",
         "winlang": "1033",
         "winowner": "Windows User",
         "winprodid": "00330-52237-66356-AAOEM",
         "winprodkey": "REDACTED",
         "workgroup": "WORKGROUP"
      },
      "storages": [
         {
            "description": "Integrated : Bus 0 : Device 23 : Function 0 : Adapter 0 : Port 3 : Target 0 : LUN 0",
            "disksize": 500107,
            "firmware": "P9CR30A",
            "interface": "RAID",
            "model": "CT500P3SSD8",
            "name": "PhysicalDisk0",
            "serial": "2331XXXXXXXX _00000001.",
            "type": "SSD"
         }
      ],
      "versionclient": "GLPI-Inventory_v1.9-gitd73f5c8d"
   },
   "deviceid": "TAWFIK-2024-06-02-15-33-25",
   "itemtype": "Computer",
   "partial": true
}
[info] Inventory dumped on standard output

I have seen this happen in 3 cases so far, the above output is from one of them.

g-bougard commented 4 weeks ago

Hi @mostafa0017

yes, I can believe that. Manufacturers or the OS are making something wrong. That's usual and that's a shame.

I'll update the code to remove the suffix after spaces on normal serial too.

g-bougard commented 3 weeks ago

Hi @mostafa0017

next nightly build should fix the problem on any serialnumber.