From 07080ec0945cdec2e844a83f862d3d4278d6e2fb Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 27 Mar 2014 20:17:38 +0100 Subject: [PATCH] Fix #5420 --- .../apache/serverstatus/mode/libconnect.pm | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/centreon-plugins/apps/apache/serverstatus/mode/libconnect.pm b/centreon-plugins/apps/apache/serverstatus/mode/libconnect.pm index 5bdaa1277..e912956fa 100644 --- a/centreon-plugins/apps/apache/serverstatus/mode/libconnect.pm +++ b/centreon-plugins/apps/apache/serverstatus/mode/libconnect.pm @@ -42,42 +42,32 @@ use LWP::UserAgent; sub connect { my ($self, %options) = @_; - my $ua = LWP::UserAgent->new( protocols_allowed => ['http','https'], timeout => $self->{option_results}->{timeout}); + my $ua = LWP::UserAgent->new( protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout}); my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown'; - my $response; - my $content; + my ($response, $content); - if (defined $self->{option_results}->{credentials}) { - $ua->credentials($self->{option_results}->{hostname}.':'.$self->{option_results}->{port},$self->{option_results}->{username},$self->{option_results}->{password}); + my $req = HTTP::Request->new( GET => $self->{option_results}->{proto}."://" .$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.'/server-status'); + + if (defined($self->{option_results}->{credentials})) { + $req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password}); } - if ($self->{option_results}->{proto} eq "https") { - if (defined $self->{option_results}->{proxyurl}) { - $ua->proxy(['https'], $self->{option_results}->{proxyurl}); - $response = $ua->get('https://'.$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.'/server-status'); - } else { - $response = $ua->get('https://'.$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.'/server-status'); - } - } else { - if (defined $self->{option_results}->{proxyurl}) { - $ua->proxy(['http'], $self->{option_results}->{proxyurl}); - $response = $ua->get($self->{option_results}->{proto}."://" .$self->{option_results}->{hostname}.'/server-status'); - } else { - $response = $ua->get('http://'.$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.'/server-status'); - } + if (defined($self->{option_results}->{proxyurl})) { + $ua->proxy(['http', 'https'], $self->{option_results}->{proxyurl}); } + + $response = $ua->request($req); - if ($response->is_success) { + if ($response->is_success) { $content = $response->content; return $content; - } else { - $self->{output}->output_add(severity => $connection_exit, - short_msg => $response->status_line); - $self->{output}->display(); - $self->{output}->exit(); - } - + } + + $self->{output}->output_add(severity => $connection_exit, + short_msg => $response->status_line); + $self->{output}->display(); + $self->{output}->exit(); } 1;