From f9bbdde455842d31a0edf6d4ef067b4ce58c963c Mon Sep 17 00:00:00 2001 From: Guillaume Bougard Date: Tue, 3 Oct 2023 19:08:03 +0200 Subject: [PATCH] fix: don't fail esx inventory because of a vm missing an uuid --- lib/GLPI/Agent/SOAP/VMware/Host.pm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/GLPI/Agent/SOAP/VMware/Host.pm b/lib/GLPI/Agent/SOAP/VMware/Host.pm index 25859d70c..2938ee183 100644 --- a/lib/GLPI/Agent/SOAP/VMware/Host.pm +++ b/lib/GLPI/Agent/SOAP/VMware/Host.pm @@ -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) = @_; @@ -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;