From 58fcd24c9ffb5b3be3dff6eaf583f682d1c1f02d Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 4 Dec 2019 14:14:39 +0100 Subject: [PATCH] enhance indent --- .../mip/restapi/mode/listscenarios.pm | 6 +- centreon/plugins/backend/http/curl.pm | 66 +++++++++++-------- .../plugins/backend/http/curlconstants.pm | 2 +- centreon/plugins/backend/http/lwp.pm | 22 ++++--- centreon/plugins/http.pm | 2 +- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/apps/monitoring/mip/restapi/mode/listscenarios.pm b/apps/monitoring/mip/restapi/mode/listscenarios.pm index c287d4c01..e47d1e60d 100644 --- a/apps/monitoring/mip/restapi/mode/listscenarios.pm +++ b/apps/monitoring/mip/restapi/mode/listscenarios.pm @@ -29,7 +29,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { }); @@ -43,7 +43,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - + my $api_results = $options{custom}->request_api( url_path => '/api/measures/?type=ASA_DESKTOP&engineActivated=true&fields=name,alias,displayName,frequency,scenario.name,scenario.application.name,timeout,agent.id,agent.name,activated,engineActivated&limit=-1' ); @@ -86,7 +86,7 @@ sub run { sub disco_format { my ($self, %options) = @_; - + $self->{output}->add_disco_format(elements => ['id', 'name', 'alias', 'display_name', 'app_name']); } diff --git a/centreon/plugins/backend/http/curl.pm b/centreon/plugins/backend/http/curl.pm index 73eb62320..bf8472be5 100644 --- a/centreon/plugins/backend/http/curl.pm +++ b/centreon/plugins/backend/http/curl.pm @@ -32,25 +32,31 @@ sub new { if (!defined($options{noptions}) || $options{noptions} != 1) { $options{options}->add_options(arguments => { - "curl-opt:s@" => { name => 'curl_opt' }, + 'curl-opt:s@' => { name => 'curl_opt' }, }); $options{options}->add_help(package => __PACKAGE__, sections => 'BACKEND CURL OPTIONS', once => 1); } - + $self->{output} = $options{output}; - + return $self; } sub check_options { my ($self, %options) = @_; - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Net::Curl::Easy', - error_msg => "Cannot load module 'Net::Curl::Easy'."); - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'centreon::plugins::backend::http::curlconstants', - error_msg => "Cannot load module 'centreon::plugins::backend::http::curlconstants'."); + centreon::plugins::misc::mymodule_load( + output => $self->{output}, + module => 'Net::Curl::Easy', + error_msg => "Cannot load module 'Net::Curl::Easy'." + ); + centreon::plugins::misc::mymodule_load( + output => $self->{output}, + module => 'centreon::plugins::backend::http::curlconstants', + error_msg => "Cannot load module 'centreon::plugins::backend::http::curlconstants'." + ); $self->{constant_cb} = \¢reon::plugins::backend::http::curlconstants::get_constant_value; - + foreach (('unknown_status', 'warning_status', 'critical_status')) { if (defined($options{request}->{$_})) { $options{request}->{$_} =~ s/%\{http_code\}/\$self->{response_code}/g; @@ -138,7 +144,7 @@ sub cb_debug { sub curl_setopt { my ($self, %options) = @_; - + eval { $self->{curl_easy}->setopt($options{option}, $options{parameter}); }; @@ -154,7 +160,7 @@ sub set_method { if ($options{request}->{method} eq 'GET') { return ; } - + if ($options{content_type_forced} == 1) { $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POSTFIELDS'), parameter => $options{request}->{query_form_post}) if (defined($options{request}->{query_form_post}) && $options{request}->{query_form_post} ne ''); @@ -164,7 +170,7 @@ sub set_method { push @{$options{headers}}, 'Content-Type: application/x-www-form-urlencoded'; $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POSTFIELDS'), parameter => $uri_post->query); } - + if ($options{request}->{method} eq 'POST') { $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_POST'), parameter => 1); } @@ -211,10 +217,10 @@ sub set_proxy { $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_PROXYPASSWORD'), parameter => $2); $options{request}->{proxyurl} =~ s/\/\/$1:$2@//; } - + $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_PROXY'), parameter => $options{request}->{proxyurl}); } - + if (defined($options{request}->{proxypac}) && $options{request}->{proxypac} ne '') { $self->{output}->add_option_msg(short_msg => 'Unsupported proxypac option'); $self->{output}->option_exit(); @@ -256,7 +262,7 @@ sub cb_get_header { $uservar->{response_headers}->[$uservar->{nheaders}]->{response_line} = $header; } } - + return length($_[1]); } @@ -264,7 +270,7 @@ sub request { my ($self, %options) = @_; $self->{curl_easy} = Net::Curl::Easy->new(); - + if ($self->{output}->is_debug()) { $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_DEBUGFUNCTION'), parameter => \&cb_debug); $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_DEBUGDATA'), parameter => $self); @@ -277,7 +283,7 @@ sub request { if (defined($options{request}->{cookies_file})) { $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_COOKIEFILE'), parameter => $options{request}->{cookies_file}); } - + $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_FOLLOWLOCATION'), parameter => 1); if (defined($options{request}->{no_follow})) { $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_FOLLOWLOCATION'), parameter => 0); @@ -302,9 +308,9 @@ sub request { if (defined($options{request}->{get_params})) { $uri->query_form($options{request}->{get_params}); } - + $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_URL'), parameter => $uri); - + my $headers = []; my $content_type_forced = 0; foreach my $key (keys %{$options{request}->{headers}}) { @@ -319,11 +325,11 @@ sub request { if (scalar(@$headers) > 0) { $self->{curl_easy}->pushopt($self->{constant_cb}->(name => 'CURLOPT_HTTPHEADER'), $headers); } - + if (defined($options{request}->{cacert_file}) && $options{request}->{cacert_file} ne '') { $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_CAINFO'), parameter => $options{request}->{cacert_file}); } - + $self->set_auth(%options); $self->set_proxy(%options); $self->set_extra_curl_opt(%options); @@ -334,7 +340,7 @@ sub request { $self->{response_headers} = [{}]; $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_HEADERDATA'), parameter => $self); $self->curl_setopt(option => $self->{constant_cb}->(name => 'CURLOPT_HEADERFUNCTION'), parameter => \&cb_get_header); - + eval { $self->{curl_easy}->perform(); }; @@ -344,7 +350,7 @@ sub request { } $self->{response_code} = $self->{curl_easy}->getinfo($self->{constant_cb}->(name => 'CURLINFO_RESPONSE_CODE')); - + # Check response my $status = 'ok'; my $message; @@ -373,8 +379,10 @@ sub request { my $short_msg = $self->{response_code} . ' ' . (defined($http_code_explained->{$self->{response_code}}) ? $http_code_explained->{$self->{response_code}} : 'unknown'); - $self->{output}->output_add(severity => $status, - short_msg => $short_msg); + $self->{output}->output_add( + severity => $status, + short_msg => $short_msg + ); $self->{output}->display(); $self->{output}->exit(); } @@ -384,7 +392,7 @@ sub request { sub get_headers { my ($self, %options) = @_; - + my $headers = ''; foreach (keys %{$self->{response_headers}->[$options{nheader}]}) { next if (/response_line/); @@ -392,17 +400,17 @@ sub get_headers { $headers .= "$_: " . $value . "\n"; } } - + return $headers; } sub get_first_header { my ($self, %options) = @_; - + if (!defined($options{name})) { return $self->get_headers(nheader => 0); } - + return undef if (!defined($self->{response_headers}->[0]->{ lc($options{name}) })); return wantarray ? @{$self->{response_headers}->[0]->{ lc($options{name}) }} : $self->{response_headers}->[0]->{ lc($options{name}) }->[0]; @@ -428,7 +436,7 @@ sub get_code { sub get_message { my ($self, %options) = @_; - + return $http_code_explained->{$self->{response_code}}; } diff --git a/centreon/plugins/backend/http/curlconstants.pm b/centreon/plugins/backend/http/curlconstants.pm index 6c30d01f2..21e2de212 100644 --- a/centreon/plugins/backend/http/curlconstants.pm +++ b/centreon/plugins/backend/http/curlconstants.pm @@ -26,7 +26,7 @@ use Net::Curl::Easy qw(:constants); sub get_constant_value { my (%options) = @_; - + return eval $options{name}; } diff --git a/centreon/plugins/backend/http/lwp.pm b/centreon/plugins/backend/http/lwp.pm index 1fb968569..07146ab1e 100644 --- a/centreon/plugins/backend/http/lwp.pm +++ b/centreon/plugins/backend/http/lwp.pm @@ -33,8 +33,8 @@ sub new { if (!defined($options{noptions}) || $options{noptions} != 1) { $options{options}->add_options(arguments => { - "ssl:s" => { name => 'ssl' }, - "ssl-opt:s@" => { name => 'ssl_opt' }, + 'ssl:s' => { name => 'ssl' }, + 'ssl-opt:s@' => { name => 'ssl_opt' }, }); $options{options}->add_help(package => __PACKAGE__, sections => 'BACKEND LWP OPTIONS', once => 1); } @@ -42,7 +42,7 @@ sub new { $self->{output} = $options{output}; $self->{ua} = undef; $self->{debug_handlers} = 0; - + return $self; } @@ -138,7 +138,7 @@ sub request { ); } } - + if ($self->{output}->is_debug() && $self->{debug_handlers} == 0) { $self->{debug_handlers} = 1; $self->{ua}->add_handler('request_send', sub { @@ -150,13 +150,13 @@ sub request { }); $self->{ua}->add_handler("response_done", sub { my ($response, $ua, $handler) = @_; - + $self->{output}->output_add(long_msg => '======> response done', debug => 1); $self->{output}->output_add(long_msg => $response->as_string, debug => 1); return ; }); } - + if (defined($request_options->{no_follow})) { $self->{ua}->requests_redirectable(undef); } else { @@ -263,8 +263,10 @@ sub request { $self->{response}->www_authenticate =~ /(\S+)/); } - $self->{output}->output_add(severity => $status, - short_msg => $short_msg); + $self->{output}->output_add( + severity => $status, + short_msg => $short_msg + ); $self->{output}->display(); $self->{output}->exit(); } @@ -275,13 +277,13 @@ sub request { sub get_headers { my ($self, %options) = @_; - + my $headers = ''; foreach ($options{response}->header_field_names()) { my $value = $options{response}->header($_); $headers .= "$_: " . (defined($value) ? $value : '') . "\n"; } - + return $headers; } diff --git a/centreon/plugins/http.pm b/centreon/plugins/http.pm index a39972099..73ffd0bb4 100644 --- a/centreon/plugins/http.pm +++ b/centreon/plugins/http.pm @@ -149,7 +149,7 @@ sub check_options { } } } - + $self->{'backend_' . $self->{http_backend}}->check_options(%options); }