From f8d7de7ce36b88d40d52bbf8b069f3d037a02e42 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 3 Sep 2019 09:21:41 +0200 Subject: [PATCH] set content-legth to 0 for vmware vcsa --- apps/vmware/vcsa/restapi/custom/api.pm | 5 +++-- centreon/plugins/backend/http/curl.pm | 8 ++++---- centreon/plugins/http.pm | 15 +++++++++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/apps/vmware/vcsa/restapi/custom/api.pm b/apps/vmware/vcsa/restapi/custom/api.pm index d29c3ca59..38641a749 100644 --- a/apps/vmware/vcsa/restapi/custom/api.pm +++ b/apps/vmware/vcsa/restapi/custom/api.pm @@ -166,14 +166,15 @@ sub authenticate { my $has_cache_file = $options{statefile}->read(statefile => 'vcsa_api_' . md5_hex($self->{option_results}->{hostname}) . '_' . md5_hex($self->{option_results}->{api_username})); my $session_id = $options{statefile}->get(name => 'session_id'); - if ($has_cache_file == 0 || !defined($session_id)) { + if ($has_cache_file == 0 || !defined($session_id)) { my $content = $self->{http}->request( method => 'POST', url_path => '/rest/com/vmware/cis/session', credentials => 1, basic => 1, username => $self->{api_username}, password => $self->{api_password}, - warning_status => '', unknown_status => '', critical_status => '' + warning_status => '', unknown_status => '', critical_status => '', + curl_backend_options => { header => ['Content-Length: 0'] }, ); if ($self->{http}->get_code() != 200) { $self->{output}->add_option_msg(short_msg => "Login error [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); diff --git a/centreon/plugins/backend/http/curl.pm b/centreon/plugins/backend/http/curl.pm index 215395cae..768ce915b 100644 --- a/centreon/plugins/backend/http/curl.pm +++ b/centreon/plugins/backend/http/curl.pm @@ -131,7 +131,7 @@ sub cb_debug { if ($type == $uservar->{constant_cb}->(name => 'CURLINFO_SSL_DATA_IN')) { $msg = sprintf("=> Recv SSL data: %s", $data); } - + $uservar->{output}->output_add(long_msg => $msg, debug => 1); return 0; } @@ -313,9 +313,9 @@ sub request { $content_type_forced = 1; } } - + $self->set_method(%options, content_type_forced => $content_type_forced, headers => $headers); - + if (scalar(@$headers) > 0) { $self->{curl_easy}->pushopt($self->{constant_cb}->(name => 'CURLOPT_HTTPHEADER'), $headers); } @@ -341,7 +341,7 @@ sub request { $self->{output}->add_option_msg(short_msg => 'curl perform error : ' . $@); $self->{output}->option_exit(); } - + $self->{response_code} = $self->{curl_easy}->getinfo($self->{constant_cb}->(name => 'CURLINFO_RESPONSE_CODE')); # Check response diff --git a/centreon/plugins/http.pm b/centreon/plugins/http.pm index ad0f86f1b..8ad028aea 100644 --- a/centreon/plugins/http.pm +++ b/centreon/plugins/http.pm @@ -30,10 +30,10 @@ sub new { if (!defined($options{noptions}) || $options{noptions} != 1) { $options{options}->add_options(arguments => { - "http-peer-addr:s" => { name => 'http_peer_addr' }, - "proxyurl:s" => { name => 'proxyurl' }, - "proxypac:s" => { name => 'proxypac' }, - "http-backend:s" => { name => 'http_backend', default => 'lwp' }, + 'http-peer-addr:s' => { name => 'http_peer_addr' }, + 'proxyurl:s' => { name => 'proxyurl' }, + 'proxypac:s' => { name => 'proxypac' }, + 'http-backend:s' => { name => 'http_backend', default => 'lwp' }, }); $options{options}->add_help(package => __PACKAGE__, sections => 'HTTP GLOBAL OPTIONS'); } @@ -87,6 +87,13 @@ sub check_options { $self->{output}->option_exit(); } + if (defined($options{request}->{curl_backend_options}) && + $self->{http_backend} eq 'curl') { + foreach (keys %{$options{request}->{curl_backend_options}}) { + $options{request}->{$_} = $options{request}->{curl_backend_options}->{$_}; + } + } + if (($options{request}->{proto} ne 'http') && ($options{request}->{proto} ne 'https')) { $self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'."); $self->{output}->option_exit();