diff --git a/apps/protocols/http/mode/expectedcontent.pm b/apps/protocols/http/mode/expectedcontent.pm index cd818c741..1f547221c 100644 --- a/apps/protocols/http/mode/expectedcontent.pm +++ b/apps/protocols/http/mode/expectedcontent.pm @@ -46,6 +46,7 @@ sub new { "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, + "proxypac:s" => { name => 'proxypac' }, "expected-string:s" => { name => 'expected_string' }, "timeout:s" => { name => 'timeout' }, "no-follow" => { name => 'no_follow', }, @@ -173,7 +174,11 @@ Port used by Webserver =item B<--proxyurl> -Proxy URL if any +Proxy URL + +=item B<--proxypac> + +Proxy pac file (can be an url or local file) =item B<--method> diff --git a/apps/protocols/http/mode/jsoncontent.pm b/apps/protocols/http/mode/jsoncontent.pm index ae858f6a4..0987fa4ed 100644 --- a/apps/protocols/http/mode/jsoncontent.pm +++ b/apps/protocols/http/mode/jsoncontent.pm @@ -50,6 +50,7 @@ sub new { "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, + "proxypac:s" => { name => 'proxypac' }, "header:s@" => { name => 'header' }, "get-param:s@" => { name => 'get_param' }, "timeout:s" => { name => 'timeout', default => 10 }, @@ -368,7 +369,11 @@ Port used by Webserver =item B<--proxyurl> -Proxy URL if any +Proxy URL + +=item B<--proxypac> + +Proxy pac file (can be an url or local file) =item B<--proto> diff --git a/apps/protocols/http/mode/response.pm b/apps/protocols/http/mode/response.pm index f9cada349..3616e37f3 100644 --- a/apps/protocols/http/mode/response.pm +++ b/apps/protocols/http/mode/response.pm @@ -46,6 +46,7 @@ sub new { "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, + "proxypac:s" => { name => 'proxypac' }, "timeout:s" => { name => 'timeout' }, "no-follow" => { name => 'no_follow', }, "ssl:s" => { name => 'ssl' }, @@ -187,7 +188,11 @@ Specify password for basic authentification (Mandatory if --credentials is speci =item B<--proxyurl> -Proxy URL if any +Proxy URL + +=item B<--proxypac> + +Proxy pac file (can be an url or local file) =item B<--timeout> diff --git a/apps/protocols/http/mode/soapcontent.pm b/apps/protocols/http/mode/soapcontent.pm index 1c621049f..2b02b790e 100644 --- a/apps/protocols/http/mode/soapcontent.pm +++ b/apps/protocols/http/mode/soapcontent.pm @@ -50,6 +50,7 @@ sub new { "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, "proxyurl:s" => { name => 'proxyurl' }, + "proxypac:s" => { name => 'proxypac' }, "header:s@" => { name => 'header' }, "timeout:s" => { name => 'timeout', default => 10 }, "ssl:s" => { name => 'ssl', }, @@ -381,7 +382,11 @@ Port used by Webserver =item B<--proxyurl> -Proxy URL if any +Proxy URL + +=item B<--proxypac> + +Proxy pac file (can be an url or local file) =item B<--proto> diff --git a/centreon/plugins/http.pm b/centreon/plugins/http.pm index a1bf9ea3e..f7086b30f 100644 --- a/centreon/plugins/http.pm +++ b/centreon/plugins/http.pm @@ -147,6 +147,30 @@ sub get_port_request { return $port; } +sub set_proxy { + my ($self, %options) = @_; + + if (defined($options{request}->{proxypac}) && $options{request}->{proxypac} ne '') { + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'HTTP::ProxyPAC', + error_msg => "Cannot load module 'HTTP::ProxyPAC'."); + my $pac; + eval { + $pac = HTTP::ProxyPAC->new($options{request}->{proxypac}); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => 'issue to load proxypac: ' . $@); + $self->{output}->option_exit(); + } + my $res = $pac->find_proxy($options{url}); + if (defined($res->direct) && $res->direct != 1) { + $self->{ua}->proxy(['http', 'https'], $res->proxy); + } + } + if (defined($options{request}->{proxyurl}) && $options{request}->{proxyurl} ne '') { + $self->{ua}->proxy(['http', 'https'], $options{request_options}->{proxyurl}); + } +} + sub request { my ($self, %options) = @_; @@ -215,9 +239,7 @@ sub request { $req->authorization_basic($request_options->{username}, $request_options->{password}); } - if (defined($request_options->{proxyurl})) { - $self->{ua}->proxy(['http', 'https'], $request_options->{proxyurl}); - } + $self->set_proxy(request => $request_options, url => $url); if (defined($request_options->{cert_pkcs12}) && $request_options->{cert_file} ne '' && $request_options->{cert_pwd} ne '') { eval "use Net::SSL"; die $@ if $@;