Skip to content

Commit

Permalink
reduce conditional block
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch committed Jul 19, 2012
1 parent 8855751 commit f382bbd
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions lib/FusionInventory/Agent/Task/Inventory/Input/Linux/Storages.pm
Expand Up @@ -45,35 +45,36 @@ sub doInventory {
# get serial & firmware numbers from hdparm, if available
if (_correctHdparmAvailable()) {
foreach my $device (@devices) {
if (!$device->{SERIALNUMBER} || !$device->{FIRMWARE}) {
my $handle = getFileHandle(
command => "hdparm -I /dev/$device->{NAME}",
logger => $logger
);
next unless $handle;
while (my $line = <$handle>) {
if ($line =~ /^\s+Serial Number\s*:\s*(.+)/i) {
my $value = $1;
$value =~ s/\s+$//;
$device->{SERIALNUMBER} = $value
if !$device->{SERIALNUMBER};
next;
} elsif ($line =~ /^\s+Firmware Revision\s*:\s*(.+)/i) {
my $value = $1;
$value =~ s/\s+$//;
$device->{FIRMWARE} = $value
if !$device->{FIRMWARE};
next;
} elsif ($line =~ /^\s*Transport:.*(SCSI|SATA|USB)/) {
$device->{DESCRIPTION} = $1;
} elsif ($line =~ /^\s*Model Number:\s*(.*?)\s*$/) {
$device->{MODEL} = $1;
} elsif ($line =~ /Logical Unit WWN Device Identifier:\s*(.*?)\s*$/) {
$device->{WWN} = $1;
}
next if $device->{SERIALNUMBER} && $device->{FIRMWARE};

my $handle = getFileHandle(
command => "hdparm -I /dev/$device->{NAME}",
logger => $logger
);
next unless $handle;

while (my $line = <$handle>) {
if ($line =~ /^\s+Serial Number\s*:\s*(.+)/i) {
my $value = $1;
$value =~ s/\s+$//;
$device->{SERIALNUMBER} = $value
if !$device->{SERIALNUMBER};
next;
} elsif ($line =~ /^\s+Firmware Revision\s*:\s*(.+)/i) {
my $value = $1;
$value =~ s/\s+$//;
$device->{FIRMWARE} = $value
if !$device->{FIRMWARE};
next;
} elsif ($line =~ /^\s*Transport:.*(SCSI|SATA|USB)/) {
$device->{DESCRIPTION} = $1;
} elsif ($line =~ /^\s*Model Number:\s*(.*?)\s*$/) {
$device->{MODEL} = $1;
} elsif ($line =~ /Logical Unit WWN Device Identifier:\s*(.*?)\s*$/) {
$device->{WWN} = $1;
}
close $handle;
}
close $handle;
}
}

Expand Down

0 comments on commit f382bbd

Please sign in to comment.