mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-25 14:44:43 +02:00
create new class
This commit is contained in:
parent
06e81eb696
commit
30c63a59d7
@ -22,23 +22,11 @@ package centreon::plugins::http;
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use LWP::UserAgent;
|
use centreon::plugins::useragent;
|
||||||
use HTTP::Cookies;
|
use HTTP::Cookies;
|
||||||
use URI;
|
use URI;
|
||||||
use IO::Socket::SSL;
|
use IO::Socket::SSL;
|
||||||
|
|
||||||
{
|
|
||||||
package CentreonUserAgent;
|
|
||||||
our @ISA = qw(LWP::UserAgent);
|
|
||||||
|
|
||||||
sub get_basic_credentials {
|
|
||||||
my($self, $realm, $uri, $proxy) = @_;
|
|
||||||
return if $proxy;
|
|
||||||
return $centreon::plugins::http::request_options->{username}, $centreon::plugins::http::request_options->{password} if $centreon::plugins::http::request_options->{credentials};
|
|
||||||
return undef, undef;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
my $self = {};
|
my $self = {};
|
||||||
@ -216,14 +204,15 @@ sub set_proxy {
|
|||||||
sub request {
|
sub request {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
our $request_options = { %{$self->{options}} };
|
my $request_options = { %{$self->{options}} };
|
||||||
foreach (keys %options) {
|
foreach (keys %options) {
|
||||||
$request_options->{$_} = $options{$_} if (defined($options{$_}));
|
$request_options->{$_} = $options{$_} if (defined($options{$_}));
|
||||||
}
|
}
|
||||||
$self->check_options(request => $request_options);
|
$self->check_options(request => $request_options);
|
||||||
|
|
||||||
if (!defined($self->{ua})) {
|
if (!defined($self->{ua})) {
|
||||||
$self->{ua} = CentreonUserAgent->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})) {
|
if (defined($request_options->{cookies_file})) {
|
||||||
$self->{ua}->cookie_jar(HTTP::Cookies->new(file => $request_options->{cookies_file},
|
$self->{ua}->cookie_jar(HTTP::Cookies->new(file => $request_options->{cookies_file},
|
||||||
autosave => 1));
|
autosave => 1));
|
||||||
|
49
centreon-plugins/centreon/plugins/useragent.pm
Normal file
49
centreon-plugins/centreon/plugins/useragent.pm
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#
|
||||||
|
# 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};
|
||||||
|
return undef, undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
Loading…
x
Reference in New Issue
Block a user