Add option to send a certificate with conditional module load - Refs #6202
This commit is contained in:
parent
4967c3c9b6
commit
55332dea4d
|
@ -1,35 +1,36 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# Copyright 2005-2015 CENTREON
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# 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
|
||||
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS 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
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give CENTREON
|
||||
# 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
|
||||
# distribute the resulting timeelapsedutable under terms of CENTREON choice, provided that
|
||||
# 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
|
||||
# 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
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
#
|
||||
# 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
|
||||
####################################################################################
|
||||
|
@ -47,7 +48,7 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$self->{version} = '1.1';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
|
@ -62,6 +63,9 @@ sub new {
|
|||
"expected-string:s" => { name => 'expected_string' },
|
||||
"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' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
@ -86,13 +90,17 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
|
||||
$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 {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($self->{option_results}->{port})) {
|
||||
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
|
||||
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
|
||||
}
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
|
@ -163,6 +171,18 @@ Threshold for HTTP timeout
|
|||
|
||||
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>
|
||||
|
||||
Specify String to check on the Webpage
|
||||
|
|
|
@ -1,35 +1,36 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# Copyright 2005-2015 CENTREON
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# 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
|
||||
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS 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
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give CENTREON
|
||||
# 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
|
||||
# distribute the resulting timeelapsedutable under terms of CENTREON choice, provided that
|
||||
# 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
|
||||
# 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
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
#
|
||||
# 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
|
||||
####################################################################################
|
||||
|
@ -50,7 +51,7 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$self->{version} = '1.1';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"data:s" => { name => 'data' },
|
||||
|
@ -68,7 +69,10 @@ sub new {
|
|||
"get-param:s@" => { name => 'get_param' },
|
||||
"timeout:s" => { name => 'timeout', default => 10 },
|
||||
"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' },
|
||||
"critical-numeric:s" => { name => 'critical_numeric' },
|
||||
"warning-string:s" => { name => 'warning_string' },
|
||||
|
@ -129,6 +133,10 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
|
||||
$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} = {};
|
||||
if (defined($self->{option_results}->{header})) {
|
||||
foreach (@{$self->{option_results}->{header}}) {
|
||||
|
@ -158,7 +166,7 @@ sub check_options {
|
|||
|
||||
sub load_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
$self->{method} = 'GET';
|
||||
if (defined($self->{option_results}->{data})) {
|
||||
local $/ = undef;
|
||||
|
@ -176,7 +184,7 @@ sub load_request {
|
|||
|
||||
sub display_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
foreach my $severity (('ok', 'warning', 'critical')) {
|
||||
next if (scalar(@{$self->{'values_' . $severity}}) == 0 && scalar(@{$self->{'values_string_' . $severity}}) == 0);
|
||||
my $format = $self->{option_results}->{'format_' . $severity};
|
||||
|
@ -197,7 +205,7 @@ sub display_output {
|
|||
sub lookup {
|
||||
my ($self, %options) = @_;
|
||||
my ($xpath, @values);
|
||||
|
||||
|
||||
my $json = JSON->new;
|
||||
my $content;
|
||||
eval {
|
||||
|
@ -207,7 +215,7 @@ sub lookup {
|
|||
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
foreach my $xpath_find (@{$self->{option_results}->{lookup}}) {
|
||||
eval {
|
||||
my $jpath = JSON::Path->new($xpath_find);
|
||||
|
@ -217,7 +225,7 @@ sub lookup {
|
|||
$self->{output}->add_option_msg(short_msg => "Cannot lookup: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
$self->{output}->output_add(long_msg => "Lookup XPath $xpath_find:");
|
||||
foreach my $value (@values) {
|
||||
$self->{count}++;
|
||||
|
@ -225,26 +233,26 @@ sub lookup {
|
|||
push @{$self->{values}}, $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($self->{option_results}->{threshold_value} eq 'count') {
|
||||
my $exit = lc($self->{perfdata}->threshold_check(value => $self->{count},
|
||||
my $exit = lc($self->{perfdata}->threshold_check(value => $self->{count},
|
||||
threshold => [ { label => 'critical-numeric', exit_litteral => 'critical' }, { label => 'warning-numeric', exit_litteral => 'warning' } ]));
|
||||
push @{$self->{'values_' . $exit}}, $self->{count};
|
||||
$self->{'count_' . $exit}++;
|
||||
}
|
||||
|
||||
|
||||
$self->{output}->perfdata_add(label => 'count',
|
||||
value => $self->{count},
|
||||
warning => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-numeric') : undef,
|
||||
critical => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef,
|
||||
min => 0);
|
||||
|
||||
|
||||
my $count = 0;
|
||||
foreach my $value (@{$self->{values}}) {
|
||||
$count++;
|
||||
if ($value =~ /^[0-9.]+$/) {
|
||||
if ($self->{option_results}->{threshold_value} eq 'values') {
|
||||
my $exit = lc($self->{perfdata}->threshold_check(value => $value,
|
||||
my $exit = lc($self->{perfdata}->threshold_check(value => $value,
|
||||
threshold => [ { label => 'critical-numeric', exit_litteral => 'critical' }, { label => 'warning-numeric', exit_litteral => 'warning' } ]));
|
||||
push @{$self->{'values_' . $exit}}, $value;
|
||||
$self->{'count_' . $exit}++
|
||||
|
@ -254,10 +262,10 @@ sub lookup {
|
|||
warning => $self->{option_results}->{threshold_value} eq 'values' ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-numeric') : undef,
|
||||
critical => $self->{option_results}->{threshold_value} eq 'values' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef);
|
||||
} else {
|
||||
if (defined($self->{option_results}->{critical_string}) && $self->{option_results}->{critical_string} ne '' &&
|
||||
if (defined($self->{option_results}->{critical_string}) && $self->{option_results}->{critical_string} ne '' &&
|
||||
$value =~ /$self->{option_results}->{critical_string}/) {
|
||||
push @{$self->{values_string_critical}}, $value;
|
||||
} elsif (defined($self->{option_results}->{warning_string}) && $self->{option_results}->{warning_string} ne '' &&
|
||||
} elsif (defined($self->{option_results}->{warning_string}) && $self->{option_results}->{warning_string} ne '' &&
|
||||
$value =~ /$self->{option_results}->{warning_string}/) {
|
||||
push @{$self->{values_string_warning}}, $value;
|
||||
} else {
|
||||
|
@ -265,7 +273,7 @@ sub lookup {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$self->display_output();
|
||||
}
|
||||
|
||||
|
@ -273,12 +281,12 @@ sub run {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($self->{option_results}->{port})) {
|
||||
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
|
||||
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
|
||||
}
|
||||
$self->load_request();
|
||||
|
||||
|
||||
my $timing0 = [gettimeofday];
|
||||
$self->{json_response} = centreon::plugins::httplib::connect($self, headers => $self->{headers}, method => $self->{method},
|
||||
$self->{json_response} = centreon::plugins::httplib::connect($self, headers => $self->{headers}, method => $self->{method},
|
||||
query_form_get => $self->{get_params}, query_form_post => $self->{json_request});
|
||||
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||
|
||||
|
@ -289,7 +297,7 @@ sub run {
|
|||
} else {
|
||||
$self->lookup();
|
||||
}
|
||||
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
||||
threshold => [ { label => 'critical-time', exit_litteral => 'critical' }, { label => 'warning-time', exit_litteral => 'warning' } ]);
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
|
@ -303,7 +311,7 @@ sub run {
|
|||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-time'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-time'),
|
||||
min => 0);
|
||||
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
@ -340,7 +348,7 @@ FORMAT OPTIONS:
|
|||
=item B<--format-ok>
|
||||
|
||||
Output format (Default: '%{count} element(s) finded')
|
||||
Can used:
|
||||
Can used:
|
||||
'%{values}' = display all values (also text string)
|
||||
'%{values_ok}' = values from attributes and text node only (seperated by option values-separator)
|
||||
'%{values_warning}' and '%{values_critical}'
|
||||
|
@ -442,6 +450,18 @@ Threshold for HTTP timeout (Default: 10)
|
|||
|
||||
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>
|
||||
|
||||
Set GET params (Multiple option. Example: --get-param='key=value')
|
||||
|
|
|
@ -1,35 +1,37 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# Copyright 2005-2015 CENTREON
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# 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
|
||||
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS 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
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give CENTREON
|
||||
# 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
|
||||
# distribute the resulting timeelapsedutable under terms of CENTREON choice, provided that
|
||||
# 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
|
||||
# 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
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
#
|
||||
# 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
|
||||
####################################################################################
|
||||
|
@ -48,7 +50,7 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$self->{version} = '1.1';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
|
@ -64,6 +66,9 @@ sub new {
|
|||
"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' },
|
||||
});
|
||||
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}->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 {
|
||||
|
@ -102,15 +111,15 @@ sub run {
|
|||
if (!defined($self->{option_results}->{port})) {
|
||||
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
|
||||
}
|
||||
|
||||
|
||||
my $timing0 = [gettimeofday];
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
|
||||
|
||||
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||
|
||||
$self->{output}->output_add(long_msg => $webcontent);
|
||||
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
||||
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
|
@ -186,6 +195,18 @@ Threshold warning 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
|
||||
|
||||
=cut
|
||||
|
|
|
@ -1,35 +1,36 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# Copyright 2005-2015 CENTREON
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# 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
|
||||
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS 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
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give CENTREON
|
||||
# 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
|
||||
# distribute the resulting timeelapsedutable under terms of CENTREON choice, provided that
|
||||
# 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
|
||||
# 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
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
#
|
||||
# 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
|
||||
####################################################################################
|
||||
|
@ -49,7 +50,7 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$self->{version} = '1.1';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"service-soap:s" => { name => 'service_soap' },
|
||||
|
@ -67,7 +68,10 @@ sub new {
|
|||
"header:s@" => { name => 'header' },
|
||||
"timeout:s" => { name => 'timeout', default => 10 },
|
||||
"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' },
|
||||
"critical-numeric:s" => { name => 'critical_numeric' },
|
||||
"warning-string:s" => { name => 'warning_string' },
|
||||
|
@ -136,6 +140,10 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
|
||||
$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} = {};
|
||||
if (defined($self->{option_results}->{header})) {
|
||||
foreach (@{$self->{option_results}->{header}}) {
|
||||
|
@ -149,7 +157,7 @@ sub check_options {
|
|||
|
||||
sub load_request {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
local $/ = undef;
|
||||
if (!open(FILE, "<", $self->{option_results}->{data})) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
|
@ -163,7 +171,7 @@ sub load_request {
|
|||
|
||||
sub display_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
foreach my $severity (('ok', 'warning', 'critical')) {
|
||||
next if (scalar(@{$self->{'values_' . $severity}}) == 0 && scalar(@{$self->{'values_string_' . $severity}}) == 0);
|
||||
my $format = $self->{option_results}->{'format_' . $severity};
|
||||
|
@ -184,7 +192,7 @@ sub display_output {
|
|||
sub lookup {
|
||||
my ($self, %options) = @_;
|
||||
my ($xpath, $nodeset);
|
||||
|
||||
|
||||
eval {
|
||||
$xpath = XML::XPath->new(xml => $self->{soap_response});
|
||||
};
|
||||
|
@ -192,7 +200,7 @@ sub lookup {
|
|||
$self->{output}->add_option_msg(short_msg => "Cannot load SOAP response");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
foreach my $xpath_find (@{$self->{option_results}->{lookup}}) {
|
||||
eval {
|
||||
$nodeset = $xpath->find($xpath_find);
|
||||
|
@ -201,7 +209,7 @@ sub lookup {
|
|||
$self->{output}->add_option_msg(short_msg => "Cannot lookup: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
|
||||
$self->{output}->output_add(long_msg => "Lookup XPath $xpath_find:");
|
||||
foreach my $node ($nodeset->get_nodelist()) {
|
||||
$self->{count}++;
|
||||
|
@ -217,26 +225,26 @@ sub lookup {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($self->{option_results}->{threshold_value} eq 'count') {
|
||||
my $exit = lc($self->{perfdata}->threshold_check(value => $self->{count},
|
||||
my $exit = lc($self->{perfdata}->threshold_check(value => $self->{count},
|
||||
threshold => [ { label => 'critical-numeric', exit_litteral => 'critical' }, { label => 'warning-numeric', exit_litteral => 'warning' } ]));
|
||||
push @{$self->{'values_' . $exit}}, $self->{count};
|
||||
$self->{'count_' . $exit}++;
|
||||
}
|
||||
|
||||
|
||||
$self->{output}->perfdata_add(label => 'count',
|
||||
value => $self->{count},
|
||||
warning => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-numeric') : undef,
|
||||
critical => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef,
|
||||
min => 0);
|
||||
|
||||
|
||||
my $count = 0;
|
||||
foreach my $value (@{$self->{values}}) {
|
||||
$count++;
|
||||
if ($value =~ /^[0-9.]+$/) {
|
||||
if ($self->{option_results}->{threshold_value} eq 'values') {
|
||||
my $exit = lc($self->{perfdata}->threshold_check(value => $value,
|
||||
my $exit = lc($self->{perfdata}->threshold_check(value => $value,
|
||||
threshold => [ { label => 'critical-numeric', exit_litteral => 'critical' }, { label => 'warning-numeric', exit_litteral => 'warning' } ]));
|
||||
push @{$self->{'values_' . $exit}}, $value;
|
||||
$self->{'count_' . $exit}++
|
||||
|
@ -246,10 +254,10 @@ sub lookup {
|
|||
warning => $self->{option_results}->{threshold_value} eq 'values' ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-numeric') : undef,
|
||||
critical => $self->{option_results}->{threshold_value} eq 'values' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef);
|
||||
} else {
|
||||
if (defined($self->{option_results}->{critical_string}) && $self->{option_results}->{critical_string} ne '' &&
|
||||
if (defined($self->{option_results}->{critical_string}) && $self->{option_results}->{critical_string} ne '' &&
|
||||
$value =~ /$self->{option_results}->{critical_string}/) {
|
||||
push @{$self->{values_string_critical}}, $value;
|
||||
} elsif (defined($self->{option_results}->{warning_string}) && $self->{option_results}->{warning_string} ne '' &&
|
||||
} elsif (defined($self->{option_results}->{warning_string}) && $self->{option_results}->{warning_string} ne '' &&
|
||||
$value =~ /$self->{option_results}->{warning_string}/) {
|
||||
push @{$self->{values_string_warning}}, $value;
|
||||
} else {
|
||||
|
@ -257,7 +265,7 @@ sub lookup {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$self->display_output();
|
||||
}
|
||||
|
||||
|
@ -265,7 +273,7 @@ sub run {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($self->{option_results}->{port})) {
|
||||
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
|
||||
$self->{option_results}->{port} = centreon::plugins::httplib::get_port($self);
|
||||
}
|
||||
$self->load_request();
|
||||
|
||||
|
@ -280,7 +288,7 @@ sub run {
|
|||
} else {
|
||||
$self->lookup();
|
||||
}
|
||||
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
||||
threshold => [ { label => 'critical-time', exit_litteral => 'critical' }, { label => 'warning-time', exit_litteral => 'warning' } ]);
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
|
@ -294,7 +302,7 @@ sub run {
|
|||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-time'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-time'),
|
||||
min => 0);
|
||||
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
@ -306,7 +314,7 @@ __END__
|
|||
=head1 MODE
|
||||
|
||||
Check SOAP content. Send the soap request with option '--data'. Example:
|
||||
centreon_plugins.pl --plugin=apps::protocols::http::plugin --mode=soap-content --service-soap='http://www.mysite.com/mysoapaction'
|
||||
centreon_plugins.pl --plugin=apps::protocols::http::plugin --mode=soap-content --service-soap='http://www.mysite.com/mysoapaction'
|
||||
--header='Content-Type: text/xml;charset=UTF-8' --data='/home/user/soap_request.xml' --hostname='myws.site.com' --urlpath='/get/payment'
|
||||
--lookup='//numeric/text()'
|
||||
|
||||
|
@ -335,7 +343,7 @@ FORMAT OPTIONS:
|
|||
=item B<--format-ok>
|
||||
|
||||
Output format (Default: '%{count} element(s) finded')
|
||||
Can used:
|
||||
Can used:
|
||||
'%{values}' = display all values (also text string)
|
||||
'%{values_ok}' = values from attributes and text node only (seperated by option values-separator)
|
||||
'%{values_warning}' and '%{values_critical}'
|
||||
|
@ -437,6 +445,18 @@ Threshold for HTTP timeout (Default: 10)
|
|||
|
||||
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>
|
||||
|
||||
Set HTTP headers (Multiple option)
|
||||
|
|
|
@ -1,35 +1,36 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# Copyright 2005-2015 CENTREON
|
||||
# Centreon is developped by : Julien Mathis and Romain Le Merlus under
|
||||
# GPL Licence 2.0.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation ; either version 2 of the License.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
#
|
||||
# Linking this program statically or dynamically with other modules is making a
|
||||
# combined work based on this program. Thus, the terms and conditions of the GNU
|
||||
# General Public License cover the whole combination.
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give MERETHIS
|
||||
# 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
|
||||
# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that
|
||||
# MERETHIS 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
|
||||
# derived from this program. If you modify this program, you may extend this
|
||||
#
|
||||
# As a special exception, the copyright holders of this program give CENTREON
|
||||
# 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
|
||||
# distribute the resulting timeelapsedutable under terms of CENTREON choice, provided that
|
||||
# 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
|
||||
# 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
|
||||
# do not wish to do so, delete this exception statement from your version.
|
||||
#
|
||||
#
|
||||
# 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
|
||||
####################################################################################
|
||||
|
@ -44,7 +45,7 @@ use URI;
|
|||
|
||||
sub get_port {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
my $cache_port = '';
|
||||
if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} ne '') {
|
||||
$cache_port = $self->{option_results}->{port};
|
||||
|
@ -52,7 +53,7 @@ sub get_port {
|
|||
$cache_port = 80 if ($self->{option_results}->{proto} eq 'http');
|
||||
$cache_port = 443 if ($self->{option_results}->{proto} eq 'https');
|
||||
}
|
||||
|
||||
|
||||
return $cache_port;
|
||||
}
|
||||
|
||||
|
@ -60,14 +61,14 @@ sub connect {
|
|||
my ($self, %options) = @_;
|
||||
my $method = defined($options{method}) ? $options{method} : 'GET';
|
||||
my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
|
||||
|
||||
|
||||
my $ua = LWP::UserAgent->new(keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout},
|
||||
requests_redirectable => [ 'GET', 'HEAD', 'POST' ]);
|
||||
if (defined($options{cookies_file})) {
|
||||
$ua->cookie_jar(HTTP::Cookies->new(file => $options{cookies_file},
|
||||
autosave => 1));
|
||||
}
|
||||
|
||||
|
||||
my ($response, $content);
|
||||
my ($req, $url);
|
||||
if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} =~ /^[0-9]+$/) {
|
||||
|
@ -92,7 +93,7 @@ sub connect {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($method eq 'POST') {
|
||||
if (defined($content_type_forced)) {
|
||||
$req->content_type($content_type_forced);
|
||||
|
@ -105,14 +106,14 @@ sub connect {
|
|||
$req->content_type('application/x-www-form-urlencoded');
|
||||
$req->content($uri_post->query);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{credentials}) && defined($self->{option_results}->{ntlm})) {
|
||||
$ua->credentials($self->{option_results}->{hostname} . ':' . $self->{option_results}->{port}, '', $self->{option_results}->{username}, $self->{option_results}->{password});
|
||||
} elsif (defined($self->{option_results}->{credentials})) {
|
||||
$req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password});
|
||||
}
|
||||
|
||||
|
||||
if (defined($self->{option_results}->{proxyurl})) {
|
||||
$ua->proxy(['http', 'https'], $self->{option_results}->{proxyurl});
|
||||
}
|
||||
|
@ -124,16 +125,27 @@ sub connect {
|
|||
);
|
||||
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);
|
||||
|
||||
if ($response->is_success) {
|
||||
$content = $response->content;
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
$self->{output}->output_add(severity => $connection_exit,
|
||||
short_msg => $response->status_line);
|
||||
short_msg => $response->status_line);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue