mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-28 08:04:36 +02:00
Add option to send a certificate with conditional module load - Refs #6202
This commit is contained in:
parent
f867e349dd
commit
d9631e2956
@ -1,35 +1,36 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# 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.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify it under
|
# 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
|
# the terms of the GNU General Public License as published by the Free Software
|
||||||
# Foundation ; either version 2 of the License.
|
# Foundation ; either version 2 of the License.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
# 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.
|
# 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>.
|
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||||
#
|
#
|
||||||
# Linking this program statically or dynamically with other modules is making a
|
# 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
|
# 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,13 +90,17 @@ 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 {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
if (!defined($self->{option_results}->{port})) {
|
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);
|
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||||
@ -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
|
||||||
|
@ -1,35 +1,36 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# 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.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify it under
|
# 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
|
# the terms of the GNU General Public License as published by the Free Software
|
||||||
# Foundation ; either version 2 of the License.
|
# Foundation ; either version 2 of the License.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
# 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.
|
# 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>.
|
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||||
#
|
#
|
||||||
# Linking this program statically or dynamically with other modules is making a
|
# 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
|
# 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,7 +69,10 @@ 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' },
|
||||||
"warning-string:s" => { name => 'warning_string' },
|
"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}->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}}) {
|
||||||
@ -158,7 +166,7 @@ sub check_options {
|
|||||||
|
|
||||||
sub load_request {
|
sub load_request {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{method} = 'GET';
|
$self->{method} = 'GET';
|
||||||
if (defined($self->{option_results}->{data})) {
|
if (defined($self->{option_results}->{data})) {
|
||||||
local $/ = undef;
|
local $/ = undef;
|
||||||
@ -176,7 +184,7 @@ sub load_request {
|
|||||||
|
|
||||||
sub display_output {
|
sub display_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
foreach my $severity (('ok', 'warning', 'critical')) {
|
foreach my $severity (('ok', 'warning', 'critical')) {
|
||||||
next if (scalar(@{$self->{'values_' . $severity}}) == 0 && scalar(@{$self->{'values_string_' . $severity}}) == 0);
|
next if (scalar(@{$self->{'values_' . $severity}}) == 0 && scalar(@{$self->{'values_string_' . $severity}}) == 0);
|
||||||
my $format = $self->{option_results}->{'format_' . $severity};
|
my $format = $self->{option_results}->{'format_' . $severity};
|
||||||
@ -197,7 +205,7 @@ sub display_output {
|
|||||||
sub lookup {
|
sub lookup {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
my ($xpath, @values);
|
my ($xpath, @values);
|
||||||
|
|
||||||
my $json = JSON->new;
|
my $json = JSON->new;
|
||||||
my $content;
|
my $content;
|
||||||
eval {
|
eval {
|
||||||
@ -207,7 +215,7 @@ sub lookup {
|
|||||||
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
|
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $xpath_find (@{$self->{option_results}->{lookup}}) {
|
foreach my $xpath_find (@{$self->{option_results}->{lookup}}) {
|
||||||
eval {
|
eval {
|
||||||
my $jpath = JSON::Path->new($xpath_find);
|
my $jpath = JSON::Path->new($xpath_find);
|
||||||
@ -217,7 +225,7 @@ sub lookup {
|
|||||||
$self->{output}->add_option_msg(short_msg => "Cannot lookup: $@");
|
$self->{output}->add_option_msg(short_msg => "Cannot lookup: $@");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "Lookup XPath $xpath_find:");
|
$self->{output}->output_add(long_msg => "Lookup XPath $xpath_find:");
|
||||||
foreach my $value (@values) {
|
foreach my $value (@values) {
|
||||||
$self->{count}++;
|
$self->{count}++;
|
||||||
@ -225,26 +233,26 @@ sub lookup {
|
|||||||
push @{$self->{values}}, $value;
|
push @{$self->{values}}, $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($self->{option_results}->{threshold_value} eq 'count') {
|
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' } ]));
|
threshold => [ { label => 'critical-numeric', exit_litteral => 'critical' }, { label => 'warning-numeric', exit_litteral => 'warning' } ]));
|
||||||
push @{$self->{'values_' . $exit}}, $self->{count};
|
push @{$self->{'values_' . $exit}}, $self->{count};
|
||||||
$self->{'count_' . $exit}++;
|
$self->{'count_' . $exit}++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->perfdata_add(label => 'count',
|
$self->{output}->perfdata_add(label => 'count',
|
||||||
value => $self->{count},
|
value => $self->{count},
|
||||||
warning => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-numeric') : undef,
|
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,
|
critical => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef,
|
||||||
min => 0);
|
min => 0);
|
||||||
|
|
||||||
my $count = 0;
|
my $count = 0;
|
||||||
foreach my $value (@{$self->{values}}) {
|
foreach my $value (@{$self->{values}}) {
|
||||||
$count++;
|
$count++;
|
||||||
if ($value =~ /^[0-9.]+$/) {
|
if ($value =~ /^[0-9.]+$/) {
|
||||||
if ($self->{option_results}->{threshold_value} eq 'values') {
|
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' } ]));
|
threshold => [ { label => 'critical-numeric', exit_litteral => 'critical' }, { label => 'warning-numeric', exit_litteral => 'warning' } ]));
|
||||||
push @{$self->{'values_' . $exit}}, $value;
|
push @{$self->{'values_' . $exit}}, $value;
|
||||||
$self->{'count_' . $exit}++
|
$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,
|
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);
|
critical => $self->{option_results}->{threshold_value} eq 'values' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef);
|
||||||
} else {
|
} 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}/) {
|
$value =~ /$self->{option_results}->{critical_string}/) {
|
||||||
push @{$self->{values_string_critical}}, $value;
|
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}/) {
|
$value =~ /$self->{option_results}->{warning_string}/) {
|
||||||
push @{$self->{values_string_warning}}, $value;
|
push @{$self->{values_string_warning}}, $value;
|
||||||
} else {
|
} else {
|
||||||
@ -265,7 +273,7 @@ sub lookup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->display_output();
|
$self->display_output();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,12 +281,12 @@ sub run {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
if (!defined($self->{option_results}->{port})) {
|
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();
|
$self->load_request();
|
||||||
|
|
||||||
my $timing0 = [gettimeofday];
|
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});
|
query_form_get => $self->{get_params}, query_form_post => $self->{json_request});
|
||||||
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||||
|
|
||||||
@ -289,7 +297,7 @@ sub run {
|
|||||||
} else {
|
} else {
|
||||||
$self->lookup();
|
$self->lookup();
|
||||||
}
|
}
|
||||||
|
|
||||||
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
||||||
threshold => [ { label => 'critical-time', exit_litteral => 'critical' }, { label => 'warning-time', exit_litteral => 'warning' } ]);
|
threshold => [ { label => 'critical-time', exit_litteral => 'critical' }, { label => 'warning-time', exit_litteral => 'warning' } ]);
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
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'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-time'),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-time'),
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-time'),
|
||||||
min => 0);
|
min => 0);
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
@ -340,7 +348,7 @@ FORMAT OPTIONS:
|
|||||||
=item B<--format-ok>
|
=item B<--format-ok>
|
||||||
|
|
||||||
Output format (Default: '%{count} element(s) finded')
|
Output format (Default: '%{count} element(s) finded')
|
||||||
Can used:
|
Can used:
|
||||||
'%{values}' = display all values (also text string)
|
'%{values}' = display all values (also text string)
|
||||||
'%{values_ok}' = values from attributes and text node only (seperated by option values-separator)
|
'%{values_ok}' = values from attributes and text node only (seperated by option values-separator)
|
||||||
'%{values_warning}' and '%{values_critical}'
|
'%{values_warning}' and '%{values_critical}'
|
||||||
@ -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')
|
||||||
|
@ -1,35 +1,37 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# 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.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify it under
|
# 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
|
# the terms of the GNU General Public License as published by the Free Software
|
||||||
# Foundation ; either version 2 of the License.
|
# Foundation ; either version 2 of the License.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
# 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.
|
# 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>.
|
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||||
#
|
#
|
||||||
# Linking this program statically or dynamically with other modules is making a
|
# 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
|
# 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 {
|
||||||
@ -102,15 +111,15 @@ sub run {
|
|||||||
if (!defined($self->{option_results}->{port})) {
|
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 $timing0 = [gettimeofday];
|
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]);
|
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => $webcontent);
|
$self->{output}->output_add(long_msg => $webcontent);
|
||||||
|
|
||||||
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
||||||
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(severity => $exit,
|
||||||
@ -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
|
||||||
|
@ -1,35 +1,36 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# 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.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify it under
|
# 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
|
# the terms of the GNU General Public License as published by the Free Software
|
||||||
# Foundation ; either version 2 of the License.
|
# Foundation ; either version 2 of the License.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
# 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.
|
# 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>.
|
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||||
#
|
#
|
||||||
# Linking this program statically or dynamically with other modules is making a
|
# 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
|
# 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,7 +68,10 @@ 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' },
|
||||||
"warning-string:s" => { name => 'warning_string' },
|
"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}->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}}) {
|
||||||
@ -149,7 +157,7 @@ sub check_options {
|
|||||||
|
|
||||||
sub load_request {
|
sub load_request {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
local $/ = undef;
|
local $/ = undef;
|
||||||
if (!open(FILE, "<", $self->{option_results}->{data})) {
|
if (!open(FILE, "<", $self->{option_results}->{data})) {
|
||||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||||
@ -163,7 +171,7 @@ sub load_request {
|
|||||||
|
|
||||||
sub display_output {
|
sub display_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
foreach my $severity (('ok', 'warning', 'critical')) {
|
foreach my $severity (('ok', 'warning', 'critical')) {
|
||||||
next if (scalar(@{$self->{'values_' . $severity}}) == 0 && scalar(@{$self->{'values_string_' . $severity}}) == 0);
|
next if (scalar(@{$self->{'values_' . $severity}}) == 0 && scalar(@{$self->{'values_string_' . $severity}}) == 0);
|
||||||
my $format = $self->{option_results}->{'format_' . $severity};
|
my $format = $self->{option_results}->{'format_' . $severity};
|
||||||
@ -184,7 +192,7 @@ sub display_output {
|
|||||||
sub lookup {
|
sub lookup {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
my ($xpath, $nodeset);
|
my ($xpath, $nodeset);
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
$xpath = XML::XPath->new(xml => $self->{soap_response});
|
$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}->add_option_msg(short_msg => "Cannot load SOAP response");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $xpath_find (@{$self->{option_results}->{lookup}}) {
|
foreach my $xpath_find (@{$self->{option_results}->{lookup}}) {
|
||||||
eval {
|
eval {
|
||||||
$nodeset = $xpath->find($xpath_find);
|
$nodeset = $xpath->find($xpath_find);
|
||||||
@ -201,7 +209,7 @@ sub lookup {
|
|||||||
$self->{output}->add_option_msg(short_msg => "Cannot lookup: $@");
|
$self->{output}->add_option_msg(short_msg => "Cannot lookup: $@");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "Lookup XPath $xpath_find:");
|
$self->{output}->output_add(long_msg => "Lookup XPath $xpath_find:");
|
||||||
foreach my $node ($nodeset->get_nodelist()) {
|
foreach my $node ($nodeset->get_nodelist()) {
|
||||||
$self->{count}++;
|
$self->{count}++;
|
||||||
@ -217,26 +225,26 @@ sub lookup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($self->{option_results}->{threshold_value} eq 'count') {
|
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' } ]));
|
threshold => [ { label => 'critical-numeric', exit_litteral => 'critical' }, { label => 'warning-numeric', exit_litteral => 'warning' } ]));
|
||||||
push @{$self->{'values_' . $exit}}, $self->{count};
|
push @{$self->{'values_' . $exit}}, $self->{count};
|
||||||
$self->{'count_' . $exit}++;
|
$self->{'count_' . $exit}++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->perfdata_add(label => 'count',
|
$self->{output}->perfdata_add(label => 'count',
|
||||||
value => $self->{count},
|
value => $self->{count},
|
||||||
warning => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-numeric') : undef,
|
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,
|
critical => $self->{option_results}->{threshold_value} eq 'count' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef,
|
||||||
min => 0);
|
min => 0);
|
||||||
|
|
||||||
my $count = 0;
|
my $count = 0;
|
||||||
foreach my $value (@{$self->{values}}) {
|
foreach my $value (@{$self->{values}}) {
|
||||||
$count++;
|
$count++;
|
||||||
if ($value =~ /^[0-9.]+$/) {
|
if ($value =~ /^[0-9.]+$/) {
|
||||||
if ($self->{option_results}->{threshold_value} eq 'values') {
|
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' } ]));
|
threshold => [ { label => 'critical-numeric', exit_litteral => 'critical' }, { label => 'warning-numeric', exit_litteral => 'warning' } ]));
|
||||||
push @{$self->{'values_' . $exit}}, $value;
|
push @{$self->{'values_' . $exit}}, $value;
|
||||||
$self->{'count_' . $exit}++
|
$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,
|
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);
|
critical => $self->{option_results}->{threshold_value} eq 'values' ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-numeric') : undef);
|
||||||
} else {
|
} 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}/) {
|
$value =~ /$self->{option_results}->{critical_string}/) {
|
||||||
push @{$self->{values_string_critical}}, $value;
|
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}/) {
|
$value =~ /$self->{option_results}->{warning_string}/) {
|
||||||
push @{$self->{values_string_warning}}, $value;
|
push @{$self->{values_string_warning}}, $value;
|
||||||
} else {
|
} else {
|
||||||
@ -257,7 +265,7 @@ sub lookup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->display_output();
|
$self->display_output();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +273,7 @@ sub run {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
if (!defined($self->{option_results}->{port})) {
|
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();
|
$self->load_request();
|
||||||
|
|
||||||
@ -280,7 +288,7 @@ sub run {
|
|||||||
} else {
|
} else {
|
||||||
$self->lookup();
|
$self->lookup();
|
||||||
}
|
}
|
||||||
|
|
||||||
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
|
||||||
threshold => [ { label => 'critical-time', exit_litteral => 'critical' }, { label => 'warning-time', exit_litteral => 'warning' } ]);
|
threshold => [ { label => 'critical-time', exit_litteral => 'critical' }, { label => 'warning-time', exit_litteral => 'warning' } ]);
|
||||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
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'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-time'),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-time'),
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-time'),
|
||||||
min => 0);
|
min => 0);
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
@ -306,7 +314,7 @@ __END__
|
|||||||
=head1 MODE
|
=head1 MODE
|
||||||
|
|
||||||
Check SOAP content. Send the soap request with option '--data'. Example:
|
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'
|
--header='Content-Type: text/xml;charset=UTF-8' --data='/home/user/soap_request.xml' --hostname='myws.site.com' --urlpath='/get/payment'
|
||||||
--lookup='//numeric/text()'
|
--lookup='//numeric/text()'
|
||||||
|
|
||||||
@ -335,7 +343,7 @@ FORMAT OPTIONS:
|
|||||||
=item B<--format-ok>
|
=item B<--format-ok>
|
||||||
|
|
||||||
Output format (Default: '%{count} element(s) finded')
|
Output format (Default: '%{count} element(s) finded')
|
||||||
Can used:
|
Can used:
|
||||||
'%{values}' = display all values (also text string)
|
'%{values}' = display all values (also text string)
|
||||||
'%{values_ok}' = values from attributes and text node only (seperated by option values-separator)
|
'%{values_ok}' = values from attributes and text node only (seperated by option values-separator)
|
||||||
'%{values_warning}' and '%{values_critical}'
|
'%{values_warning}' and '%{values_critical}'
|
||||||
@ -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)
|
||||||
|
@ -1,35 +1,36 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# 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.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify it under
|
# 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
|
# the terms of the GNU General Public License as published by the Free Software
|
||||||
# Foundation ; either version 2 of the License.
|
# Foundation ; either version 2 of the License.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
# 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.
|
# 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>.
|
# this program; if not, see <http://www.gnu.org/licenses>.
|
||||||
#
|
#
|
||||||
# Linking this program statically or dynamically with other modules is making a
|
# 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
|
# 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
|
||||||
####################################################################################
|
####################################################################################
|
||||||
@ -44,7 +45,7 @@ use URI;
|
|||||||
|
|
||||||
sub get_port {
|
sub get_port {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $cache_port = '';
|
my $cache_port = '';
|
||||||
if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} ne '') {
|
if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} ne '') {
|
||||||
$cache_port = $self->{option_results}->{port};
|
$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 = 80 if ($self->{option_results}->{proto} eq 'http');
|
||||||
$cache_port = 443 if ($self->{option_results}->{proto} eq 'https');
|
$cache_port = 443 if ($self->{option_results}->{proto} eq 'https');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cache_port;
|
return $cache_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,14 +61,14 @@ sub connect {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
my $method = defined($options{method}) ? $options{method} : 'GET';
|
my $method = defined($options{method}) ? $options{method} : 'GET';
|
||||||
my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
|
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},
|
my $ua = LWP::UserAgent->new(keep_alive => 1, protocols_allowed => ['http', 'https'], timeout => $self->{option_results}->{timeout},
|
||||||
requests_redirectable => [ 'GET', 'HEAD', 'POST' ]);
|
requests_redirectable => [ 'GET', 'HEAD', 'POST' ]);
|
||||||
if (defined($options{cookies_file})) {
|
if (defined($options{cookies_file})) {
|
||||||
$ua->cookie_jar(HTTP::Cookies->new(file => $options{cookies_file},
|
$ua->cookie_jar(HTTP::Cookies->new(file => $options{cookies_file},
|
||||||
autosave => 1));
|
autosave => 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($response, $content);
|
my ($response, $content);
|
||||||
my ($req, $url);
|
my ($req, $url);
|
||||||
if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} =~ /^[0-9]+$/) {
|
if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} =~ /^[0-9]+$/) {
|
||||||
@ -92,7 +93,7 @@ sub connect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($method eq 'POST') {
|
if ($method eq 'POST') {
|
||||||
if (defined($content_type_forced)) {
|
if (defined($content_type_forced)) {
|
||||||
$req->content_type($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_type('application/x-www-form-urlencoded');
|
||||||
$req->content($uri_post->query);
|
$req->content($uri_post->query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined($self->{option_results}->{credentials}) && defined($self->{option_results}->{ntlm})) {
|
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});
|
$ua->credentials($self->{option_results}->{hostname} . ':' . $self->{option_results}->{port}, '', $self->{option_results}->{username}, $self->{option_results}->{password});
|
||||||
} elsif (defined($self->{option_results}->{credentials})) {
|
} elsif (defined($self->{option_results}->{credentials})) {
|
||||||
$req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password});
|
$req->authorization_basic($self->{option_results}->{username}, $self->{option_results}->{password});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined($self->{option_results}->{proxyurl})) {
|
if (defined($self->{option_results}->{proxyurl})) {
|
||||||
$ua->proxy(['http', 'https'], $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);
|
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) {
|
||||||
$content = $response->content;
|
$content = $response->content;
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->output_add(severity => $connection_exit,
|
$self->{output}->output_add(severity => $connection_exit,
|
||||||
short_msg => $response->status_line);
|
short_msg => $response->status_line);
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user