diff --git a/lib/FusionInventory/Agent/Task/Inventory/Input/Generic/USB.pm b/lib/FusionInventory/Agent/Task/Inventory/Input/Generic/USB.pm index 0a17043d39..94135eb8d5 100644 --- a/lib/FusionInventory/Agent/Task/Inventory/Input/Generic/USB.pm +++ b/lib/FusionInventory/Agent/Task/Inventory/Input/Generic/USB.pm @@ -16,6 +16,19 @@ sub doInventory { my $inventory = $params{inventory}; foreach my $device (_getDevices(logger => $params{logger})) { + $inventory->addEntry( + section => 'USBDEVICES', + entry => $device, + ); + } +} + +sub _getDevices { + my (%params) = @_; + + my @devices; + + foreach my $device (_getDevicesFromLsusb(%params)) { next unless $device->{PRODUCTID}; next unless $device->{VENDORID}; @@ -40,14 +53,13 @@ sub doInventory { } } - $inventory->addEntry( - section => 'USBDEVICES', - entry => $device, - ); + push @devices, $device; } + + return @devices; } -sub _getDevices { +sub _getDevicesFromLsusb { my $handle = getFileHandle( @_, command => 'lsusb -v', diff --git a/lib/FusionInventory/Agent/Task/Inventory/Input/Win32/USB.pm b/lib/FusionInventory/Agent/Task/Inventory/Input/Win32/USB.pm index 8df4f03421..7f16f8d095 100644 --- a/lib/FusionInventory/Agent/Task/Inventory/Input/Win32/USB.pm +++ b/lib/FusionInventory/Agent/Task/Inventory/Input/Win32/USB.pm @@ -23,31 +23,41 @@ sub doInventory { } sub _getDevices { + my (%params) = @_; + my @devices; my $seen; + foreach my $device (_getDevicesFromWMI(%params)) { + next if $device->{VENDORID} =~ /^0+$/; + + # avoid duplicates + next if $seen->{$device->{SERIAL}}++; + + # pseudo serial generated by windows + delete $device->{SERIAL} if $device->{SERIAL} =~ /&/; + + push @devices, $device; + } + + return @devices; +} + +sub _getDevicesFromWMI { + my @devices; + foreach my $object (getWMIObjects( class => 'CIM_LogicalDevice', properties => [ qw/DeviceID Name/ ] )) { next unless $object->{DeviceID} =~ /^USB\\VID_(\w+)&PID_(\w+)\\(.*)/; - my $device = { + push @devices, { NAME => $object->{Name}, VENDORID => $1, PRODUCTID => $2, SERIAL => $3 }; - - next if $device->{VENDORID} =~ /^0+$/; - - # avoid duplicates - next if $seen->{$device->{SERIAL}}++; - - # pseudo serial generated by windows - delete $device->{SERIAL} if $device->{SERIAL} =~ /&/; - - push @devices, $device; } return @devices; diff --git a/t/inventory/generic/usb.t b/t/inventory/generic/usb.t index 1265f32957..661560d81f 100755 --- a/t/inventory/generic/usb.t +++ b/t/inventory/generic/usb.t @@ -9,13 +9,6 @@ use FusionInventory::Agent::Task::Inventory::Input::Generic::USB; my %tests = ( 'dell-xt2' => [ - { - VENDORID => '1d6b', - SERIAL => '0000', - SUBCLASS => '0', - CLASS => '9', - PRODUCTID => '0001' - }, { VENDORID => '0a5c', SUBCLASS => '0', @@ -40,20 +33,6 @@ my %tests = ( CLASS => '254', PRODUCTID => '8160' }, - { - VENDORID => '1d6b', - SERIAL => '0000', - SUBCLASS => '0', - CLASS => '9', - PRODUCTID => '0001' - }, - { - VENDORID => '1d6b', - SERIAL => '0000', - SUBCLASS => '0', - CLASS => '9', - PRODUCTID => '0001' - }, { VENDORID => '0a5c', SERIAL => '0123456789ABCD', @@ -61,52 +40,11 @@ my %tests = ( CLASS => '254', PRODUCTID => '5801' }, - { - VENDORID => '1d6b', - SERIAL => '0000', - SUBCLASS => '0', - CLASS => '9', - PRODUCTID => '0001' - }, - { - VENDORID => '1d6b', - SERIAL => '0000', - SUBCLASS => '0', - CLASS => '9', - PRODUCTID => '0001' - }, - { - VENDORID => '1b96', - SUBCLASS => '0', - CLASS => '0', - PRODUCTID => '0001' - }, - { - VENDORID => '1d6b', - SERIAL => '0000', - SUBCLASS => '0', - CLASS => '9', - PRODUCTID => '0001' - }, { VENDORID => '047d', SUBCLASS => '1', CLASS => '3', PRODUCTID => '101f' - }, - { - VENDORID => '1d6b', - SERIAL => '0000', - SUBCLASS => '0', - CLASS => '9', - PRODUCTID => '0002' - }, - { - VENDORID => '1d6b', - SERIAL => '0000', - SUBCLASS => '0', - CLASS => '9', - PRODUCTID => '0002' } ] );