This commit is contained in:
qgarnier 2018-01-22 17:42:08 +01:00
commit 728e371f67
6 changed files with 89 additions and 28 deletions

View File

@ -43,6 +43,7 @@ sub new {
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"ntlm" => { name => 'ntlm' },
"ntlmv2" => { name => 'ntlmv2' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
@ -195,19 +196,19 @@ Set path to get Webpage (Default: '/')
=item B<--credentials>
Specify this option if you access webpage over basic authentification
Specify this option if you access webpage over basic authentication
=item B<--ntlm>
=item B<--ntlmv2>
Specify this option if you access webpage over ntlm authentification (Use with --credentials option)
Specify this option if you access webpage over ntlmv2 authentication (Use with --credentials and --port options)
=item B<--username>
Specify username for basic authentification (Mandatory if --credentials is specidied)
Specify username for basic authentication (Mandatory if --credentials is specidied)
=item B<--password>
Specify password for basic authentification (Mandatory if --credentials is specidied)
Specify password for basic authentication (Mandatory if --credentials is specidied)
=item B<--timeout>

View File

@ -47,6 +47,7 @@ sub new {
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"ntlm" => { name => 'ntlm' },
"ntlmv2" => { name => 'ntlmv2' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
@ -392,19 +393,19 @@ Set path to get Webpage (Default: '/')
=item B<--credentials>
Specify this option if you access webpage over basic authentification
Specify this option if you access webpage over basic authentication
=item B<--ntlm>
=item B<--ntlmv2>
Specify this option if you access webpage over ntlm authentification (Use with --credentials option)
Specify this option if you access webpage over ntlmv2 authentication (Use with --credentials and --port options)
=item B<--username>
Specify username for basic authentification (Mandatory if --credentials is specidied)
Specify username for basic authentication (Mandatory if --credentials is specidied)
=item B<--password>
Specify password for basic authentification (Mandatory if --credentials is specidied)
Specify password for basic authentication (Mandatory if --credentials is specidied)
=item B<--timeout>

View File

@ -43,6 +43,7 @@ sub new {
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"ntlm" => { name => 'ntlm' },
"ntlmv2" => { name => 'ntlmv2' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
@ -173,19 +174,19 @@ Set path to get webpage (Default: '/')
=item B<--credentials>
Specify this option if you access webpage over basic authentification
Specify this option if you access webpage over basic authentication
=item B<--ntlm>
=item B<--ntlmv2>
Specify this option if you access webpage over ntlm authentification (Use with --credentials option)
Specify this option if you access webpage over ntlmv2 authentication (Use with --credentials and --port options)
=item B<--username>
Specify username for basic authentification (Mandatory if --credentials is specidied)
Specify username for basic authentication (Mandatory if --credentials is specidied)
=item B<--password>
Specify password for basic authentification (Mandatory if --credentials is specidied)
Specify password for basic authentication (Mandatory if --credentials is specidied)
=item B<--proxyurl>

View File

@ -47,6 +47,7 @@ sub new {
"urlpath:s" => { name => 'url_path' },
"credentials" => { name => 'credentials' },
"ntlm" => { name => 'ntlm' },
"ntlmv2" => { name => 'ntlmv2' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
@ -419,19 +420,19 @@ Set path to get Webpage (Default: '/')
=item B<--credentials>
Specify this option if you access webpage over basic authentification
Specify this option if you access webpage over basic authentication
=item B<--ntlm>
=item B<--ntlmv2>
Specify this option if you access webpage over ntlm authentification (Use with --credentials option)
Specify this option if you access webpage over ntlmv2 authentication (Use with --credentials and --port options)
=item B<--username>
Specify username for basic authentification (Mandatory if --credentials is specidied)
Specify username for basic authentication (Mandatory if --credentials is specidied)
=item B<--password>
Specify password for basic authentification (Mandatory if --credentials is specidied)
Specify password for basic authentication (Mandatory if --credentials is specidied)
=item B<--timeout>

View File

@ -22,7 +22,7 @@ package centreon::plugins::http;
use strict;
use warnings;
use LWP::UserAgent;
use centreon::plugins::useragent;
use HTTP::Cookies;
use URI;
use IO::Socket::SSL;
@ -211,7 +211,8 @@ sub request {
$self->check_options(request => $request_options);
if (!defined($self->{ua})) {
$self->{ua} = LWP::UserAgent->new(keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $request_options->{timeout});
$self->{ua} = centreon::plugins::useragent->new(keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $request_options->{timeout},
credentials => $request_options->{credentials}, username => $request_options->{username}, password => $request_options->{password});
if (defined($request_options->{cookies_file})) {
$self->{ua}->cookie_jar(HTTP::Cookies->new(file => $request_options->{cookies_file},
autosave => 1));
@ -264,11 +265,11 @@ sub request {
$req->content($uri_post->query);
}
}
if (defined($request_options->{credentials}) && defined($request_options->{ntlm})) {
$self->{ua}->credentials($request_options->{hostname} . ':' . $request_options->{port}, '', $request_options->{username}, $request_options->{password});
} elsif (defined($request_options->{credentials})) {
$req->authorization_basic($request_options->{username}, $request_options->{password});
if (defined($request_options->{credentials}) && defined($request_options->{ntlmv2})) {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Authen::NTLM',
error_msg => "Cannot load module 'Authen::NTLM'.");
Authen::NTLM::ntlmv2(1);
}
$self->set_proxy(request => $request_options, url => $url);
@ -311,9 +312,15 @@ sub request {
}
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
my $short_msg = $response->status_line;
if ($short_msg =~ /^401/) {
my ($authenticate) = $response->www_authenticate =~ /(\S+)/;
$short_msg .= ' (' . $authenticate . ' authentification expected)';
}
$self->{output}->output_add(long_msg => $response->content, debug => 1);
$self->{output}->output_add(severity => $status,
short_msg => $response->status_line);
short_msg => $short_msg);
$self->{output}->display();
$self->{output}->exit();
}

View File

@ -0,0 +1,50 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package centreon::plugins::useragent;
use strict;
use warnings;
use base 'LWP::UserAgent';
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
$self = LWP::UserAgent::new(@_);
$self->agent("centreon::plugins::useragent");
$self->{credentials} = $options{credentials} if defined($options{credentials});
$self->{username} = $options{username} if defined($options{username});
$self->{password} = $options{password} if defined($options{password});
return $self;
}
sub get_basic_credentials {
my($self, $realm, $uri, $proxy) = @_;
return if $proxy;
return $self->{username}, $self->{password} if $self->{credentials} and wantarray;
return $self->{username}.":".$self->{password} if $self->{credentials};
return undef;
}
1;