FusionInventory-Agent
view release on metacpan or search on metacpan
lib/FusionInventory/Agent/Tools/Linux.pm view on Meta::CPAN
$result->{NAME} = $params{device};
return $result;
}
sub getCPUsFromProc {
my (%params) = (
file => '/proc/cpuinfo',
@_
);
my $handle = getFileHandle(%params);
my (@cpus, $cpu);
while (my $line = <$handle>) {
if ($line =~ /^([^:]+\S) \s* : \s (.+)/x) {
$cpu->{lc($1)} = trimWhitespace($2);
} elsif ($line =~ /^$/) {
# an empty line marks the end of a cpu section
# push to the list, but only if it is a valid cpu
push @cpus, $cpu if $cpu && _isValidCPU($cpu);
undef $cpu;
}
}
close $handle;
# push remaining cpu to the list, if it is valid cpu
push @cpus, $cpu if $cpu && _isValidCPU($cpu);
return @cpus;
}
sub _isValidCPU {
my ($cpu) = @_;
return exists $cpu->{processor} || exists $cpu->{cpu};
}
sub getDevicesFromHal {
my (%params) = (
command => '/usr/bin/lshal',
@_
);
# We need to support dump params to permit full testing when root params is set
if ($params{root}) {
$params{file} = "$params{root}/lshal";
} elsif ($params{dump}) {
$params{dump}->{lshal} = getAllLines(%params);
}
my $handle = getFileHandle(%params);
my (@devices, $device);
while (my $line = <$handle>) {
chomp $line;
if ($line =~ m{^udi = '/org/freedesktop/Hal/devices/(storage|legacy_floppy|block)}) {
$device = {};
next;
}
next unless defined $device;
if ($line =~ /^$/) {
push(@devices, $device);
undef $device;
} elsif ($line =~ /^\s+ storage.serial \s = \s '([^']+)'/x) {
$device->{SERIALNUMBER} = $1;
} elsif ($line =~ /^\s+ storage.firmware_version \s = \s '([^']+)'/x) {
$device->{FIRMWARE} = $1;
} elsif ($line =~ /^\s+ block.device \s = \s '([^']+)'/x) {
my $value = $1;
($device->{NAME}) = $value =~ m{/dev/(\S+)};
} elsif ($line =~ /^\s+ info.vendor \s = \s '([^']+)'/x) {
$device->{MANUFACTURER} = $1;
} elsif ($line =~ /^\s+ storage.model \s = \s '([^']+)'/x) {
$device->{MODEL} = $1;
} elsif ($line =~ /^\s+ storage.drive_type \s = \s '([^']+)'/x) {
$device->{TYPE} = $1;
} elsif ($line =~ /^\s+ storage.size \s = \s (\S+)/x) {
my $value = $1;
$device->{DISKSIZE} = int($value/(1024*1024) + 0.5);
}
}
close $handle;
return @devices;
}
sub getDevicesFromProc {
my (%params) = @_;
# We need to support dump params to permit full testing when root params is set
my $dump = $params{dump};
my $root = $params{root} || "";
my $logger = $params{logger};
# compute list of devices
my @names;
foreach my $file (glob "$root/sys/block/*") {
if ($dump && -d $file) {
my $basename = basename($file);
$dump->{sys}->{block}->{$basename} = {};
}
next unless $file =~ /([shv]d[a-z]+|fd\d)$/;
push @names, $1;
}
# add any block device identified as device by the kernel like SSD disks or
# removable disks (SD cards and others)
foreach my $file (glob "$root/sys/block/*/device") {
if ($dump && -d $file) {
my $dirname = basename(dirname($file));
$dump->{sys}->{block}->{$dirname}->{device} = {};
}
next unless $file =~ m|([^/]*)/device$|;
( run in 0.585 second using v1.01-cache-2.11-cpan-0b5f733616e )