From a774d42786a96b37ef57684ae7b3d388f8768b02 Mon Sep 17 00:00:00 2001 From: Shini31 Date: Wed, 1 Jul 2015 18:14:07 +0200 Subject: [PATCH 1/2] add key and root cert files options --- apps/protocols/http/mode/expectedcontent.pm | 12 +++++- apps/protocols/http/mode/jsoncontent.pm | 12 +++++- apps/protocols/http/mode/responsetime.pm | 42 +++++++++++++-------- apps/protocols/http/mode/soapcontent.pm | 12 +++++- centreon/plugins/httplib.pm | 10 ++++- 5 files changed, 67 insertions(+), 21 deletions(-) diff --git a/apps/protocols/http/mode/expectedcontent.pm b/apps/protocols/http/mode/expectedcontent.pm index 9e3083a81..15796e2f6 100644 --- a/apps/protocols/http/mode/expectedcontent.pm +++ b/apps/protocols/http/mode/expectedcontent.pm @@ -48,7 +48,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; + $self->{version} = '1.2'; $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, @@ -64,6 +64,8 @@ sub new { "timeout:s" => { name => 'timeout', default => '3' }, "ssl:s" => { name => 'ssl', }, "cert-file:s" => { name => 'cert_file' }, + "key-file:s" => { name => 'key_file' }, + "cacert-file:s" => { name => 'cacert_file' }, "cert-pwd:s" => { name => 'cert_pwd' }, "cert-pkcs12" => { name => 'cert_pkcs12' }, }); @@ -175,6 +177,14 @@ Specify SSL version (example : 'sslv3', 'tlsv1'...) Specify certificate to send to the webserver +=item B<--key-file> + +Specify key to send to the webserver + +=item B<--cacert-file> + +Specify root certificate to send to the webserver + =item B<--cert-pwd> Specify certificate's password diff --git a/apps/protocols/http/mode/jsoncontent.pm b/apps/protocols/http/mode/jsoncontent.pm index 8f08afc5d..e4e73d2ee 100644 --- a/apps/protocols/http/mode/jsoncontent.pm +++ b/apps/protocols/http/mode/jsoncontent.pm @@ -51,7 +51,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; + $self->{version} = '1.2'; $options{options}->add_options(arguments => { "data:s" => { name => 'data' }, @@ -70,6 +70,8 @@ sub new { "timeout:s" => { name => 'timeout', default => 10 }, "ssl:s" => { name => 'ssl', }, "cert-file:s" => { name => 'cert_file' }, + "key-file:s" => { name => 'key_file' }, + "cacert-file:s" => { name => 'cacert_file' }, "cert-pwd:s" => { name => 'cert_pwd' }, "cert-pkcs12" => { name => 'cert_pkcs12' }, @@ -454,6 +456,14 @@ Specify SSL version (example : 'sslv3', 'tlsv1'...) Specify certificate to send to the webserver +=item B<--key-file> + +Specify key to send to the webserver + +=item B<--cacert-file> + +Specify root certificate to send to the webserver + =item B<--cert-pwd> Specify certificate's password diff --git a/apps/protocols/http/mode/responsetime.pm b/apps/protocols/http/mode/responsetime.pm index 9775839ed..3d341860f 100644 --- a/apps/protocols/http/mode/responsetime.pm +++ b/apps/protocols/http/mode/responsetime.pm @@ -53,22 +53,24 @@ sub new { $self->{version} = '1.1'; $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', }, - "proto:s" => { name => 'proto', default => "http" }, - "urlpath:s" => { name => 'url_path', default => "/" }, - "credentials" => { name => 'credentials' }, - "ntlm" => { name => 'ntlm' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "proxyurl:s" => { name => 'proxyurl' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "timeout:s" => { name => 'timeout', default => '3' }, - "ssl:s" => { name => 'ssl', }, - "cert-file:s" => { name => 'cert_file' }, - "cert-pwd:s" => { name => 'cert_pwd' }, - "cert-pkcs12" => { name => 'cert_pkcs12' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port', }, + "proto:s" => { name => 'proto', default => "http" }, + "urlpath:s" => { name => 'url_path', default => "/" }, + "credentials" => { name => 'credentials' }, + "ntlm" => { name => 'ntlm' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "proxyurl:s" => { name => 'proxyurl' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "timeout:s" => { name => 'timeout', default => '3' }, + "ssl:s" => { name => 'ssl' }, + "cert-file:s" => { name => 'cert_file' }, + "key-file:s" => { name => 'key_file' }, + "cacert-file:s" => { name => 'cacert_file' }, + "cert-pwd:s" => { name => 'cert_pwd' }, + "cert-pkcs12" => { name => 'cert_pkcs12' }, }); return $self; } @@ -199,6 +201,14 @@ Threshold critical in seconds (Webpage response time) Specify certificate to send to the webserver +=item B<--key-file> + +Specify key to send to the webserver + +=item B<--cacert-file> + +Specify root certificate to send to the webserver + =item B<--cert-pwd> Specify certificate's password diff --git a/apps/protocols/http/mode/soapcontent.pm b/apps/protocols/http/mode/soapcontent.pm index b52d75bfd..c020ddc2f 100644 --- a/apps/protocols/http/mode/soapcontent.pm +++ b/apps/protocols/http/mode/soapcontent.pm @@ -50,7 +50,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.1'; + $self->{version} = '1.2'; $options{options}->add_options(arguments => { "service-soap:s" => { name => 'service_soap' }, @@ -69,6 +69,8 @@ sub new { "timeout:s" => { name => 'timeout', default => 10 }, "ssl:s" => { name => 'ssl', }, "cert-file:s" => { name => 'cert_file' }, + "key-file:s" => { name => 'key_file' }, + "cacert-file:s" => { name => 'cacert_file' }, "cert-pwd:s" => { name => 'cert_pwd' }, "cert-pkcs12" => { name => 'cert_pkcs12' }, @@ -449,6 +451,14 @@ Specify SSL version (example : 'sslv3', 'tlsv1'...) Specify certificate to send to the webserver +=item B<--key-file> + +Specify key to send to the webserver + +=item B<--cacert-file> + +Specify root certificate to send to the webserver + =item B<--cert-pwd> Specify certificate's password diff --git a/centreon/plugins/httplib.pm b/centreon/plugins/httplib.pm index 10d9772f4..0e7c420da 100644 --- a/centreon/plugins/httplib.pm +++ b/centreon/plugins/httplib.pm @@ -133,8 +133,14 @@ sub connect { } if (defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pkcs12})) { - eval "use Net::SSL"; die $@ if $@; - $ENV{HTTPS_CERT_FILE} = $self->{option_results}->{cert_file}; + use IO::Socket::SSL; + my $context = new IO::Socket::SSL::SSL_Context( + SSL_use_cert => 1, + SSL_cert_file => $self->{option_results}->{cert_file}, + $self->{option_results}->{key_file} ? ( SSL_key_file => $self->{option_results}->{key_file} ):(), + $self->{option_results}->{cacert_file} ? ( SSL_ca_file => $self->{option_results}->{cacert_file} ):(), + ); + IO::Socket::SSL::set_default_context($context); } $response = $ua->request($req); From 665b8ca14a067f6dea47395c0f6f97dfbb7734cb Mon Sep 17 00:00:00 2001 From: Shini31 Date: Wed, 1 Jul 2015 18:18:06 +0200 Subject: [PATCH 2/2] fix tabulation error --- apps/protocols/http/mode/responsetime.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/protocols/http/mode/responsetime.pm b/apps/protocols/http/mode/responsetime.pm index 3d341860f..eff0a7dae 100644 --- a/apps/protocols/http/mode/responsetime.pm +++ b/apps/protocols/http/mode/responsetime.pm @@ -65,7 +65,7 @@ sub new { "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, "timeout:s" => { name => 'timeout', default => '3' }, - "ssl:s" => { name => 'ssl' }, + "ssl:s" => { name => 'ssl' }, "cert-file:s" => { name => 'cert_file' }, "key-file:s" => { name => 'key_file' }, "cacert-file:s" => { name => 'cacert_file' },