Skip to content

Commit

Permalink
less intermediate variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Rousse authored and Guillaume Rousse committed Mar 2, 2012
1 parent d36d357 commit 1b2636c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 61 deletions.
22 changes: 9 additions & 13 deletions lib/FusionInventory/Agent/Task/Inventory/Input/AIX/Bios.pm
Expand Up @@ -22,30 +22,26 @@ sub doInventory {
my $inventory = $params{inventory};
my $logger = $params{logger};

my ($serial, $model, $version, $date);
my $bios = {
BMANUFACTURER => 'IBM',
SMANUFACTURER => 'IBM',
};

my @infos = getLsvpdInfos(logger => $logger);

my $system = first { $_->{DS} eq 'System Firmware' } @infos;
$version = $system->{RM} if $system;
$bios->{BVERSION} = $system->{RM} if $system;

my $platform = first { $_->{DS} eq 'Platform Firmware' } @infos;
$version .= "(Firmware : $platform->{RM})" if $platform;
$bios->{BVERSION} .= "(Firmware : $platform->{RM})" if $platform;

my $vpd = first { $_->{DS} eq 'System VPD' } @infos;
if ($vpd) {
$model = $vpd->{TM};
$serial = $vpd->{SE};
$bios->{SMODEL} = $vpd->{TM};
$bios->{SSN} = $vpd->{SE};
}

$inventory->setBios({
BVERSION => $version,
BDATE => $date,
BMANUFACTURER => 'IBM',
SMANUFACTURER => 'IBM',
SMODEL => $model,
SSN => $serial,
});
$inventory->setBios($bios);
}

