/usr/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/Generic/USB.pm is in fusioninventory-agent 1:2.3.10.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | package FusionInventory::Agent::Task::Inventory::Generic::USB;
use strict;
use warnings;
use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Generic;
sub isEnabled {
return canRun('lsusb');
}
sub doInventory {
my (%params) = @_;
my $inventory = $params{inventory};
foreach my $device (_getDevices(
logger => $params{logger},
datadir => $params{datadir})
) {
$inventory->addEntry(
section => 'USBDEVICES',
entry => $device,
);
}
}
sub _getDevices {
my @devices;
foreach my $device (_getDevicesFromLsusb(@_)) {
next unless $device->{PRODUCTID};
next unless $device->{VENDORID};
# ignore the USB Hub
next if
$device->{PRODUCTID} eq "0001" ||
$device->{PRODUCTID} eq "0002" ;
if (defined($device->{SERIAL}) && length($device->{SERIAL}) < 5) {
$device->{SERIAL} = undef;
}
my $vendor = getUSBDeviceVendor(id => $device->{VENDORID}, @_);
if ($vendor) {
$device->{MANUFACTURER} = $vendor->{name};
my $entry = $vendor->{devices}->{$device->{PRODUCTID}};
if ($entry) {
$device->{CAPTION} = $entry->{name};
}
}
push @devices, $device;
}
return @devices;
}
sub _getDevicesFromLsusb {
my $handle = getFileHandle(
@_,
command => 'lsusb -v',
);
return unless $handle;
my @devices;
my $device;
while (my $line = <$handle>) {
if ($line =~ /^$/) {
push @devices, $device if $device;
undef $device;
} elsif ($line =~ /^\s*idVendor\s*0x(\w+)/i) {
$device->{VENDORID} = $1;
} elsif ($line =~ /^\s*idProduct\s*0x(\w+)/i) {
$device->{PRODUCTID} = $1;
} elsif ($line =~ /^\s*iSerial\s*\d+\s(\w+)/i) {
$device->{SERIAL} = $1;
} elsif ($line =~ /^\s*bInterfaceClass\s*(\d+)/i) {
$device->{CLASS} = $1;
} elsif ($line =~ /^\s*bInterfaceSubClass\s*(\d+)/i) {
$device->{SUBCLASS} = $1;
}
}
close $handle;
push @devices, $device if $device;
return @devices;
}
1;
|