Add option to send a certificate with conditional module load - Refs #6202

This commit is contained in:
Mathieu Cinquin 2015-04-24 13:40:13 +02:00
parent f867e349dd
commit d9631e2956
5 changed files with 257 additions and 164 deletions

View File

@ -1,5 +1,5 @@
############################################################################### ###############################################################################
# Copyright 2005-2013 MERETHIS # Copyright 2005-2015 CENTREON
# Centreon is developped by : Julien Mathis and Romain Le Merlus under # Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0. # GPL Licence 2.0.
# #
@ -18,18 +18,19 @@
# combined work based on this program. Thus, the terms and conditions of the GNU # combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination. # General Public License cover the whole combination.
# #
# As a special exception, the copyright holders of this program give MERETHIS # As a special exception, the copyright holders of this program give CENTREON
# permission to link this program with independent modules to produce an timeelapsedutable, # permission to link this program with independent modules to produce an timeelapsedutable,
# regardless of the license terms of these independent modules, and to copy and # regardless of the license terms of these independent modules, and to copy and
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that # distribute the resulting timeelapsedutable under terms of CENTREON choice, provided that
# MERETHIS also meet, for each linked independent module, the terms and conditions # CENTREON also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not # of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this # derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you # exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version. # do not wish to do so, delete this exception statement from your version.
# #
# For more information : contact@centreon.com # For more information : contact@centreon.com
# Author : Simon BOMM <sbomm@merethis.com> # Authors : Simon BOMM <sbomm@merethis.com>
# Mathieu Cinquin <mcinquin@centreon.com>
# #
# Based on De Bodt Lieven plugin # Based on De Bodt Lieven plugin
#################################################################################### ####################################################################################
@ -47,7 +48,7 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.1';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"hostname:s" => { name => 'hostname' }, "hostname:s" => { name => 'hostname' },
@ -62,6 +63,9 @@ sub new {
"expected-string:s" => { name => 'expected_string' }, "expected-string:s" => { name => 'expected_string' },
"timeout:s" => { name => 'timeout', default => '3' }, "timeout:s" => { name => 'timeout', default => '3' },
"ssl:s" => { name => 'ssl', }, "ssl:s" => { name => 'ssl', },
"cert-file:s" => { name => 'cert_file' },
"cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' },
}); });
return $self; return $self;
} }
@ -86,6 +90,10 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option"); $self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used");
$self->{output}->option_exit();
}
} }
sub run { sub run {
@ -163,6 +171,18 @@ Threshold for HTTP timeout
Specify SSL version (example : 'sslv3', 'tlsv1'...) Specify SSL version (example : 'sslv3', 'tlsv1'...)
=item B<--cert-file>
Specify certificate to send to the webserver
=item B<--cert-pwd>
Specify certificate's password
=item B<--cert-pkcs12>
Specify type of certificate (PKCS12)
=item B<--expected-string> =item B<--expected-string>
Specify String to check on the Webpage Specify String to check on the Webpage

View File

@ -1,5 +1,5 @@
############################################################################### ###############################################################################
# Copyright 2005-2013 MERETHIS # Copyright 2005-2015 CENTREON
# Centreon is developped by : Julien Mathis and Romain Le Merlus under # Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0. # GPL Licence 2.0.
# #
@ -18,18 +18,19 @@
# combined work based on this program. Thus, the terms and conditions of the GNU # combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination. # General Public License cover the whole combination.
# #
# As a special exception, the copyright holders of this program give MERETHIS # As a special exception, the copyright holders of this program give CENTREON
# permission to link this program with independent modules to produce an timeelapsedutable, # permission to link this program with independent modules to produce an timeelapsedutable,
# regardless of the license terms of these independent modules, and to copy and # regardless of the license terms of these independent modules, and to copy and
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that # distribute the resulting timeelapsedutable under terms of CENTREON choice, provided that
# MERETHIS also meet, for each linked independent module, the terms and conditions # CENTREON also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not # of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this # derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you # exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version. # do not wish to do so, delete this exception statement from your version.
# #
# For more information : contact@centreon.com # For more information : contact@centreon.com
# Author : Simon BOMM <sbomm@merethis.com> # Authors : Simon BOMM <sbomm@merethis.com>
# Mathieu Cinquin <mcinquin@centreon.com>
# #
# Based on De Bodt Lieven plugin # Based on De Bodt Lieven plugin
#################################################################################### ####################################################################################
@ -50,7 +51,7 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.1';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"data:s" => { name => 'data' }, "data:s" => { name => 'data' },
@ -68,6 +69,9 @@ sub new {
"get-param:s@" => { name => 'get_param' }, "get-param:s@" => { name => 'get_param' },
"timeout:s" => { name => 'timeout', default => 10 }, "timeout:s" => { name => 'timeout', default => 10 },
"ssl:s" => { name => 'ssl', }, "ssl:s" => { name => 'ssl', },
"cert-file:s" => { name => 'cert_file' },
"cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' },
"warning-numeric:s" => { name => 'warning_numeric' }, "warning-numeric:s" => { name => 'warning_numeric' },
"critical-numeric:s" => { name => 'critical_numeric' }, "critical-numeric:s" => { name => 'critical_numeric' },
@ -129,6 +133,10 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option"); $self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used");
$self->{output}->option_exit();
}
$self->{headers} = {}; $self->{headers} = {};
if (defined($self->{option_results}->{header})) { if (defined($self->{option_results}->{header})) {
foreach (@{$self->{option_results}->{header}}) { foreach (@{$self->{option_results}->{header}}) {
@ -442,6 +450,18 @@ Threshold for HTTP timeout (Default: 10)
Specify SSL version (example : 'sslv3', 'tlsv1'...) Specify SSL version (example : 'sslv3', 'tlsv1'...)
=item B<--cert-file>
Specify certificate to send to the webserver
=item B<--cert-pwd>
Specify certificate's password
=item B<--cert-pkcs12>
Specify type of certificate (PKCS12)
=item B<--get-param> =item B<--get-param>
Set GET params (Multiple option. Example: --get-param='key=value') Set GET params (Multiple option. Example: --get-param='key=value')

View File

@ -1,5 +1,5 @@
############################################################################### ###############################################################################
# Copyright 2005-2013 MERETHIS # Copyright 2005-2015 CENTREON
# Centreon is developped by : Julien Mathis and Romain Le Merlus under # Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0. # GPL Licence 2.0.
# #
@ -18,18 +18,20 @@
# combined work based on this program. Thus, the terms and conditions of the GNU # combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination. # General Public License cover the whole combination.
# #
# As a special exception, the copyright holders of this program give MERETHIS # As a special exception, the copyright holders of this program give CENTREON
# permission to link this program with independent modules to produce an timeelapsedutable, # permission to link this program with independent modules to produce an timeelapsedutable,
# regardless of the license terms of these independent modules, and to copy and # regardless of the license terms of these independent modules, and to copy and
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that # distribute the resulting timeelapsedutable under terms of CENTREON choice, provided that
# MERETHIS also meet, for each linked independent module, the terms and conditions # CENTREON also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not # of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this # derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you # exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version. # do not wish to do so, delete this exception statement from your version.
# #
# For more information : contact@centreon.com # For more information : contact@centreon.com
# Author : Simon BOMM <sbomm@merethis.com> # Authors : Simon BOMM <sbomm@merethis.com>
# Mathieu Cinquin <mcinquin@centreon.com>
#
# #
# Based on De Bodt Lieven plugin # Based on De Bodt Lieven plugin
#################################################################################### ####################################################################################
@ -48,7 +50,7 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.1';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"hostname:s" => { name => 'hostname' }, "hostname:s" => { name => 'hostname' },
@ -64,6 +66,9 @@ sub new {
"critical:s" => { name => 'critical' }, "critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '3' }, "timeout:s" => { name => 'timeout', default => '3' },
"ssl:s" => { name => 'ssl', }, "ssl:s" => { name => 'ssl', },
"cert-file:s" => { name => 'cert_file' },
"cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' },
}); });
return $self; return $self;
} }
@ -94,6 +99,10 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used"); $self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used");
$self->{output}->option_exit();
}
} }
sub run { sub run {
@ -186,6 +195,18 @@ Threshold warning in seconds (Webpage response time)
Threshold critical in seconds (Webpage response time) Threshold critical in seconds (Webpage response time)
=item B<--cert-file>
Specify certificate to send to the webserver
=item B<--cert-pwd>
Specify certificate's password
=item B<--cert-pkcs12>
Specify type of certificate (PKCS12)
=back =back
=cut =cut

View File

@ -1,5 +1,5 @@
############################################################################### ###############################################################################
# Copyright 2005-2013 MERETHIS # Copyright 2005-2015 CENTREON
# Centreon is developped by : Julien Mathis and Romain Le Merlus under # Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0. # GPL Licence 2.0.
# #
@ -18,18 +18,19 @@
# combined work based on this program. Thus, the terms and conditions of the GNU # combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination. # General Public License cover the whole combination.
# #
# As a special exception, the copyright holders of this program give MERETHIS # As a special exception, the copyright holders of this program give CENTREON
# permission to link this program with independent modules to produce an timeelapsedutable, # permission to link this program with independent modules to produce an timeelapsedutable,
# regardless of the license terms of these independent modules, and to copy and # regardless of the license terms of these independent modules, and to copy and
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that # distribute the resulting timeelapsedutable under terms of CENTREON choice, provided that
# MERETHIS also meet, for each linked independent module, the terms and conditions # CENTREON also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not # of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this # derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you # exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version. # do not wish to do so, delete this exception statement from your version.
# #
# For more information : contact@centreon.com # For more information : contact@centreon.com
# Author : Simon BOMM <sbomm@merethis.com> # Authors : Simon BOMM <sbomm@merethis.com>
# Mathieu Cinquin <mcinquin@merethis.com>
# #
# Based on De Bodt Lieven plugin # Based on De Bodt Lieven plugin
#################################################################################### ####################################################################################
@ -49,7 +50,7 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.1';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"service-soap:s" => { name => 'service_soap' }, "service-soap:s" => { name => 'service_soap' },
@ -67,6 +68,9 @@ sub new {
"header:s@" => { name => 'header' }, "header:s@" => { name => 'header' },
"timeout:s" => { name => 'timeout', default => 10 }, "timeout:s" => { name => 'timeout', default => 10 },
"ssl:s" => { name => 'ssl', }, "ssl:s" => { name => 'ssl', },
"cert-file:s" => { name => 'cert_file' },
"cert-pwd:s" => { name => 'cert_pwd' },
"cert-pkcs12" => { name => 'cert_pkcs12' },
"warning-numeric:s" => { name => 'warning_numeric' }, "warning-numeric:s" => { name => 'warning_numeric' },
"critical-numeric:s" => { name => 'critical_numeric' }, "critical-numeric:s" => { name => 'critical_numeric' },
@ -136,6 +140,10 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option"); $self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if ((defined($self->{option_results}->{pkcs12})) && (!defined($self->{option_results}->{cert_file}) && !defined($self->{option_results}->{cert_pwd}))) {
$self->{output}->add_option_msg(short_msg => "You need to set --cert-file= and --cert-pwd= options when --pkcs12 is used");
$self->{output}->option_exit();
}
$self->{headers} = {}; $self->{headers} = {};
if (defined($self->{option_results}->{header})) { if (defined($self->{option_results}->{header})) {
foreach (@{$self->{option_results}->{header}}) { foreach (@{$self->{option_results}->{header}}) {
@ -437,6 +445,18 @@ Threshold for HTTP timeout (Default: 10)
Specify SSL version (example : 'sslv3', 'tlsv1'...) Specify SSL version (example : 'sslv3', 'tlsv1'...)
=item B<--cert-file>
Specify certificate to send to the webserver
=item B<--cert-pwd>
Specify certificate's password
=item B<--cert-pkcs12>
Specify type of certificate (PKCS1
=item B<--header> =item B<--header>
Set HTTP headers (Multiple option) Set HTTP headers (Multiple option)

View File

@ -1,5 +1,5 @@
############################################################################### ###############################################################################
# Copyright 2005-2013 MERETHIS # Copyright 2005-2015 CENTREON
# Centreon is developped by : Julien Mathis and Romain Le Merlus under # Centreon is developped by : Julien Mathis and Romain Le Merlus under
# GPL Licence 2.0. # GPL Licence 2.0.
# #
@ -18,18 +18,19 @@
# combined work based on this program. Thus, the terms and conditions of the GNU # combined work based on this program. Thus, the terms and conditions of the GNU
# General Public License cover the whole combination. # General Public License cover the whole combination.
# #
# As a special exception, the copyright holders of this program give MERETHIS # As a special exception, the copyright holders of this program give CENTREON
# permission to link this program with independent modules to produce an timeelapsedutable, # permission to link this program with independent modules to produce an timeelapsedutable,
# regardless of the license terms of these independent modules, and to copy and # regardless of the license terms of these independent modules, and to copy and
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that # distribute the resulting timeelapsedutable under terms of CENTREON choice, provided that
# MERETHIS also meet, for each linked independent module, the terms and conditions # CENTREON also meet, for each linked independent module, the terms and conditions
# of the license of that module. An independent module is a module which is not # of the license of that module. An independent module is a module which is not
# derived from this program. If you modify this program, you may extend this # derived from this program. If you modify this program, you may extend this
# exception to your version of the program, but you are not obliged to do so. If you # exception to your version of the program, but you are not obliged to do so. If you
# do not wish to do so, delete this exception statement from your version. # do not wish to do so, delete this exception statement from your version.
# #
# For more information : contact@centreon.com # For more information : contact@centreon.com
# Author : Simon BOMM <sbomm@merethis.com> # Authors : Simon BOMM <sbomm@merethis.com>
# Mathieu Cinquin <mcinquin@centreon.com>
# #
# Based on De Bodt Lieven plugin # Based on De Bodt Lieven plugin
#################################################################################### ####################################################################################
@ -125,6 +126,17 @@ sub connect {
IO::Socket::SSL::set_default_context($context); IO::Socket::SSL::set_default_context($context);
} }
if (defined($self->{option_results}->{cert_pkcs12}) && $self->{option_results}->{cert_file} ne '' && $self->{option_results}->{cert_pwd} ne '') {
eval "use Net::SSL"; die $@ if $@;
$ENV{HTTPS_PKCS12_FILE} = $self->{option_results}->{cert_file};
$ENV{HTTPS_PKCS12_PASSWORD} = $self->{option_results}->{cert_pwd};
}
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};
}
$response = $ua->request($req); $response = $ua->request($req);
if ($response->is_success) { if ($response->is_success) {