mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 23:54:18 +02:00
(plugin) hardware::server::hp::ilo::restapi - mode hardware ignore som… (#4349)
This commit is contained in:
parent
0072f02e85
commit
36c1b12458
@ -84,7 +84,12 @@ sub get_devices {
|
|||||||
$self->get_chassis() if (!defined($self->{chassis}));
|
$self->get_chassis() if (!defined($self->{chassis}));
|
||||||
foreach my $chassis (@{$self->{chassis}}) {
|
foreach my $chassis (@{$self->{chassis}}) {
|
||||||
$chassis->{Devices} = [];
|
$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}}) {
|
foreach (@{$result->{Members}}) {
|
||||||
my $device_detailed = $self->{custom}->request_api(url_path => $_->{'@odata.id'});
|
my $device_detailed = $self->{custom}->request_api(url_path => $_->{'@odata.id'});
|
||||||
push @{$chassis->{Devices}}, $device_detailed;
|
push @{$chassis->{Devices}}, $device_detailed;
|
||||||
@ -135,7 +140,12 @@ sub get_storages {
|
|||||||
$self->{storages} = [];
|
$self->{storages} = [];
|
||||||
my $systems = $self->{custom}->request_api(url_path => '/redfish/v1/Systems');
|
my $systems = $self->{custom}->request_api(url_path => '/redfish/v1/Systems');
|
||||||
foreach my $system (@{$systems->{Members}}) {
|
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}}) {
|
foreach my $storage (@{$storages->{Members}}) {
|
||||||
my $storage_detailed = $self->{custom}->request_api(url_path => $storage->{'@odata.id'});
|
my $storage_detailed = $self->{custom}->request_api(url_path => $storage->{'@odata.id'});
|
||||||
push @{$self->{storages}}, $storage_detailed;
|
push @{$self->{storages}}, $storage_detailed;
|
||||||
|
@ -191,26 +191,34 @@ sub request_api {
|
|||||||
$self->authenticate(statefile => $self->{cache});
|
$self->authenticate(statefile => $self->{cache});
|
||||||
}
|
}
|
||||||
|
|
||||||
my $content = $self->{http}->request(%options,
|
my $content = $self->{http}->request(
|
||||||
|
%options,
|
||||||
warning_status => '', unknown_status => '', critical_status => ''
|
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.
|
# 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->clean_token(statefile => $self->{cache});
|
||||||
$self->authenticate(statefile => $self->{cache});
|
$self->authenticate(statefile => $self->{cache});
|
||||||
$content = $self->{http}->request(%options,
|
$content = $self->{http}->request(
|
||||||
|
%options,
|
||||||
warning_status => '', unknown_status => '', critical_status => ''
|
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);
|
my $decoded = $self->json_decode(content => $content);
|
||||||
if (!defined($decoded)) {
|
if (!defined($decoded)) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)");
|
$self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)");
|
||||||
$self->{output}->option_exit();
|
$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}->add_option_msg(short_msg => 'api request error: ' . (defined($decoded->{type}) ? $decoded->{type} : 'unknown'));
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user