Skip to content

Commit

Permalink
Merge remote branch 'origin/2.2.x' into 2.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonéri Le Bouder committed May 17, 2012
2 parents 31a1636 + ae38059 commit c7fee92
Show file tree
Hide file tree
Showing 17 changed files with 8,214 additions and 7,109 deletions.
2 changes: 1 addition & 1 deletion etc/agent.cfg
Expand Up @@ -46,7 +46,7 @@ scan-homedirs = 0
# save the inventory as HTML
html = 0
# timeout for inventory modules execution
backend-collect-timeout = 180
backend-collect-timeout = 30
# always send data to server
force = 0
# mark the machine with given tag
Expand Down
Expand Up @@ -84,7 +84,7 @@ sub _getScreensFromWindows {
foreach my $object (getWmiObjects(
class => 'Win32_DesktopMonitor',
properties => [ qw/
Caption MonitorManufacturer MonitorType PNPDeviceID
Caption MonitorManufacturer MonitorType PNPDeviceID Availability
/ ]
)) {
next unless $object->{Availability};
Expand Down
Expand Up @@ -52,6 +52,12 @@ sub doInventory {
if (!$cpu->{THREAD}) {
$cpu->{THREAD} = $procList->[$cpt]{THREAD};
}

# Get directly informations from cpuinfo if not already processed in dmidecode
$cpu->{STEPPING} = $procList->[$cpt]{STEPPING} unless $cpu->{STEPPING} ;
$cpu->{FAMILYNUMBER} = $procList->[$cpt]{FAMILYNUMBER} unless $cpu->{FAMILYNUMBER};
$cpu->{MODEL} = $procList->[$cpt]{MODEL} unless $cpu->{MODEL};

if ($cpu->{NAME} =~ /([\d\.]+)s*(GHZ)/i) {
$cpu->{SPEED} = {
ghz => 1000,
Expand Down Expand Up @@ -81,12 +87,16 @@ sub _getCPUsFromProc {
my $id = $cpu->{'physical id'};
$hasPhysicalId = 0;
if (defined $id) {
$cpus{$id}{STEPPING} = $cpu->{'stepping'};
$cpus{$id}{FAMILYNUMBER} = $cpu->{'cpu family'};
$cpus{$id}{MODEL} = $cpu->{'model'};
$cpus{$id}{CORE} = $cpu->{'cpu cores'};
$cpus{$id}{THREAD} = $cpu->{'siblings'} / ($cpu->{'cpu cores'} || 1);
$hasPhysicalId = 1;
}

push @cpuList, { CORE => 1, THREAD => 1 } unless $hasPhysicalId;
push @cpuList, {STEPPING => $cpu->{'stepping'},FAMILYNUMBER => $cpu->{'cpu family'},
MODEL => $cpu->{'model'}, CORE => 1, THREAD => 1 } unless $hasPhysicalId;
}
if (!$cpuNbr) {
$cpuNbr = keys %cpus;
Expand Down
109 changes: 78 additions & 31 deletions lib/FusionInventory/Agent/Task/Inventory/Input/MacOS/CPU.pm
Expand Up @@ -4,34 +4,86 @@ use strict;
use warnings;

use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::MacOS;

sub isEnabled {
return
-r '/usr/sbin/system_profiler' &&
canLoad("Mac::SysProfile");
-r '/usr/sbin/system_profiler';
}

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

my $inventory = $params{inventory};
my $logger = $params{logger};

my $prof = Mac::SysProfile->new();
my $info = $prof->gettype('SPHardwareDataType');
return unless ref $info eq 'HASH';
my $sysprofile = getSystemProfilerInfos(@_);

$info = $info->{'Hardware Overview'};


foreach my $cpu (_getCpus(logger => $logger)) {
$inventory->addEntry(
section => 'CPUS',
entry => $cpu
);
}


### mem convert it to meg's if it comes back in gig's
my $mem = $sysprofile->{'Memory'};
if ($mem =~ /GB$/){
$mem =~ s/\sGB$//;
$mem = ($mem * 1024);
} elsif ($mem =~ /MB$/){
$mem =~ s/\sMB$//;
}

$inventory->setHardware({
MEMORY => $mem,
});
}

sub _getCpus{

my (%params) = @_;
my $logger = $params{logger};

# Get more informations from sysctl
my $sysctl = getFileHandle (
logger => $logger,
command => 'sysctl -a machdep.cpu'
);

# System profiler informations
my $sysprofile = getSystemProfilerInfos(@_);


#add sysctl informations into profiler informations
my $info = $sysprofile->{'Hardware'}->{'Hardware Overview'};

while (my $line = <$sysctl>) {
chomp $line;
if ($line =~ /(.+) : \s (.+)/x) {
$info->{$1} = $2;
}
}

my $type = $info->{'Processor Name'} ||
$info->{'CPU Type'};
my $cpus = $info->{'Number Of Processors'} ||
my $procs = $info->{'Number Of Processors'} ||
$info->{'Number Of CPUs'} ||
1;
my $speed = $info->{'Processor Speed'} ||
$info->{'CPU Speed'};

my $stepping = $info->{'machdep.cpu.stepping'};

my $family = $info->{'machdep.cpu.family'};

my $model = $info->{'machdep.cpu.model'};

# French Mac returns 2,60 Ghz instead of 2.60 Ghz :D
$speed =~ s/,/./;

if ($speed =~ /GHz$/i) {
$speed =~ s/GHz//i;
$speed = $speed * 1000;
Expand All @@ -41,39 +93,34 @@ sub doInventory {
$speed =~ s/\s//g;

my $cores =
$info->{'Total Number Of Cores'} ? $info->{'Total Number Of Cores'} / $cpus :
$info->{'Total Number Of Cores'} ? $info->{'Total Number Of Cores'} / $procs :
1 ;

my $manufacturer =
$type =~ /Intel/i ? "Intel" :
$type =~ /AMD/i ? "AMD" :
undef ;

foreach (1 .. $cpus) {
$inventory->addEntry(
section => 'CPUS',
entry => {
CORE => $cores,
MANUFACTURER => $manufacturer,
NAME => $type,
THREAD => 1,
SPEED => $speed
}
);
}
my @cpus;
my $cpu={
CORE => $cores,
MANUFACTURER => $manufacturer,
NAME => $type,
THREAD => 1,
FAMILYNUMBER => $family,
MODEL => $model,
STEPPING => $stepping,
SPEED => $speed
};

### mem convert it to meg's if it comes back in gig's
my $mem = $info->{'Memory'};
if ($mem =~ /GB$/){
$mem =~ s/\sGB$//;
$mem = ($mem * 1024);
} elsif ($mem =~ /MB$/){
$mem =~ s/\sMB$//;
for (my $i=0;$i<$procs;$i++) {
push @cpus, $cpu;
}

$inventory->setHardware({
MEMORY => $mem,
});
return $cpu;

}



1;
6 changes: 6 additions & 0 deletions lib/FusionInventory/Agent/Task/Inventory/Input/Win32/CPU.pm
Expand Up @@ -56,6 +56,9 @@ sub _getCPUs {
my $dmidecodeInfo = $dmidecodeInfos[$cpuId];
my $registryInfo = $registryInfos->{"$cpuId/"};

# Split CPUID from its value inside registry
my @splitted_identifier = split(/ |\n/ ,$registryInfo->{'/Identifier'});

my $cpu = {
CORE => $dmidecodeInfo->{CORE} || $object->{NumberOfCores},
THREAD => $dmidecodeInfo->{THREAD},
Expand All @@ -64,6 +67,9 @@ sub _getCPUs {
MANUFACTURER => $registryInfo->{'/VendorIdentifier'},
SERIAL => $dmidecodeInfo->{SERIAL},
SPEED => $dmidecodeInfo->{SPEED} || $object->{MaxClockSpeed},
FAMILYNUMBER => $splitted_identifier[2],
MODEL => $splitted_identifier[4],
STEPPING => $splitted_identifier[6],
ID => $dmidecodeInfo->{ID} || $object->{ProcessorId}
};

Expand Down
56 changes: 51 additions & 5 deletions lib/FusionInventory/Agent/Task/Inventory/Input/Win32/Softwares.pm
Expand Up @@ -29,7 +29,11 @@ sub doInventory {
my $inventory = $params{inventory};
my $logger = $params{logger};

if (is64bit()) {
my $is64bit = is64bit();

my $kbList = _getKB(is64bit => $is64bit);

if ($is64bit) {

# I don't know why but on Vista 32bit, KEY_WOW64_64 is able to read
# 32bit entries. This is not the case on Win2003 and if I correctly
Expand All @@ -44,7 +48,8 @@ sub doInventory {

foreach my $software (_getSoftwares(
softwares => $softwares64,
is64bit => 1
is64bit => 1,
kbList => $kbList
)) {
_addSoftware(inventory => $inventory, entry => $software);
}
Expand All @@ -64,7 +69,8 @@ sub doInventory {
foreach my $software (_getSoftwares(
softwares => $softwares32,
is64bit => 0,
logger => $logger
logger => $logger,
kbList => $kbList
)) {
_addSoftware(inventory => $inventory, entry => $software);
}
Expand All @@ -85,7 +91,8 @@ sub doInventory {

foreach my $software (_getSoftwares(
softwares => $softwares,
is64bit => 0
is64bit => 0,
kbList => $kbList
)) {
_addSoftware(inventory => $inventory, entry => $software);
}
Expand All @@ -95,6 +102,11 @@ sub doInventory {
is64bit => 0
);
}

foreach (values %$kbList) {
_addSoftware(inventory => $inventory, entry => $_);
}

}

sub _dateFormat {
Expand All @@ -118,6 +130,7 @@ sub _getSoftwares {
my (%params) = @_;

my $softwares = $params{softwares};
my $kbList = $params{kbList};

my @softwares;

Expand All @@ -140,7 +153,7 @@ sub _getSoftwares {
encodeFromRegistry($guid), # folder name
COMMENTS => encodeFromRegistry($data->{'/Comments'}),
HELPLINK => encodeFromRegistry($data->{'/HelpLink'}),
RELEASETYPE => encodeFromRegistry($data->{'/ReleaseType'}),
RELEASE_TYPE => encodeFromRegistry($data->{'/ReleaseType'}),
VERSION => encodeFromRegistry($data->{'/DisplayVersion'}),
PUBLISHER => encodeFromRegistry($data->{'/Publisher'}),
URL_INFO_ABOUT => encodeFromRegistry($data->{'/URLInfoAbout'}),
Expand All @@ -156,12 +169,45 @@ sub _getSoftwares {
# Workaround for #415
$software->{VERSION} =~ s/[\000-\037].*// if $software->{VERSION};

if ($software->{NAME} =~ /KB(\d{4,10})/i) {
delete($kbList->{$1});
}

push @softwares, $software;
}

return @softwares;
}

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

my $kbList = {};

foreach my $object (getWmiObjects(
class => 'Win32_QuickFixEngineering',
properties => [ qw/HotFixID Description/ ]
)) {

my $releaseType;
if ($object->{Description} && $object->{Description} =~ /^(Security Update|Hotfix|Update)/) {
$releaseType = $1;
}

next unless $object->{HotFixID} =~ /KB(\d{4,10})/i;
$kbList->{$1} = {
NAME => $object->{HotFixID},
COMMENTS => $object->{Description},
FROM => "WMI",
RELEASE_TYPE => $releaseType,
ARCH => $params{is64bit} ? 'x86_64' : 'i586'
};

}

return $kbList;
}

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

Expand Down
20 changes: 18 additions & 2 deletions lib/FusionInventory/Agent/Task/Inventory/Inventory.pm
Expand Up @@ -18,7 +18,7 @@ my %fields = (
CONTROLLERS => [ qw/CAPTION DRIVER NAME MANUFACTURER PCICLASS PCIID
PCISUBSYSTEMID PCISLOT TYPE REV/ ],
CPUS => [ qw/CACHE CORE DESCRIPTION MANUFACTURER NAME THREAD SERIAL
SPEED ID EXTERNAL_CLOCK/ ],
STEPPING FAMILYNAME FAMILYNUMBER MODEL SPEED ID EXTERNAL_CLOCK/ ],
DRIVES => [ qw/CREATEDATE DESCRIPTION FREE FILESYSTEM LABEL LETTER
SERIAL SYSTEMDRIVE TOTAL TYPE VOLUMN/ ],
ENVS => [ qw/KEY VAL/ ],
Expand All @@ -41,7 +41,7 @@ my %fields = (
SOFTWARES => [ qw/COMMENTS FILESIZE FOLDER FROM HELPLINK INSTALLDATE NAME
NO_REMOVE RELEASE_TYPE PUBLISHER UNINSTALL_STRING
URL_INFO_ABOUT VERSION VERSION_MINOR VERSION_MAJOR
GUID RELEASETYPE ARCH/ ],
GUID ARCH/ ],
SOUNDS => [ qw/CAPTION DESCRIPTION MANUFACTURER NAME/ ],
STORAGES => [ qw/DESCRIPTION DISKSIZE INTERFACE MANUFACTURER MODEL NAME
TYPE SERIAL SERIALNUMBER FIRMWARE SCSI_COID SCSI_CHID
Expand Down Expand Up @@ -685,6 +685,22 @@ Frequency in MHz
The CPU ID: http://en.wikipedia.org/wiki/CPUID
=item STEPPING
Stepping value (Contained in CPUID)
=item MODEL
Model value (Contained in CPUID)
=item FAMILYNUMBER
Family value (Contained in CPUID)
=item FAMILYNAME
Family Name
=back
=head2 DRIVES
Expand Down

0 comments on commit c7fee92

Please sign in to comment.