Skip to content

Commit

Permalink
isolate parsing into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch authored and Gonéri Le Bouder committed May 24, 2012
1 parent 868661c commit 4608ee4
Showing 1 changed file with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,48 @@ sub doInventory {

my @devices = getDevicesFromUdev(logger => $logger);

foreach my $hd (@devices) {
my $handle = getFileHandle(
logger => $logger,
command => "mpt-status -n -i $hd->{SCSI_UNID}"
);
next unless $handle;
while (my $line = <$handle>) {
next unless $line =~ /phys_id:(\d+).*product_id:\s*(\S*)\s+revision:(\S+).*size\(GB\):(\d+)/;
my $id = $1;

my $storage = {
NAME => $hd->{NAME},
DESCRIPTION => 'SATA',
TYPE => 'disk',
MODEL => $2,
FIRMWARE => $3,
SIZE => $4 * 1024
};

$storage->{SERIALNUMBER} = getSerialnumber(
device => "/dev/sg$id"
foreach my $device (@devices) {
foreach my $disk (_getDiskFromMptStatus(
name => $device->{NAME},
logger => $logger,
command => "mpt-status -n -i $device->{SCSI_UNID}"
)) {
$disk->{SERIALNUMBER} = getSerialnumber(
device => "/dev/sg$disk->{id}"
);
$storage->{MANUFACTURER} = getCanonicalManufacturer(
$storage->{MODEL}
);

$inventory->addEntry(section => 'STORAGES', entry => $storage);
delete $disk->{id};
$inventory->addEntry(section => 'STORAGES', entry => $disk);
}
close $handle;
}

}

sub _getDiskFromMptStatus {
my (%params) = @_;

my $handle = getFileHandle(%params);
next unless $handle;

my @disks;
while (my $line = <$handle>) {
next unless $line =~ /phys_id:(\d+).*product_id:\s*(\S*)\s+revision:(\S+).*size\(GB\):(\d+)/;

my $disk = {
NAME => $params{name},
DESCRIPTION => 'SATA',
TYPE => 'disk',
id => $1,
MODEL => $2,
MANUFACTURER => getCanonicalManufacturer($2),
FIRMWARE => $3,
SIZE => $4 * 1024
};

push @disks, $disk;
}
close $handle;

return @disks;
}

1;

0 comments on commit 4608ee4

Please sign in to comment.