diff --git a/src/centreon/common/redfish/restapi/mode/hardware.pm b/src/centreon/common/redfish/restapi/mode/hardware.pm index ea838db72..348d5e6e6 100644 --- a/src/centreon/common/redfish/restapi/mode/hardware.pm +++ b/src/centreon/common/redfish/restapi/mode/hardware.pm @@ -84,7 +84,12 @@ sub get_devices { $self->get_chassis() if (!defined($self->{chassis})); foreach my $chassis (@{$self->{chassis}}) { $chassis->{Devices} = []; - my $result = $self->{custom}->request_api(url_path => $chassis->{'@odata.id'} . 'Devices/'); + my $result = $self->{custom}->request_api( + url_path => $chassis->{'@odata.id'} . 'Devices/', + ignore_codes => { 404 => 1 } + ); + next if (!defined($result)); + foreach (@{$result->{Members}}) { my $device_detailed = $self->{custom}->request_api(url_path => $_->{'@odata.id'}); push @{$chassis->{Devices}}, $device_detailed; @@ -135,7 +140,12 @@ sub get_storages { $self->{storages} = []; my $systems = $self->{custom}->request_api(url_path => '/redfish/v1/Systems'); foreach my $system (@{$systems->{Members}}) { - my $storages = $self->{custom}->request_api(url_path => $system->{'@odata.id'} . '/Storage/'); + my $storages = $self->{custom}->request_api( + url_path => $system->{'@odata.id'} . '/Storage/', + ignore_codes => { 400 => 1, 404 => 1 } + ); + next if (!defined($storages)); + foreach my $storage (@{$storages->{Members}}) { my $storage_detailed = $self->{custom}->request_api(url_path => $storage->{'@odata.id'}); push @{$self->{storages}}, $storage_detailed; diff --git a/src/hardware/server/hp/ilo/restapi/custom/api.pm b/src/hardware/server/hp/ilo/restapi/custom/api.pm index f8523a0f2..0af66d642 100644 --- a/src/hardware/server/hp/ilo/restapi/custom/api.pm +++ b/src/hardware/server/hp/ilo/restapi/custom/api.pm @@ -191,26 +191,34 @@ sub request_api { $self->authenticate(statefile => $self->{cache}); } - my $content = $self->{http}->request(%options, + my $content = $self->{http}->request( + %options, warning_status => '', unknown_status => '', critical_status => '' ); + my $code = $self->{http}->get_code(); + return undef if (defined($options{ignore_codes}) && defined($options{ignore_codes}->{$code})); + # Maybe there is an issue with the token. So we retry. - if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) { + if ($code < 200 || $code >= 300) { $self->clean_token(statefile => $self->{cache}); $self->authenticate(statefile => $self->{cache}); - $content = $self->{http}->request(%options, + $content = $self->{http}->request( + %options, warning_status => '', unknown_status => '', critical_status => '' ); + $code = $self->{http}->get_code(); } + return undef if (defined($options{ignore_codes}) && defined($options{ignore_codes}->{$code})); + my $decoded = $self->json_decode(content => $content); if (!defined($decoded)) { $self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)"); $self->{output}->option_exit(); } - if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) { + if ($code < 200 || $code >= 300) { $self->{output}->add_option_msg(short_msg => 'api request error: ' . (defined($decoded->{type}) ? $decoded->{type} : 'unknown')); $self->{output}->option_exit(); }