diff --git a/pandora_agents/ChangeLog b/pandora_agents/ChangeLog index 4283d504ec..e2b7ce311d 100644 --- a/pandora_agents/ChangeLog +++ b/pandora_agents/ChangeLog @@ -1,3 +1,10 @@ +2012-04-25 Sergio Martin + + * unix/plugins/inventory: Fixed several bugs in the + inventory plugin as missed separator to end the parse, + fill with empty string the empty columns, etc. for bug 3519796 + Merged from 4.0.x + 2012-04-25 Dario Rodriguez * win32/bin/pandora_agent.conf: Fixed a default module type. diff --git a/pandora_agents/unix/plugins/inventory b/pandora_agents/unix/plugins/inventory index 9a3e97c302..df01a30a95 100755 --- a/pandora_agents/unix/plugins/inventory +++ b/pandora_agents/unix/plugins/inventory @@ -31,7 +31,12 @@ my $Separator; sub get_module_data ($$$$) { my ($name, $hwinfo, $keys, $modules) = @_; my %module; - + + # Store keys + foreach my $key (@{$keys}) { + push (@{$module{'_keys'}}, $key); + } + # Parse module data while (my $line = shift (@{$hwinfo})) { if ($line =~ /$Separator/) { @@ -41,7 +46,8 @@ sub get_module_data ($$$$) { foreach my $key (@{$keys}) { if ($line =~ /$key:\s+(.+)/) { $module{$key} = $1; - push (@{$module{'_keys'}}, $key); + # Replace semicolon by comma to avoid parse errors + $module{$key} =~ s/;/,/g; } } } @@ -106,6 +112,8 @@ sub get_processes ($$) { my %module; # Remove carriage returns $row =~ s/[\n\l\f]//g; + # Replace semicolon by comma to avoid parse errors + $row =~ s/;/,/g; $module{'service'} = $row; $module{'_keys'} = ['service']; push (@{$modules->{$name}}, \%module); @@ -170,6 +178,10 @@ sub get_software_module_data ($$) { $module{'program'} = $1; $module{'version'} = $2; $module{'description'} = $3; + # Replace semicolon by comma to avoid parse errors + $module{'program'} =~ s/;/,/g; + $module{'version'} =~ s/;/,/g; + $module{'description'} =~ s/;/,/g; $module{'_keys'} = ['program', 'version','description']; push (@{$modules->{$name}}, \%module); } @@ -184,10 +196,12 @@ sub print_module ($$) { print " \n"; foreach my $item (@{$module}) { # Compose module data - my $data = ''; + my $data = undef; foreach my $key (@{$item->{'_keys'}}) { - next unless defined ($item->{$key}); - $data .= ($data eq '' ? '' : ';') . $item->{$key}; + $data = (!defined($data) ? '' : "$data;"); + if (defined($item->{$key})) { + $data .= $item->{$key}; + } } print " \n"; @@ -232,7 +246,7 @@ close (FILE); # Retrieve hardware information $Mode = 'LSHW'; -$Separator = ''; +$Separator = '\s+\*\-'; my @hwinfo = `lshw 2>/dev/null`; if ($? != 0) { $Mode = 'HWINFO';