1;
Expand Up @@ -16,10 +16,14 @@ sub doInventory {

my $inventory = $params{inventory};

my $bios = {
SMANUFACTURER => 'DEC',
};

# sysctl infos

# example on *BSD: AlphaStation 255 4/232
my $SystemModel = getFirstLine(command => 'sysctl -n hw.model');
$bios->{SMODEL} = getFirstLine(command => 'sysctl -n hw.model');

my $processorn = getFirstLine(command => 'sysctl -n hw.ncpu');

Expand All @@ -37,14 +41,11 @@ sub doInventory {

my ($processort, $processors);
foreach my $line (getAllLines(command => 'dmesg')) {
if ($line =~ /$SystemModel,\s*(\S+)\s*MHz/) { $processors = $1; }
if ($line =~ /$bios->{SMODEL},\s*(\S+)\s*MHz/) { $processors = $1; }
if ($line =~ /^cpu[^:]*:\s*(.*)$/i) { $processort = $1; }
}

$inventory->setBios({
SMANUFACTURER => 'DEC',
SMODEL => $SystemModel,
});
$inventory->setBios($bios);

for my $i (1 .. $processorn) {
$inventory->addEntry(
Expand Down
20 changes: 10 additions & 10 deletions lib/FusionInventory/Agent/Task/Inventory/Input/BSD/Archs/MIPS.pm
Expand Up @@ -15,12 +15,16 @@ sub doInventory {
my (%params) = @_;

my $inventory = $params{inventory};

my $bios = {
SMANUFACTURER => 'SGI',
};

# sysctl infos

# example on NetBSD: SGI-IP22
# example on OpenBSD: SGI-O2 (IP32)
my $SystemModel = getFirstLine(command => 'sysctl -n hw.model');
$bios->{SMODEL} = getFirstLine(command => 'sysctl -n hw.model');

my $processorn = getFirstLine(command => 'sysctl -n hw.ncpu');

Expand All @@ -41,18 +45,14 @@ sub doInventory {
# cpu0 at mainbus0: MIPS R5000 CPU rev 2.1 180 MHz with R5000 based FPC rev 1.0
# cpu0: cache L1-I 32KB D 32KB 2 way, L2 512KB direct

my ($SystemSerial, $processort, $processors);
my ($processort, $processors);
foreach my $line (getAllLines(command => 'dmesg')) {
if ($line =~ /$SystemModel\s*\[\S*\s*(\S*)\]/) { $SystemSerial = $1; }
if ($line =~ /cpu0 at mainbus0:\s*(.*)$/) { $processort = $1; }
if ($line =~ /CPU\s*.*\D(\d+)\s*MHz/) { $processors = $1; }
if ($line =~ /$bios->{SMODEL}\s*\[\S*\s*(\S*)\]/) { $bios->{SSN} = $1; }
if ($line =~ /cpu0 at mainbus0:\s*(.*)$/) { $processort = $1; }
if ($line =~ /CPU\s*.*\D(\d+)\s*MHz/) { $processors = $1; }
}

$inventory->setBios({
SMANUFACTURER => 'SGI',
SMODEL => $SystemModel,
SSN => $SystemSerial,
});
$inventory->setBios($bios);

for my $i (1 .. $processorn) {
$inventory->addEntry(
Expand Down
28 changes: 14 additions & 14 deletions lib/FusionInventory/Agent/Task/Inventory/Input/BSD/Archs/SPARC.pm
Expand Up @@ -16,17 +16,21 @@ sub doInventory {

my $inventory = $params{inventory};

my $bios = {
SMANUFACTURER => 'SUN',
};

# sysctl infos

# it gives only the CPU on OpenBSD/sparc64
my $SystemModel = getFirstLine(command => 'sysctl -n hw.model');
$bios->{SMODEL} = getFirstLine(command => 'sysctl -n hw.model');

# example on NetBSD: 0x807b65c
# example on OpenBSD: 2155570635
my $SystemSerial = getFirstLine(command => 'sysctl -n kern.hostid');
$bios->{SSN} = getFirstLine(command => 'sysctl -n kern.hostid');
# force hexadecimal, but remove 0x to make it appear as in the firmware
$SystemSerial = dec2hex($SystemSerial);
$SystemSerial =~ s/^0x//;
$bios->{SSN} = dec2hex($bios->{SSN});
$bios->{SSN} =~ s/^0x//;

my $processorn = getFirstLine(command => 'sysctl -n hw.ncpu');

Expand All @@ -52,14 +56,14 @@ sub doInventory {

my $processort;
foreach my $line (getAllLines(command => 'dmesg')) {
if ($line=~ /^mainbus0 \(root\):\s*(.*)$/) { $SystemModel = $1; }
if ($line=~ /^mainbus0 \(root\):\s*(.*)$/) { $bios->{SMODEL} = $1; }
if ($line =~ /^cpu[^:]*:\s*(.*)$/i) { $processort = $1; }
}

$SystemModel =~ s/SUNW,//;
$SystemModel =~ s/[:\(].*$//;
$SystemModel =~ s/^\s*//;
$SystemModel =~ s/\s*$//;
$bios->{SMODEL} =~ s/SUNW,//;
$bios->{SMODEL} =~ s/[:\(].*$//;
$bios->{SMODEL} =~ s/^\s*//;
$bios->{SMODEL} =~ s/\s*$//;

$processort =~ s/SUNW,//;
$processort =~ s/^\s*//;
Expand All @@ -71,11 +75,7 @@ sub doInventory {
$processors = sprintf("%.0f", "$1$2"); # round number
}

$inventory->setBios({
SMANUFACTURER => 'SUN',
SMODEL => $SystemModel,
SSN => $SystemSerial,
});
$inventory->setBios($bios);

for my $i (1 .. $processorn) {
$inventory->addEntry(
Expand Down
Expand Up @@ -44,35 +44,30 @@ sub doInventory {
);
}

my $SystemSerial = getFirstLine(file => '/proc/device-tree/serial-number');
$SystemSerial =~ s/[^\,^\.^\w^\ ]//g; # I remove some unprintable char
my $bios;

my $SystemModel = getFirstLine(file => '/proc/device-tree/model');
$SystemModel =~ s/[^\,^\.^\w^\ ]//g;
$bios->{SSN} = getFirstLine(file => '/proc/device-tree/serial-number');
$bios->{SSN} =~ s/[^\,^\.^\w^\ ]//g; # I remove some unprintable char

$bios->{SMODEL} = getFirstLine(file => '/proc/device-tree/model');
$bios->{SMODEL} =~ s/[^\,^\.^\w^\ ]//g;

my $colorCode = getFirstLine(file => '/proc/device-tree/color-code');
my ($color) = unpack "h7" , $colorCode;
$SystemModel .= " color: $color" if $color;
$bios->{SMODEL} .= " color: $color" if $color;

my $BiosVersion = getFirstLine(file => '/proc/device-tree/openprom/model');
$BiosVersion =~ s/[^\,^\.^\w^\ ]//g;
$bios->{BVERSION} =
getFirstLine(file => '/proc/device-tree/openprom/model');
$bios->{BVERSION} =~ s/[^\,^\.^\w^\ ]//g;

my ($BiosManufacturer, $SystemManufacturer);
my $copyright = getFirstLine(file => '/proc/device-tree/copyright');
if ($copyright && $copyright =~ /Apple/) {
# What about the Apple clone?
$BiosManufacturer = "Apple Computer, Inc.";
$SystemManufacturer = "Apple Computer, Inc."
$bios->{BMANUFACTURER} = "Apple Computer, Inc.";
$bios->{SMANUFACTURER} = "Apple Computer, Inc."
}

$inventory->setBios({
SMANUFACTURER => $SystemManufacturer,
SMODEL => $SystemModel,
SSN => $SystemSerial,
BMANUFACTURER => $BiosManufacturer,
BVERSION => $BiosVersion,
});

$inventory->setBios($bios);
}

sub _getCPUsFromProc {
Expand Down

0 comments on commit 1b2636c

Please sign in to comment.