enahce ilo: add http backend library
This commit is contained in:
parent
1ed1d7b9ad
commit
cb9d650ed7
|
@ -23,8 +23,8 @@ package hardware::server::hp::ilo::xmlapi::custom::api;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use IO::Socket::SSL;
|
use IO::Socket::SSL;
|
||||||
use LWP::UserAgent;
|
|
||||||
use XML::Simple;
|
use XML::Simple;
|
||||||
|
use centreon::plugins::http;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
|
@ -42,19 +42,19 @@ sub new {
|
||||||
|
|
||||||
if (!defined($options{noptions})) {
|
if (!defined($options{noptions})) {
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
"hostname:s" => { name => 'hostname' },
|
'hostname:s' => { name => 'hostname' },
|
||||||
"timeout:s" => { name => 'timeout', default => 30 },
|
'timeout:s' => { name => 'timeout', default => 30 },
|
||||||
"port:s" => { name => 'port', default => 443 },
|
'port:s' => { name => 'port', default => 443 },
|
||||||
"username:s" => { name => 'username' },
|
'username:s' => { name => 'username' },
|
||||||
"password:s" => { name => 'password' },
|
'password:s' => { name => 'password' },
|
||||||
'ssl-opt:s%' => { name => 'ssl_opt' },
|
'force-ilo3' => { name => 'force_ilo3' },
|
||||||
"force-ilo3" => { name => 'force_ilo3' },
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$options{options}->add_help(package => __PACKAGE__, sections => 'XML API OPTIONS', once => 1);
|
$options{options}->add_help(package => __PACKAGE__, sections => 'XML API OPTIONS', once => 1);
|
||||||
|
|
||||||
$self->{output} = $options{output};
|
$self->{output} = $options{output};
|
||||||
$self->{mode} = $options{mode};
|
$self->{mode} = $options{mode};
|
||||||
|
$self->{http} = centreon::plugins::http->new(%options);
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
@ -99,13 +99,18 @@ sub check_options {
|
||||||
|
|
||||||
$self->{ssl_opts} = '';
|
$self->{ssl_opts} = '';
|
||||||
if (!defined($self->{option_results}->{ssl_opt})) {
|
if (!defined($self->{option_results}->{ssl_opt})) {
|
||||||
|
$self->{option_results}->{ssl_opt} = ['SSL_verify_mode => SSL_VERIFY_NONE'];
|
||||||
$self->{ssl_opts} = 'SSL_verify_mode => SSL_VERIFY_NONE';
|
$self->{ssl_opts} = 'SSL_verify_mode => SSL_VERIFY_NONE';
|
||||||
} else {
|
} else {
|
||||||
foreach (keys %{$self->{option_results}->{ssl_opt}}) {
|
foreach (keys @{$self->{option_results}->{ssl_opt}}) {
|
||||||
$self->{ssl_opts} .= "$_ => " . $self->{option_results}->{ssl_opt}->{$_} . ", ";
|
$self->{ssl_opts} .= "$_, ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!defined($self->{option_results}->{curl_opt})) {
|
||||||
|
$self->{option_results}->{curl_opt} = ['URLOPT_SSL_VERIFYPEER => 0'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{http}->set_options(%{$self->{option_results}});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,22 +177,13 @@ sub get_ilo3_data {
|
||||||
</RIBCL>
|
</RIBCL>
|
||||||
";
|
";
|
||||||
|
|
||||||
my $ua = LWP::UserAgent->new(keep_alive => 0, protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout});
|
$self->{http}->add_header(key => 'TE', value => 'chunked');
|
||||||
my $req = HTTP::Request->new(POST => "https://" . $self->{option_results}->{hostname} . '/ribcl');
|
$self->{http}->add_header(key => 'Connection', value => 'Close');
|
||||||
$req->content_length(length($xml_script));
|
|
||||||
$req->content($xml_script);
|
|
||||||
$req->header(TE => 'chunked');
|
|
||||||
$req->header(Connection => 'Close');
|
|
||||||
|
|
||||||
my $context = new IO::Socket::SSL::SSL_Context(eval $self->{ssl_opts});
|
$self->{content} = $self->{http}->request(
|
||||||
IO::Socket::SSL::set_default_context($context);
|
method => 'POST', proto => 'https', url_path => '/ribcl',
|
||||||
|
query_form_post => $xml_script,
|
||||||
my $response = $ua->request($req);
|
);
|
||||||
$self->{content} = $response->content;
|
|
||||||
if (!$response->is_success) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Cannot get data: $response->status_line");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_ilo_error {
|
sub check_ilo_error {
|
||||||
|
@ -369,11 +365,6 @@ Set timeout (Default: 30).
|
||||||
|
|
||||||
Don't try to find ILO version.
|
Don't try to find ILO version.
|
||||||
|
|
||||||
=item B<--ssl-opt>
|
|
||||||
|
|
||||||
Set SSL Options (--ssl-opt="SSL_version=SSLv3").
|
|
||||||
Default: --ssl-opt="SSL_verify_mode=SSL_VERIFY_NONE"
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
Loading…
Reference in New Issue