From 4c1cad8393fee95632a7fd4b9009548811f21a70 Mon Sep 17 00:00:00 2001 From: Guillaume Bougard Date: Wed, 20 Dec 2023 10:41:50 +0100 Subject: [PATCH] fix: Fix wrong 'n/a' ko status report to tasks managed by GLPI Inventory plugin Closes glpi-project/glpi-inventory-plugin#456 --- Changes | 1 + lib/GLPI/Agent/SOAP/VMware.pm | 12 +++++++++--- lib/GLPI/Agent/Task/ESX.pm | 7 +++++-- lib/GLPI/Agent/Task/NetDiscovery.pm | 1 - 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index acfce6f2b..f0c55ed8f 100644 --- a/Changes +++ b/Changes @@ -51,6 +51,7 @@ netdiscovery/netinventory: esx: * Fix first connection timeout support * Added --timeout option support to glpi-esx +* Fix wrong 'n/a' ko status report to tasks managed by GLPI Inventory plugin toolbox: * fix #533: Fix Toolbox export buttons in inventory results diff --git a/lib/GLPI/Agent/SOAP/VMware.pm b/lib/GLPI/Agent/SOAP/VMware.pm index a020c0cf4..1aa98269d 100644 --- a/lib/GLPI/Agent/SOAP/VMware.pm +++ b/lib/GLPI/Agent/SOAP/VMware.pm @@ -42,6 +42,12 @@ sub timeout { return $self->{ua}->timeout($timeout); } +sub lastError { + my ($self) = @_; + + return $self->{_lastError} // ''; +} + sub _send { my ( $self, $action, $xmlToSend ) = @_; @@ -69,7 +75,7 @@ sub _send { if ( $tmpRef && $tmpRef->{faultstring} ) { $errorString .= ": " . $tmpRef->{faultstring}; } - $self->{lastError} = $errorString; + $self->{_lastError} = $errorString; return; } @@ -116,13 +122,13 @@ sub connect { my ( $self, $user, $password ) = @_; unless ($user) { - $self->{lastError} = "No user".($self->{lastError} ? "" : " and password"). + $self->{_lastError} = "No user".($self->{lastError} ? "" : " and password"). " provided for ESX connection"; return; } unless ($password) { - $self->{lastError} = "No password provided for ESX connection"; + $self->{_lastError} = "No password provided for ESX connection"; return; } diff --git a/lib/GLPI/Agent/Task/ESX.pm b/lib/GLPI/Agent/Task/ESX.pm index 34e78a5ab..193d80e89 100644 --- a/lib/GLPI/Agent/Task/ESX.pm +++ b/lib/GLPI/Agent/Task/ESX.pm @@ -40,7 +40,7 @@ sub connect { timeout => $self->timeout(), ); if ( !$vpbs->connect( $params{user}, $params{password} ) ) { - $self->lastError($vpbs->{lastError}); + $self->lastError($vpbs->lastError() || "Connection failure"); return; } @@ -330,9 +330,12 @@ sub serverInventory { sub lastError { my ($self, $error) = @_; + $self->{lastError} = $self->{esx}->lastError() + if $self->{esx}; + $self->{lastError} = $error if $error; - return $self->{lastError} || "n/a"; + return $self->{lastError}; } sub timeout { diff --git a/lib/GLPI/Agent/Task/NetDiscovery.pm b/lib/GLPI/Agent/Task/NetDiscovery.pm index 970f794e3..f15321331 100644 --- a/lib/GLPI/Agent/Task/NetDiscovery.pm +++ b/lib/GLPI/Agent/Task/NetDiscovery.pm @@ -973,7 +973,6 @@ sub _scanAddressByRemote { } else { $error = $esxscan->lastError(); my %errors = ( - 'n/a' => '', '405 Method Not Allowed' => 'not supporting VMWare SOAP API' ); $error = $errors{$error} if $errors{$error};