Skip to content

Commit

Permalink
fix: don't fail esx inventory because of a vm missing an uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
g-bougard committed Oct 3, 2023
1 parent 812d8d6 commit f9bbdde
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/GLPI/Agent/SOAP/VMware/Host.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use warnings;

use GLPI::Agent::Tools;
use GLPI::Agent::Tools::Virtualization;
use GLPI::Agent::Tools::UUID;

sub new {
my ($class, %params) = @_;
Expand Down Expand Up @@ -392,21 +393,23 @@ sub getVirtualMachines {
}

# Compute serialnumber set in bios by ESX
my @uuid_parts = unpack("A2A2A2A2xA2A2xA2A2xA2A2xA2A2A2A2A2A2", $machine->{summary}{config}{uuid});
my $serial = "VMware-".join(' ', @uuid_parts[0..7]).'-'.join(' ', @uuid_parts[8..15]);

push @virtualMachines,
{
my $uuid = $machine->{summary}{config}{uuid};
my $vmInventory = {
NAME => $machine->{name},
STATUS => $status,
UUID => $machine->{summary}{config}{uuid},
SERIAL => $serial,
UUID => $uuid,
MEMORY => $machine->{summary}{config}{memorySizeMB},
VMTYPE => 'VMware',
VCPU => $machine->{summary}{config}{numCpu},
MAC => join( '/', @mac ),
COMMENT => $comment
};
};
if (is_uuid_string($uuid)) {
my @uuid_parts = unpack("A2A2A2A2xA2A2xA2A2xA2A2xA2A2A2A2A2A2", $uuid);
$vmInventory->{SERIAL} = "VMware-".join(' ', @uuid_parts[0..7]).'-'.join(' ', @uuid_parts[8..15]);
}

push @virtualMachines, $vmInventory;
}

return @virtualMachines;
Expand Down

0 comments on commit f9bbdde

Please sign in to comment.