Mac::SysProfile.pm gettype changes for compatibility with MacOS 10.6 & 10.7
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OCS Inventory: Unified Unix Agent |
In Progress
|
Undecided
|
mortheres |
Bug Description
Hello,
due to the changes of Apple's system_profiler in MacOS X 10.6 and 10.7, here is the gettype function of Mac/SysProfile.pm which reports the memory, the storage and the cpu correctly to the server.
While creating the hash for the Storages.pm, the keys $hdr had the same value. For example, I had $hdr = Intel 6 Series Chipset for every different storage in my computer. In case this happens, I used a workaround to rename each one of it to:
Intel 6 Series Chipset 1
Intel 6 Series Chipset 2
Intel 6 Series Chipset 3
......
If I kept the original name, the hash only contained the values of the last key with the same name.
sub gettype {
my ($pro, $typ, $fre) = @_;
$pro->types() unless exists $types{$typ};
if(!exists $types{$typ}) {
delete $pro->{$typ};
return undef;
}
my $raw = $fre || !$pro->{$typ} ? `$conf{bin} $typ` : $pro->{$typ};
my $hdr = '';
my($k,$v,$k2);
my $counter = 0;
for(split /\n/, $raw) {
next if m/^\s*$/ || m/^\w/;
$hdr = $_;
$hdr =~ s/^\s+//;
$hdr =~ s/:.*$//;
if ($counter > 0) {
}
} elsif(m/^\s{6}\w/) {
($k,$v) = split /:\s+/;
} else {
}
} elsif(m/^\s{8}\w/) {
$k2 = $_;
$k2 =~ s/^\s+//;
$k2 =~ s/:.*$//;
} else {
}
} elsif(m/^\s{10}\w/) {
} else {
}
}
}
return $pro->{$typ};
}
Regards,
Andreas
Changed in ocsinventory-unix-agent: | |
assignee: | nobody → mortheres (mortheres) |
Changed in ocsinventory-unix-agent: | |
status: | New → In Progress |
In the 10 whitespaces els if statement, there should be a check for $k2. If it doesn't exist, an undefined variable error is returned:
if ($k2) {
$pro-> {$typ}- >{$hdr} ->{$k2} ->{$k3} = $v3;
$pro-> {$typ}- >{$k2}- >{$k3} = $v3;
$pro- >{$typ} ->{$hdr} ->{$k3} = $v3;
$pro->{ $typ}-> {$k3} = $v3;
if($hdr) {
} else {
}
} else {
if ($hdr) {
} else {
}
}
I have also modified the code in order to enable automatic calculation of the whitespaces, instead of declaring by hand the four cases (4, 6, 8, 10 whitespaces).
Andreas