(plugin) hardware::server::hp::ilo::xmlapi - add option --force-ilo2 option (#3527)

This commit is contained in:
qgarnier 2022-03-08 10:39:11 +01:00 committed by GitHub
parent b0b7838cd8
commit 4fd85b4eae
1 changed files with 43 additions and 27 deletions

View File

@ -47,7 +47,8 @@ sub new {
'port:s' => { name => 'port', default => 443 },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'force-ilo3' => { name => 'force_ilo3' }
'force-ilo3' => { name => 'force_ilo3' },
'force-ilo2' => { name => 'force_ilo2' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'XML API OPTIONS', once => 1);
@ -55,6 +56,9 @@ sub new {
$self->{output} = $options{output};
$self->{http} = centreon::plugins::http->new(%options);
$self->{ilo2} = 0;
$self->{ilo3} = 0;
return $self;
}
@ -102,9 +106,10 @@ sub check_options {
sub find_ilo_version {
my ($self, %options) = @_;
($self->{ilo2}, $self->{ilo3}) = (0, 0);
my $client = new IO::Socket::SSL->new(PeerAddr => $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port},
eval $self->{ssl_opts}, Timeout => $self->{option_results}->{timeout});
my $client = new IO::Socket::SSL->new(
PeerAddr => $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port},
eval $self->{ssl_opts}, Timeout => $self->{option_results}->{timeout}
);
if (!$client) {
$self->{output}->add_option_msg(short_msg => "Failed to establish SSL connection: $!, ssl_error=$SSL_ERROR");
$self->{output}->option_exit();
@ -129,8 +134,10 @@ sub find_ilo_version {
sub get_ilo2_data {
my ($self, %options) = @_;
my $client = new IO::Socket::SSL->new(PeerAddr => $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port},
eval $self->{ssl_opts}, Timeout => $self->{option_results}->{timeout});
my $client = new IO::Socket::SSL->new(
PeerAddr => $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port},
eval $self->{ssl_opts}, Timeout => $self->{option_results}->{timeout}
);
if (!$client) {
$self->{output}->add_option_msg(short_msg => "Failed to establish SSL connection: $!, ssl_error=$SSL_ERROR");
$self->{output}->option_exit();
@ -274,10 +281,14 @@ sub get_ilo_response {
$response = $self->change_shitty_xml(response => $response);
my $xml_result;
eval {
$xml_result = XMLin($response,
ForceArray => ['FAN', 'TEMP', 'MODULE', 'SUPPLY', 'PROCESSOR', 'NIC',
'SMART_STORAGE_BATTERY', 'CONTROLLER', 'DRIVE_ENCLOSURE',
'LOGICAL_DRIVE', 'PHYSICAL_DRIVE', 'DRIVE_BAY', 'BACKPLANE']);
$xml_result = XMLin(
$response,
ForceArray => [
'FAN', 'TEMP', 'MODULE', 'SUPPLY', 'PROCESSOR', 'NIC',
'SMART_STORAGE_BATTERY', 'CONTROLLER', 'DRIVE_ENCLOSURE',
'LOGICAL_DRIVE', 'PHYSICAL_DRIVE', 'DRIVE_BAY', 'BACKPLANE'
]
);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode xml response: $@");
@ -292,10 +303,11 @@ sub get_ilo_data {
$self->{content} = '';
if (!defined($self->{option_results}->{force_ilo3})) {
if (!defined($self->{option_results}->{force_ilo3}) && !defined($self->{option_results}->{force_ilo2})) {
$self->find_ilo_version();
} else {
$self->{ilo3} = 1;
$self->{ilo3} = 1 if (defined($self->{option_results}->{force_ilo3}));
$self->{ilo2} = 1 if (defined($self->{option_results}->{force_ilo2}));
}
if ($self->{ilo3} == 1) {
@ -349,7 +361,11 @@ Set timeout (Default: 30).
=item B<--force-ilo3>
Don't try to find ILO version.
No version identification. Directly check for version 3.
=item B<--force-ilo2>
No version identification. Directly check for version 2.
=back