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 12, 2012
2 parents 25fcb3b + 6bffb44 commit 423bdaf
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README
Expand Up @@ -92,12 +92,12 @@ better use first execution mode. The various installation procedure may offer
limited choice about initial configuration, but you should always be able to
change it thereafter.

When executing, the agent tries to runs every available task for every
When executing, the agent tries to run every available task for every
configured target. A task is a specific kind of work to perform (local
inventory, network discovery, wake on lan, etc...), while a target is both a
recipient for the result and a controller for this work (an OCS server, a GLPI
server, a local directory, etc...). Only the local inventory task is compatible
with all kind of targets, tough, all others require a GLPI server target, and
with all kind of target, tough, all others require a GLPI server target, and
will get discarded for other kind of target.

Configuration
Expand Down
22 changes: 21 additions & 1 deletion fusioninventory-agent
Expand Up @@ -278,7 +278,27 @@ List available tasks and exit
=item B<--no-category>=I<CATEGORY>
Do not list given category items in inventory.
Do not list given category items in inventory. It can be:
=over 4
=item
printer
=item
software
=item
environment
=item
process
=back
=item B<--scan-homedirs>
Expand Down
4 changes: 2 additions & 2 deletions lib/FusionInventory/Agent.pm
Expand Up @@ -510,6 +510,6 @@ Get all available tasks found on the system, as a list of module / version
pairs:
%tasks = (
'FusionInventory::Agent::Task::Foo' => x,
'FusionInventory::Agent::Task::Bar' => y,
'Foo' => x,
'Bar' => y,
);
9 changes: 3 additions & 6 deletions lib/FusionInventory/Agent/Task/Inventory.pm
Expand Up @@ -84,17 +84,14 @@ sub run {
last SWITCH;
}

if (-f $path) {
$file = $path;
last SWITCH;
}

if (-d $path) {
$file =
$path . "/" . $self->{deviceid} .
$format eq 'xml' ? '.ocs' : '.html';
($format eq 'xml' ? '.ocs' : '.html');
last SWITCH;
}

$file = $path;
}

if ($file) {
Expand Down
Expand Up @@ -37,7 +37,8 @@ sub doInventory {
}
}

# fallback on sysfs if udev didn't worked
# fallback on sysfs if /dev/.udev is not available. That's the
# case on any up to date Linux system
if (!@devices) {
@devices = getDevicesFromProc(logger => $logger);
}
Expand Down
Expand Up @@ -69,11 +69,10 @@ sub doInventory {
}

my $line = getFirstLine(
command => "zfs get org.opensolaris.libbe:uuid $filesystem->{VOLUMN}"
command => "zfs get creation $filesystem->{VOLUMN}"
);

if ($line && $line =~ /org.opensolaris.libbe:uuid\s+(\S{5}\S+)/) {
$filesystem->{UUID} = $1;
if ($line && $line =~ /creation\s+(\S.*\S+)\s-/) {
$filesystem->{FILESYSTEM} = 'zfs';
next;
}
Expand Down
Expand Up @@ -35,10 +35,14 @@ sub doInventory {
pattern => qr/(.*mcap.*)/
);

my $memcap = $line;
$memcap =~ s/[^\d]+//g;
my $memory = $memcap ?
$memcap / 1024 / 1024 : undef;
my $memory;

if ($line) {
my $memcap = $line;
$memcap =~ s/[^\d]+//g;
$memory = $memcap / 1024 / 1024;

}

my $vcpu = getFirstLine(command => '/usr/sbin/psrinfo -p');

Expand Down
1 change: 1 addition & 0 deletions lib/FusionInventory/Agent/Tools/Generic.pm
Expand Up @@ -53,6 +53,7 @@ sub getDmidecodeInfos {
next if
$2 eq 'N/A' ||
$2 eq 'Not Specified' ||
$2 eq '<BAD INDEX>' ||
$2 eq 'Not Present' ;

$block->{$1} = $2;
Expand Down
3 changes: 2 additions & 1 deletion lib/FusionInventory/Agent/Tools/Linux.pm
Expand Up @@ -411,7 +411,8 @@ This module provides some generic functions for Linux.
=head2 getDevicesFromUdev(%params)
Returns a list of devices, by parsing udev database.
Returns a list of devices, by parsing /dev/.udev directory.
This directory is not exported anymore with recent udev.
Availables parameters:
Expand Down
8 changes: 5 additions & 3 deletions lib/FusionInventory/Agent/Tools/Unix.pm
Expand Up @@ -288,6 +288,8 @@ sub getProcessesFromPs {
my $time = $10;
my $cmd = $11;

my $emailPattern = join ('|', keys %month);

# try to get a consistant time format
my $begin;
if ($started =~ /^(\d{1,2}):(\d{2})/) {
Expand All @@ -297,18 +299,18 @@ sub getProcessesFromPs {
# Sat03PM
my $start_day = $2;
$begin = sprintf("%04d-%02d-%02d %s", $year, $month, $start_day, $time);
} elsif ($started =~ /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(\d{2})/) {
} elsif ($started =~ /^($emailPattern)(\d{2})/) {
# Apr03
my $start_month = $1;
my $start_day = $2;
$begin = sprintf("%04d-%02d-%02d %s", $year, $month{$start_month}, $start_day, $time);
} elsif ($started =~ /^(\d{1,2})(\w{3})\d{1,2}/) {
} elsif ($started =~ /^(\d{1,2})($emailPattern)\d{1,2}/) {
# 5Oct10
my $start_day = $1;
my $start_month = $2;
$begin = sprintf("%04d-%02d-%02d %s", $year, $month{$start_month}, $start_day, $time);
} elsif (-f "/proc/$pid") {
# this will work only under Linux
# this will work only on OS with /proc/$pid like Linux and FreeBSD
my $stat = stat("/proc/$pid");
my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst)
= localtime($stat->ctime());
Expand Down
24 changes: 20 additions & 4 deletions t/apps/agent.t
Expand Up @@ -10,9 +10,9 @@ use XML::TreePP;

use FusionInventory::Agent::Tools;

use Test::More tests => 27;
use Test::More tests => 32;

my ($out, $err, $rc);
my ($content, $out, $err, $rc);

($out, $err, $rc) = run_agent('--help');
ok($rc == 2, '--help exit status');
Expand All @@ -32,6 +32,24 @@ like(
'--version stdin'
);

my $tmpFile = tmpnam();
($out, $err, $rc) = run_agent('--local '. $tmpFile);
ok($rc == 0, '--local exit status');
like(
$err,
qr/Inventory saved in $tmpFile/,
'--local /tmp/somefile'
);
$content = XML::TreePP->new()->parsefile($tmpFile);
ok($content, 'file output is valid XML');
unlink($tmpFile);

($out, $err, $rc) = run_agent('--local '. '-');
ok($rc == 0, '--local exit status');
$content = XML::TreePP->new()->parse($out);
ok($content, 'STDOUT output is valid XML');
unlink($tmpFile);


($out, $err, $rc) = run_agent();
ok($rc == 1, 'no target exit status');
Expand All @@ -44,8 +62,6 @@ is($out, '', 'no target stdin');

my $base_options = "--stdout --debug --no-task ocsdeploy,wakeonlan,snmpquery,netdiscovery";

my $content;

# first inventory
($out, $err, $rc) = run_agent(
"$base_options --no-category printer"
Expand Down

0 comments on commit 423bdaf

Please sign in to comment.