Skip to content

Commit

Permalink
use Parse::DMIDecode instead of our own parser
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch committed Jun 1, 2012
1 parent 7ad1492 commit f8c979c
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,30 @@ sub doInventory {
}

sub _getBattery {
my $infos = getDmidecodeInfos(@_);
my $parser = getDMIDecodeParser(@_);

return unless $infos->{22};
my @handles = $parser->get_handles(dmitype => 22);
return unless @handles;

my $info = $infos->{22}->[0];
my $handle = $handles[0];

my $battery = {
NAME => $info->{'Name'},
MANUFACTURER => $info->{'Manufacturer'},
SERIAL => $info->{'Serial Number'},
CHEMISTRY => $info->{'Chemistry'},
NAME => getSanitizedValue($handle, 'battery-name'),
MANUFACTURER => getSanitizedValue($handle, 'battery-manufacturer'),
SERIAL => getSanitizedValue($handle, 'battery-serial-number'),
CHEMISTRY => getSanitizedValue($handle, 'battery-chemistry'),
};

if ($info->{'Manufacture Date'}) {
$battery->{DATE} = _parseDate($info->{'Manufacture Date'});
}
$battery->{DATE} =
_parseDate($handle->keyword('battery-manufacture-date'));

if ($info->{Capacity} && $info->{Capacity} =~ /(\d+) \s m(W|A)h$/x) {
my $capacity = $handle->keyword('battery-design-capacity');
if ($capacity && $capacity =~ /(\d+) \s m(W|A)h$/x) {
$battery->{CAPACITY} = $1;
}

if ($info->{Voltage} && $info->{Voltage} =~ /(\d+) \s mV$/x) {
my $voltage = $handle->keyword('battery-design-voltage');
if ($voltage && $voltage =~ /(\d+) \s mV$/x) {
$battery->{VOLTAGE} = $1;
}

Expand All @@ -58,6 +60,8 @@ sub _getBattery {
sub _parseDate {
my ($string) = @_;

return unless $string;

my ($day, $month, $year);
if ($string =~ /(\d{1,2}) [\/-] (\d{1,2}) [\/-] (\d{2})/x) {
$day = $1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,27 @@ sub doInventory {
}

sub _getBiosHardware {
my $infos = getDmidecodeInfos(@_);

my $bios_info = $infos->{0}->[0];
my $system_info = $infos->{1}->[0];
my $base_info = $infos->{2}->[0];
my $chassis_info = $infos->{3}->[0];
my $parser = getDMIDecodeParser(@_);

my $bios = {
BMANUFACTURER => $bios_info->{'Vendor'},
BDATE => $bios_info->{'Release Date'},
BVERSION => $bios_info->{'Version'},
ASSETTAG => $chassis_info->{'Asset Tag'}
BMANUFACTURER => getSanitizedValue($parser, 'bios-vendor'),
BDATE => getSanitizedValue($parser, 'bios-release-date'),
BVERSION => getSanitizedValue($parser, 'bios-version'),
MSN => getSanitizedValue($parser, 'baseboard-serial-number'),
MMODEL => getSanitizedValue($parser, 'baseboard-product-name'),
MMANUFACTURER => getSanitizedValue($parser, 'baseboard-manufacturer'),
ASSETTAG => getSanitizedValue($parser, 'chassis-asset-tag'),
SKUNUMBER => getSanitizedValue($parser, 'system-sku-number'),
SSN => getSanitizedValue($parser, 'system-serial-number'),
SMANUFACTURER => getSanitizedValue($parser, 'system-manufacturer') ||
getSanitizedValue($parser, 'system-vendor'),
SMODEL => getSanitizedValue($parser, 'system-product') ||
getSanitizedValue($parser, 'system-product-name'),
};

$bios->{SMODEL} =
$system_info->{'Product'} ||
$system_info->{'Product Name'};
$bios->{MMODEL} = $base_info->{'Product Name'};
$bios->{SKUNUMBER} = $system_info->{'SKU Number'};

$bios->{SMANUFACTURER} =
$system_info->{'Manufacturer'} ||
$system_info->{'Vendor'};
$bios->{MMANUFACTURER} = $base_info->{'Manufacturer'};

$bios->{SSN} = $system_info->{'Serial Number'};
$bios->{MSN} = $base_info->{'Serial Number'};

my $hardware = {
UUID => $system_info->{'UUID'},
CHASSIS_TYPE => $chassis_info->{'Type'}
UUID => getSanitizedValue($parser,'system-uuid'),
CHASSIS_TYPE => getSanitizedValue($parser,'chassis-type')
};

my $vmsystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ sub doInventory {
my $inventory = $params{inventory};
my $logger = $params{logger};

my $memories = _getMemories(logger => $logger);

return unless $memories;

foreach my $memory (@$memories) {
foreach my $memory (_getMemories(logger => $logger)) {
$inventory->addEntry(
section => 'MEMORIES',
entry => $memory
Expand All @@ -29,60 +25,71 @@ sub doInventory {
}

sub _getMemories {
my $infos = getDmidecodeInfos(@_);
my $parser = getDMIDecodeParser(@_);

my ($memories, $slot);
my (@memories, $slot);

my $memoryCorrection;
if ($infos->{16}) {
$memoryCorrection = $infos->{16}[0]{'Error Correction Type'};
my @handles = $parser->get_handles(dmitype => 16);
if (@handles) {
$memoryCorrection =
$handles[0]->keyword('memory-error-correction-type');
}
if ($infos->{17}) {

foreach my $info (@{$infos->{17}}) {
$slot++;
# start with memory devices
foreach my $handle ($parser->get_handles(dmitype => 17)) {
my $type = $handle->keyword('memory-type');
next unless $type;

$slot++;

# Flash is 'in general' an unrelated internal BIOS storage
# See bug #1334
next if $type =~ /Flash/i;

my $description = $handle->keyword('memory-form-factor');
$description .= " ($memoryCorrection)" if $memoryCorrection;

my $memory = {
NUMSLOTS => $slot,
DESCRIPTION => $description,
CAPTION => getSanitizedValue($handle, 'memory-locator'),
SPEED => getSanitizedValue($handle, 'memory-speed'),
TYPE => getSanitizedValue($handle, 'memory-type'),
SERIALNUMBER => getSanitizedValue(
$handle, 'memory-serial-number'
),
MEMORYCORRECTION => $memoryCorrection
};

my $size = $handle->keyword('memory-size');
if ($size && $size =~ /^(\d+) \s MB$/x) {
$memory->{CAPACITY} = $1;
}

# Flash is 'in general' an unrelated internal BIOS storage, See bug: #1334
next if $info->{'Type'} =~ /Flash/i;
push @memories, $memory;
}

my $description = $info->{'Form Factor'};
$description .= " ($memoryCorrection)" if $memoryCorrection;
return @memories if @memories;

my $memory = {
NUMSLOTS => $slot,
DESCRIPTION => $description,
CAPTION => $info->{'Locator'},
SPEED => $info->{'Speed'},
TYPE => $info->{'Type'},
SERIALNUMBER => $info->{'Serial Number'},
MEMORYCORRECTION => $memoryCorrection
};
# fallback on memory modules
foreach my $handle ($parser->get_handles(dmitype => 6)) {
$slot++;

if ($info->{'Size'} && $info->{'Size'} =~ /^(\d+) \s MB$/x) {
$memory->{CAPACITY} = $1;
}
my $memory = {
NUMSLOTS => $slot,
TYPE => $handle->keyword('memory-type'),
};

push @$memories, $memory;
my $size = $handle->keyword('memory-installed-size');
if ($size && $size =~ /^(\d+)\s*(MB|Mbyte)/x) {
$memory->{CAPACITY} = $1;
}
} elsif ($infos->{6}) {

foreach my $info (@{$infos->{6}}) {
$slot++;

my $memory = {
NUMSLOTS => $slot,
TYPE => $info->{'Type'},
};

if ($info->{'Installed Size'} && $info->{'Installed Size'} =~ /^(\d+)\s*(MB|Mbyte)/x) {
$memory->{CAPACITY} = $1;
}

push @$memories, $memory;
}
push @memories, $memory;
}

return $memories;
return @memories;
}

1;
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ sub doInventory {
my $inventory = $params{inventory};
my $logger = $params{logger};

my $ports = _getPorts(logger => $logger);

return unless $ports;

foreach my $port (@$ports) {
foreach my $port (_getPorts(logger => $logger)) {
$inventory->addEntry(
section => 'PORTS',
entry => $port
Expand All @@ -29,23 +25,25 @@ sub doInventory {
}

sub _getPorts {
my $infos = getDmidecodeInfos(@_);

return unless $infos->{8};
my $parser = getDMIDecodeParser(@_);

my $ports;
foreach my $info (@{$infos->{8}}) {
my @ports;
foreach my $handle ($parser->get_handles(dmitype => 8)) {
my $port = {
CAPTION => $info->{'External Connector Type'},
DESCRIPTION => $info->{'Internal Connector Type'},
NAME => $info->{'Internal Reference Designator'},
TYPE => $info->{'Port Type'},
CAPTION => getSanitizedValue(
$handle, 'connector-external-connector-type'),
DESCRIPTION => getSanitizedValue(
$handle, 'connector-internal-connector-type'),
NAME => getSanitizedValue(
$handle, 'connector-internal-reference-designator'),
TYPE => getSanitizedValue(
$handle, 'connector-port-type'),
};

push @$ports, $port;
push @ports, $port;
}

return $ports;
return @ports;
}

1;
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ sub doInventory {
my $inventory = $params{inventory};
my $logger = $params{logger};

my $slots = _getSlots(logger => $logger);

return unless $slots;

foreach my $slot (@$slots) {
foreach my $slot (_getSlots(logger => $logger)) {
$inventory->addEntry(
section => 'SLOTS',
entry => $slot
Expand All @@ -29,23 +25,21 @@ sub doInventory {
}

sub _getSlots {
my $infos = getDmidecodeInfos(@_);

return unless $infos->{9};
my $parser = getDMIDecodeParser(@_);

my $slots;
foreach my $info (@{$infos->{9}}) {
my @slots;
foreach my $handle ($parser->get_handles(dmitype => 9)) {
my $slot = {
DESCRIPTION => $info->{'Type'},
DESIGNATION => $info->{'ID'},
NAME => $info->{'Designation'},
STATUS => $info->{'Current Usage'},
DESCRIPTION => getSanitizedValue($handle, 'slot-type'),
DESIGNATION => getSanitizedValue($handle, 'slot-id'),
NAME => getSanitizedValue($handle, 'slot-designation'),
STATUS => getSanitizedValue($handle, 'slot-current-usage'),
};

push @$slots, $slot;
push @slots, $slot;
}

return $slots;
return @slots;
}

1;

0 comments on commit f8c979c

Please sign in to comment.