Skip to content

Commit

Permalink
Merge remote-tracking branch 'forge/2.3.x' into 2.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch committed Jul 9, 2012
2 parents 9220492 + a18d430 commit c344ad7
Show file tree
Hide file tree
Showing 19 changed files with 207 additions and 55 deletions.
4 changes: 3 additions & 1 deletion Changes
Expand Up @@ -3,20 +3,22 @@ Revision history for FusionInventory agent
2.3.0
General:
* various UTF8 encoding fixes
* Add DNS_DOMAIN and FQDN in OPERATINGSYSTEM section

BSD:
* Megaraid and 3ware RAID controller support (Egor Morozov)

Linux:
* Megaraid controller support (Egor Morozov)

2.2.3
2.2.3 Mon, 25 Jun 2012 21:36:29 +0200
General:
* Fix battery voltage and capacity retrieval
* Add --timeout option

MacOSX:
* Fix global memory and CPU inventory
* Fix drives inventory

Linux:
* LXC support (Egor Morozov)
Expand Down
1 change: 0 additions & 1 deletion README
Expand Up @@ -24,7 +24,6 @@ Additional mandatory perl modules:
- LWP
- Net::IP
- UNIVERSAL::require
- Mac::SysProfile (MacOs only)

Additional optional perl modules:
- Compress::Zlib, for message compression
Expand Down
3 changes: 3 additions & 0 deletions fusioninventory-agent
Expand Up @@ -370,6 +370,9 @@ The network port to use for the embedded web server (62354).
Trust requests from given range without authentication token (false).
For example: "192.168.0.0/24", "192.68.168.0.5" or an IP range like
"20.34.101.207 - 201.3.9.99". See L<Net::IP> documentation to get more example.
=back
=head2 Logging options
Expand Down
2 changes: 1 addition & 1 deletion lib/FusionInventory/Agent.pm
Expand Up @@ -23,7 +23,7 @@ use FusionInventory::Agent::XML::Query::Prolog;

our $VERSION = '2.3.0';
our $VERSION_STRING =
"FusionInventory unified agent for UNIX, Linux and MacOSX ($VERSION)";
"FusionInventory Agent ($VERSION)";
our $AGENT_STRING =
"FusionInventory-Agent_v$VERSION";

Expand Down
5 changes: 4 additions & 1 deletion lib/FusionInventory/Agent/Task/Inventory/Input/Generic.pm
Expand Up @@ -4,6 +4,7 @@ use strict;
use warnings;

use English qw(-no_match_vars);
use Net::Domain qw(hostfqdn hostdomain);

sub isEnabled {
return 1;
Expand All @@ -15,7 +16,9 @@ sub doInventory {
my $inventory = $params{inventory};

$inventory->setOperatingSystem({
KERNEL_NAME => $OSNAME
KERNEL_NAME => $OSNAME,
FQDN => hostfqdn(),
DNS_DOMAIN => hostdomain()
});
}

Expand Down
Expand Up @@ -112,7 +112,7 @@ sub doInventory {
my $inventory = $params{inventory};
my $logger = $params{logger};

Parse::EDID->requires();
Parse::EDID->require();

foreach my $screen (_getScreens($logger)) {

Expand Down
Expand Up @@ -30,7 +30,9 @@ sub _parseMegasasctl {
}

my $storage;
$storage->{NAME} = "$vendor $model";
$storage->{NAME} = $disk_addr;
$storage->{MANUFACTURER} = $vendor;
$storage->{MODEL} = $model;
$storage->{DESCRIPTION} = 'SAS';
$storage->{TYPE} = 'disk';
$storage->{DISKSIZE} = $size;
Expand Down
Expand Up @@ -15,7 +15,6 @@ sub doInventory {
my $inventory = $params{inventory};
my $logger = $params{inventory};

my $command = 'jls -n';
foreach my $machine (_getVirtualMachines(logger => $logger)) {
$inventory->addEntry(
section => 'VIRTUALMACHINES', entry => $machine
Expand All @@ -38,8 +37,6 @@ sub _getVirtualMachines {
my $info;
foreach my $item (split(' ', $line)) {
next unless $item =~ /(\S+)=(\S+)/;
my $key = $1;
my $value = $2;
$info->{$1} = $2;
}

Expand Down
Expand Up @@ -11,6 +11,7 @@ use Win32::TieRegistry (
ArrayValues => 0,
qw/KEY_READ/
);
use File::Basename;

use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Win32;
Expand All @@ -23,6 +24,56 @@ sub isEnabled {
return !$params{no_category}->{software};
}

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

my $inventory = $params{inventory};
my $is64bit = is64bit();


my $lmachine = $Registry->Open('LMachine');

my $profileList =
$lmachine->{"SOFTWARE/Microsoft/Windows NT/CurrentVersion/ProfileList"};

return unless $profileList;

$Registry->AllowLoad(1);

foreach my $profileName (keys %$profileList) {
next unless length($profileName) > 10;

my $profilePath = $profileList->{$profileName}{'/ProfileImagePath'};
my $sid = $profileList->{$profileName}{'/Sid'};

next unless $sid;
next unless $profilePath;

$profilePath =~ s/%SystemDrive%/$ENV{SYSTEMDRIVE}/i;

my $user = basename($profilePath);
my $userKey = $is64bit ?
$Registry->Load($profilePath.'\ntuser.dat', { Access=> KEY_READ | KEY_WOW64_64 } ) :
$Registry->Load($profilePath.'\ntuser.dat', { Access=> KEY_READ } ) ;

my $softwares =
$userKey->{"SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall"};

foreach my $software (_getSoftwares(
softwares => $softwares,
is64bit => 1,
userid => $sid,
username => $user
)) {
_addSoftware(inventory => $inventory, entry => $software);
}

}
$Registry->AllowLoad(0);

}


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

Expand Down Expand Up @@ -58,6 +109,10 @@ sub doInventory {
inventory => $inventory,
is64bit => 1
);
_loadUserSoftware(
inventory => $inventory,
is64bit => 1
);

my $machKey32 = $Registry->Open('LMachine', {
Access => KEY_READ | KEY_WOW64_32 ## no critic (ProhibitBitwise)
Expand All @@ -79,6 +134,10 @@ sub doInventory {
inventory => $inventory,
is64bit => 0
);
_loadUserSoftware(
inventory => $inventory,
is64bit => 0
);


} else {
Expand All @@ -101,6 +160,11 @@ sub doInventory {
inventory => $inventory,
is64bit => 0
);
_loadUserSoftware(
inventory => $inventory,
is64bit => 0
);

}

foreach (values %$kbList) {
Expand Down Expand Up @@ -130,7 +194,7 @@ sub _getSoftwares {
my (%params) = @_;

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

my @softwares;

Expand Down Expand Up @@ -164,6 +228,8 @@ sub _getSoftwares {
NO_REMOVE => hex2dec($data->{'/NoRemove'}),
ARCH => $params{is64bit} ? 'x86_64' : 'i586',
GUID => $guid,
USERNAME => $params{username},
USERID => $params{userid},
};

# Workaround for #415
Expand Down
12 changes: 10 additions & 2 deletions lib/FusionInventory/Agent/Task/Inventory/Inventory.pm
Expand Up @@ -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 ARCH/ ],
GUID ARCH USERNAME USERID/ ],
SOUNDS => [ qw/CAPTION DESCRIPTION MANUFACTURER NAME/ ],
STORAGES => [ qw/DESCRIPTION DISKSIZE INTERFACE MANUFACTURER MODEL NAME
TYPE SERIAL SERIALNUMBER FIRMWARE SCSI_COID SCSI_CHID
Expand All @@ -63,7 +63,7 @@ my %fields = (
DEFAULTGATEWAY VMSYSTEM WINOWNER WINPRODID
WINPRODKEY WINCOMPANY WINLANG CHASSIS_TYPE/ ],
OPERATINGSYSTEM => [ qw/KERNEL_NAME KERNEL_VERSION NAME VERSION FULL_NAME
SERVICE_PACK INSTALL_DATE/ ],
SERVICE_PACK INSTALL_DATE FQDN DNS_DOMAIN/ ],
ACCESSLOG => [ qw/USERID LOGDATE/ ],
VIRTUALMACHINES => [ qw/MEMORY NAME UUID STATUS SUBSYSTEM VMTYPE VCPU
VMID MAC COMMENT OWNER/ ],
Expand Down Expand Up @@ -1104,6 +1104,14 @@ If the software is in 32 or 64bit, (1/0)
Windows software GUID
=item USERNAME
Name of the owner of the software.
=item USERID
ID of the owner of the software. SID on Windows.
=back
=head2 USERS
Expand Down
13 changes: 3 additions & 10 deletions lib/FusionInventory/Agent/Tools.pm
Expand Up @@ -45,6 +45,8 @@ our @EXPORT = qw(
delay
);

my $nowhere = $OSNAME eq 'MSWin32' ? 'nul' : '/dev/null';

# this trigger some errors on Perl 5.12/Win32:
# Anonymous function called in forbidden scalar context
if ($OSNAME ne 'MSWin32') {
Expand Down Expand Up @@ -231,16 +233,7 @@ sub getFileHandle {
last SWITCH;
}
if ($params{command}) {
if ($OSNAME eq 'MSWin32') {
FusionInventory::Agent::Tools::Win32->require;
(undef, $handle) = FusionInventory::Agent::Tools::Win32::runCommand(
command => $params{command},
no_stderr => 1
);
if (!$handle) {
return;
}
} elsif (!open $handle, '-|', $params{command} . " 2>/dev/null") {
if (!open $handle, '-|', $params{command} . " 2>$nowhere") {
$params{logger}->error(
"Can't run command $params{command}: $ERRNO"
) if $params{logger};
Expand Down
4 changes: 2 additions & 2 deletions lib/FusionInventory/Agent/Tools/Linux.pm
Expand Up @@ -201,7 +201,7 @@ sub getDevicesFromProc {
my %seen;
@names = grep { !$seen{$_}++ } @names;

# extract informations
# extract information
my @devices;
foreach my $name (@names) {
my $device = {
Expand Down Expand Up @@ -465,7 +465,7 @@ Availables parameters:
=head2 getInfoFromSmartctl(%params)
Returns some informations about a drive, using smartctl.
Returns some information about a drive, using smartctl.
Availables parameters:
Expand Down
8 changes: 7 additions & 1 deletion lib/FusionInventory/Agent/Tools/Win32.pm
Expand Up @@ -23,6 +23,8 @@ use utf8;
use File::Temp qw(:seekable tempfile);
use Win32::Job;

use Cwd;

Win32::OLE->Option(CP => Win32::OLE::CP_UTF8);

use FusionInventory::Agent::Tools;
Expand Down Expand Up @@ -179,7 +181,11 @@ sub runCommand {
my $buff = File::Temp->new();
my $void = File::Temp->new();

my ($fh, $filename) = File::Temp::tempfile( "$ENV{TEMP}/fusinvXXXXXXXXXXX", SUFFIX => '.bat');
my $winCwd = Cwd::getcwd();
$winCwd =~ s{/}{\\}g;

my ($fh, $filename) = File::Temp::tempfile( "$ENV{TEMP}\\fusinvXXXXXXXXXXX", SUFFIX => '.bat');
print $fh "cd \"".$winCwd."\"\r\n";
print $fh $params{command}."\r\n";
print $fh "exit %ERRORLEVEL%\r\n";
close $fh;
Expand Down
2 changes: 1 addition & 1 deletion t/apps/agent.t
Expand Up @@ -28,7 +28,7 @@ ok($rc == 0, '--version exit status');
is($err, '', '--version stderr');
like(
$out,
qr/^FusionInventory unified agent for UNIX, Linux and MacOSX/,
qr/^FusionInventory Agent/,
'--version stdin'
);

Expand Down
4 changes: 2 additions & 2 deletions t/inventory/bsd/storages.t
Expand Up @@ -72,12 +72,12 @@ my %tests_mfiutil = (
]
);

plan tests => scalar keys (%tests) + scalar keys (%tests_mfiutil);
plan tests => scalar keys (%tests_fstab) + scalar keys (%tests_mfiutil);

foreach my $test (keys %tests_fstab) {
my $file = "resources/bsd/fstab/$test";
my @results = FusionInventory::Agent::Task::Inventory::Input::BSD::Storages::_getDevicesFromFstab(file => $file);
is_deeply(\@results, $tests{$test}, $test);
is_deeply(\@results, $tests_fstab{$test}, $test);
}

foreach my $test (keys %tests_mfiutil) {
Expand Down

0 comments on commit c344ad7

Please sign in to comment.