Merge branch 'master' of http://git.centreon.com/centreon-plugins
This commit is contained in:
commit
2886f09a3c
|
@ -0,0 +1,178 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package apps::apache::serverstatus::mode::cpuload;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/server-status/?auto" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
# If not present: cpuload is 0
|
||||
my ($cpuload) = 0;
|
||||
|
||||
if ($webcontent !~ /^ReqPerSec:\s+([^\s]+)/mi) {
|
||||
$self->{output}->add_option_msg(short_msg => "Apache 'ExtendedStatus' option is off.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ($webcontent =~ /^CPULoad:\s+([^\s]+)/mi) {
|
||||
$cpuload = $1;
|
||||
$cpuload = '0' . $cpuload if ($cpuload =~ /^\./);
|
||||
}
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $cpuload, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("CPU Load: %.2f %%", $cpuload));
|
||||
$self->{output}->perfdata_add(label => "cpuload", unit => '%',
|
||||
value => sprintf("%.2f", $cpuload),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0
|
||||
);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Apache WebServer CpuLoad
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/server-status/?auto')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning Threshold for CpuLoad
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Critical Threshold for CpuLoad
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -40,7 +40,8 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::apache::serverstatus::mode::libconnect;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,8 +52,9 @@ sub new {
|
|||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '80' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/server-status/?auto" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
|
@ -61,13 +63,15 @@ sub new {
|
|||
"critical:s" => { name => 'critical' },
|
||||
"warning-bytes:s" => { name => 'warning_bytes' },
|
||||
"critical-bytes:s" => { name => 'critical_bytes' },
|
||||
"warning-access:s" => { name => 'warning_access' },
|
||||
"critical-access:s" => { name => 'critical_access' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
|
@ -87,6 +91,14 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Wrong critical-bytes threshold '" . $self->{option_results}->{critical_bytes} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-access', value => $self->{option_results}->{warning_access})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-access threshold '" . $self->{option_results}->{warning_access} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-access', value => $self->{option_results}->{critical_access})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_access} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
|
@ -95,76 +107,101 @@ 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();
|
||||
}
|
||||
|
||||
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = apps::apache::serverstatus::mode::libconnect::connect($self);
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my ($rPerSec, $bPerReq, $total_access, $total_bytes, $avg_bPerSec);
|
||||
|
||||
$total_access = $1 if ($webcontent =~ /^Total Accesses:\s+([^\s]+)/mi);
|
||||
$total_bytes = $1 * 1024 if ($webcontent =~ /^Total kBytes:\s+([^\s]+)/mi);
|
||||
|
||||
my @webcontentarr = split("\n", $webcontent);
|
||||
my $i = 0;
|
||||
my ($rPerSec, $rPerSecSfx, $bPerSec, $bPerSecSfx, $bPerReq, $bPerReqSfx);
|
||||
|
||||
while (($i < @webcontentarr) && ((!defined($rPerSec)) || (!defined($bPerSec)) || (!defined($bPerReq)))) {
|
||||
if ($webcontentarr[$i] =~ /([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/sec\s-\s([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/second\s-\s([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/request/) {
|
||||
($rPerSec, $rPerSecSfx, $bPerSec, $bPerSecSfx, $bPerReq, $bPerReqSfx) = ($webcontentarr[$i] =~ /([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/sec\s-\s([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/second\s-\s([0-9]*\.?[0-9]+)\s([A-Za-z]+)\/request/);
|
||||
}
|
||||
$i++;
|
||||
$rPerSec = $1 if ($webcontent =~ /^ReqPerSec:\s+([^\s]+)/mi);
|
||||
# Need a little time to init
|
||||
if ($webcontent =~ /^BytesPerReq:\s+([^\s]+)/mi) {
|
||||
$bPerReq = $1
|
||||
} else {
|
||||
$bPerReq = 0;
|
||||
}
|
||||
$avg_bPerSec = $1 if ($webcontent =~ /^BytesPerSec:\s+([^\s]+)/mi);
|
||||
|
||||
if (!defined($rPerSec)) {
|
||||
if (!defined($avg_bPerSec)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Apache 'ExtendedStatus' option is off.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ($rPerSec =~ /^\./) {
|
||||
$rPerSec = '0' . $rPerSec;
|
||||
}
|
||||
$rPerSec = '0' . $rPerSec if ($rPerSec =~ /^\./);
|
||||
$avg_bPerSec = '0' . $avg_bPerSec if ($avg_bPerSec =~ /^\./);
|
||||
$bPerReq = '0' . $bPerReq if ($bPerReq =~ /^\./);
|
||||
|
||||
if ($bPerReqSfx eq 'kB') {
|
||||
$bPerReq = $bPerReq * 1024;
|
||||
} elsif ($bPerReqSfx eq 'mB') {
|
||||
$bPerReq = $bPerReq * 1024 * 1024;
|
||||
} elsif ($bPerReqSfx eq 'gB') {
|
||||
$bPerReq = $bPerReq * 1024 * 1024 * 1024;
|
||||
}
|
||||
$self->{statefile_value}->read(statefile => 'apache_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
my $old_total_access = $self->{statefile_value}->get(name => 'total_access');
|
||||
my $old_total_bytes = $self->{statefile_value}->get(name => 'total_bytes');
|
||||
|
||||
if ($bPerSecSfx eq 'kB') {
|
||||
$bPerSec = $bPerSec * 1024;
|
||||
} elsif ($bPerSecSfx eq 'mB') {
|
||||
$bPerSec = $bPerSec * 1024 * 1024;
|
||||
} elsif ($bPerSecSfx eq 'gB') {
|
||||
$bPerSec = $bPerSec * 1024 * 1024 * 1024;
|
||||
my $new_datas = {};
|
||||
$new_datas->{last_timestamp} = time();
|
||||
$new_datas->{total_bytes} = $total_bytes;
|
||||
$new_datas->{total_access} = $total_access;
|
||||
|
||||
$self->{statefile_value}->write(data => $new_datas);
|
||||
if (!defined($old_timestamp) || !defined($old_total_access)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
$old_total_access = 0 if ($old_total_access > $new_datas->{total_access});
|
||||
$old_total_bytes = 0 if ($old_total_bytes > $new_datas->{total_bytes});
|
||||
my $delta_time = $new_datas->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
my $bPerSec = ($new_datas->{total_bytes} - $old_total_bytes) / $delta_time;
|
||||
my $aPerSec = ($new_datas->{total_access} - $old_total_access) / $delta_time;
|
||||
|
||||
my $exit1 = $self->{perfdata}->threshold_check(value => $rPerSec, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
my $exit2 = $self->{perfdata}->threshold_check(value => $bPerReq, threshold => [ { label => 'critical-bytes', 'exit_litteral' => 'critical' }, { label => 'warning-bytes', exit_litteral => 'warning' } ]);
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
|
||||
my $exit2 = $self->{perfdata}->threshold_check(value => $bPerSec, threshold => [ { label => 'critical-bytes', 'exit_litteral' => 'critical' }, { label => 'warning-bytes', exit_litteral => 'warning' } ]);
|
||||
my $exit3 = $self->{perfdata}->threshold_check(value => $aPerSec, threshold => [ { label => 'critical-access', 'exit_litteral' => 'critical' }, { label => 'warning-access', exit_litteral => 'warning' } ]);
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
|
||||
|
||||
my ($bPerSec_value, $bPerSec_unit) = $self->{perfdata}->change_bytes(value => $bPerSec);
|
||||
my ($bPerReq_value, $bPerReq_unit) = $self->{perfdata}->change_bytes(value => $bPerReq);
|
||||
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("RequestPerSec: %s BytesPerSecond: %s BytesPerRequest: %s", $rPerSec,
|
||||
$bPerSec_value . ' ' . $bPerSec_unit,
|
||||
$bPerReq_value . ' ' . $bPerReq_unit));
|
||||
$self->{output}->perfdata_add(label => "requestPerSec",
|
||||
value => $rPerSec,
|
||||
unit => $rPerSecSfx,
|
||||
short_msg => sprintf("BytesPerSec: %s AccessPerSec: %.2f RequestPerSec: %.2f BytesPerRequest: %s ",
|
||||
$bPerSec_value . ' ' . $bPerSec_unit,
|
||||
$aPerSec,
|
||||
$rPerSec,
|
||||
$bPerReq_value . ' ' . $bPerReq_unit
|
||||
));
|
||||
$self->{output}->perfdata_add(label => "avg_RequestPerSec",
|
||||
value => sprintf("%.2f", $rPerSec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0
|
||||
);
|
||||
$self->{output}->perfdata_add(label => "bytesPerSec",
|
||||
value => $bPerSec,
|
||||
unit => 'B');
|
||||
$self->{output}->perfdata_add(label => "bytesPerRequest", unit => 'B',
|
||||
value => $bPerReq,
|
||||
$self->{output}->perfdata_add(label => "bytesPerSec", unit => 'B',
|
||||
value => sprintf("%.2f", $bPerSec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-bytes'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-bytes'),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => "avg_bytesPerRequest", unit => 'B',
|
||||
value => $bPerReq,
|
||||
min => 0
|
||||
);
|
||||
$self->{output}->perfdata_add(label => "avg_bytesPerSec", unit => 'B',
|
||||
value => $avg_bPerSec,
|
||||
min => 0
|
||||
);
|
||||
$self->{output}->perfdata_add(label => "accessPerSec",
|
||||
value => sprintf("%.2f", $aPerSec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-access'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-access'),
|
||||
min => 0);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
@ -197,6 +234,10 @@ Proxy URL if any
|
|||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/server-status/?auto')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
@ -209,8 +250,6 @@ Specify username for basic authentification (Mandatory if --credentials is speci
|
|||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
@ -225,11 +264,19 @@ Critical Threshold for Request per seconds
|
|||
|
||||
=item B<--warning-bytes>
|
||||
|
||||
Warning Threshold for Bytes Per Request
|
||||
Warning Threshold for Bytes per seconds
|
||||
|
||||
=item B<--critical-bytes>
|
||||
|
||||
Critical Threshold for Bytes Per Request
|
||||
Critical Threshold for Bytes per seconds
|
||||
|
||||
=item B<--warning-access>
|
||||
|
||||
Warning Threshold for Access per seconds
|
||||
|
||||
=item B<--critical-access>
|
||||
|
||||
Critical Threshold for Access per seconds
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ use base qw(centreon::plugins::mode);
|
|||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
use apps::apache::serverstatus::mode::libconnect;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -52,8 +52,9 @@ sub new {
|
|||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '80' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/server-status/?auto" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
|
@ -98,47 +99,21 @@ sub run {
|
|||
|
||||
my $timing0 = [gettimeofday];
|
||||
|
||||
my $webcontent = apps::apache::serverstatus::mode::libconnect::connect($self, connection_exit => 'critical');
|
||||
my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
|
||||
|
||||
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||
|
||||
if (defined $webcontent) {
|
||||
my @webcontentarr = split("\n", $webcontent);
|
||||
my $i = 0;
|
||||
my $ScoreBoard = "";
|
||||
my $PosPreBegin = undef;
|
||||
my $PosPreEnd = undef;
|
||||
while (($i < @webcontentarr) && ((!defined($PosPreBegin)) || (!defined($PosPreEnd)))) {
|
||||
if (!defined($PosPreBegin)) {
|
||||
if ($webcontentarr[$i] =~ m/<pre>/i) {
|
||||
$PosPreBegin = $i;
|
||||
}
|
||||
}
|
||||
if (defined($PosPreBegin)) {
|
||||
if ($webcontentarr[$i] =~ m/<\/pre>/i) {
|
||||
$PosPreEnd = $i;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
for ($i = $PosPreBegin; $i <= $PosPreEnd; $i++) {
|
||||
$ScoreBoard = $ScoreBoard . $webcontentarr[$i];
|
||||
}
|
||||
$ScoreBoard =~ s/^.*<[Pp][Rr][Ee]>//;
|
||||
$ScoreBoard =~ s/<\/[Pp][Rr][Ee].*>//;
|
||||
my $CountOpenSlots = ($ScoreBoard =~ tr/\.//);
|
||||
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,
|
||||
short_msg => sprintf("Response time %fs ", $timeelapsed));
|
||||
$self->{output}->perfdata_add(label => "time",
|
||||
value => $timeelapsed,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
}
|
||||
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,
|
||||
short_msg => sprintf("Response time %fs ", $timeelapsed));
|
||||
$self->{output}->perfdata_add(label => "time",
|
||||
value => $timeelapsed,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -147,7 +122,7 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check Apache WebServer statistics informations
|
||||
Check Apache WebServer Time Response
|
||||
|
||||
=over 8
|
||||
|
||||
|
@ -163,6 +138,10 @@ Port used by Apache
|
|||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/server-status/?auto')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
|
|
@ -40,7 +40,7 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::apache::serverstatus::mode::libconnect;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -51,8 +51,9 @@ sub new {
|
|||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '80' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/server-status/?auto" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
|
@ -65,7 +66,6 @@ sub new {
|
|||
}
|
||||
|
||||
sub check_options {
|
||||
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
|
@ -96,40 +96,17 @@ sub check_options {
|
|||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = apps::apache::serverstatus::mode::libconnect::connect($self);
|
||||
my @webcontentarr = split("\n", $webcontent);
|
||||
my $i = 0;
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my $ScoreBoard = "";
|
||||
my $PosPreBegin = undef;
|
||||
my $PosPreEnd = undef;
|
||||
|
||||
while (($i < @webcontentarr) && ((!defined($PosPreBegin)) || (!defined($PosPreEnd)))) {
|
||||
if (!defined($PosPreBegin)) {
|
||||
if ( $webcontentarr[$i] =~ m/<pre>/i ) {
|
||||
$PosPreBegin = $i;
|
||||
}
|
||||
}
|
||||
if (defined($PosPreBegin)) {
|
||||
if ( $webcontentarr[$i] =~ m/<\/pre>/i ) {
|
||||
$PosPreEnd = $i;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
if ($webcontent =~ /^Scoreboard:\s+([^\s]+)/mi) {
|
||||
$ScoreBoard = $1;
|
||||
}
|
||||
|
||||
for ($i = $PosPreBegin; $i <= $PosPreEnd; $i++) {
|
||||
$ScoreBoard = $ScoreBoard . $webcontentarr[$i];
|
||||
}
|
||||
|
||||
$ScoreBoard =~ s/^.*<[Pp][Rr][Ee]>//;
|
||||
$ScoreBoard =~ s/<\/[Pp][Rr][Ee].*>//;
|
||||
|
||||
|
||||
my $srvLimit = length($ScoreBoard);
|
||||
|
||||
my $CountOpenSlots = ($ScoreBoard =~ tr/\.//);
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $CountOpenSlots,
|
||||
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,
|
||||
short_msg => sprintf("Free slots: %d", $CountOpenSlots));
|
||||
|
@ -190,6 +167,10 @@ Proxy URL if any
|
|||
|
||||
Protocol used http or https
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/server-status/?auto')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
|
|
@ -0,0 +1,188 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package apps::apache::serverstatus::mode::workers;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/server-status/?auto" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my ($BusyWorkers, $IdleWorkers, $ScoreBoard);
|
||||
if ($webcontent =~ /^BusyWorkers:\s+([^\s]+)/mi) {
|
||||
$BusyWorkers = $1;
|
||||
}
|
||||
if ($webcontent =~ /^IdleWorkers:\s+([^\s]+)/mi) {
|
||||
$IdleWorkers = $1;
|
||||
}
|
||||
if ($webcontent =~ /^Scoreboard:\s+([^\s]+)/mi) {
|
||||
$ScoreBoard = $1;
|
||||
}
|
||||
|
||||
my $srvLimit = length($ScoreBoard);
|
||||
my $prct_busy = $BusyWorkers / $srvLimit * 100;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $prct_busy,
|
||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Busy workers: %d Idle workers: %d (Server Limit: %d - %d %% Busy)", $BusyWorkers, $IdleWorkers, $srvLimit, $prct_busy));
|
||||
$self->{output}->perfdata_add(label => "idle_workers",
|
||||
value => $IdleWorkers,
|
||||
min => 0,
|
||||
max => $srvLimit);
|
||||
$self->{output}->perfdata_add(label => "busy_workers",
|
||||
value => $BusyWorkers,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0,
|
||||
max => $srvLimit);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Apache WebServer busy processes.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Protocol to use http or https, http is default
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/server-status/?auto')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning Threshold (%) of busy workers
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Critical Threshold (%) of busy workers
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -47,9 +47,11 @@ sub new {
|
|||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'responsetime' => 'apps::apache::serverstatus::mode::responsetime',
|
||||
'requests' => 'apps::apache::serverstatus::mode::requests',
|
||||
'slotstates' => 'apps::apache::serverstatus::mode::slotstates',
|
||||
'cpuload' => 'apps::apache::serverstatus::mode::cpuload',
|
||||
'responsetime' => 'apps::apache::serverstatus::mode::responsetime',
|
||||
'requests' => 'apps::apache::serverstatus::mode::requests',
|
||||
'slotstates' => 'apps::apache::serverstatus::mode::slotstates',
|
||||
'workers' => 'apps::apache::serverstatus::mode::workers',
|
||||
);
|
||||
|
||||
return $self;
|
||||
|
|
|
@ -0,0 +1,182 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::exchange::2010::local::mode::activesyncmailbox;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::common::powershell::exchange::2010::activesyncmailbox;
|
||||
|
||||
my %threshold = ('warning' => 'warning', 'critical' => 'critical');
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"no-ps" => { name => 'no_ps', },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
"command:s" => { name => 'command', default => 'powershell.exe' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
|
||||
"ps-exec-only" => { name => 'ps_exec_only', },
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
"mailbox:s" => { name => 'mailbox', },
|
||||
"password:s" => { name => 'password', },
|
||||
"no-trust-ssl" => { name => 'no_trust_ssl', },
|
||||
});
|
||||
$self->{thresholds} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{mailbox}) || $self->{option_results}->{mailbox} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify '--mailbox' option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{password}) || $self->{option_results}->{password} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify '--password' option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
foreach my $th (keys %threshold) {
|
||||
next if (!defined($self->{option_results}->{$th}));
|
||||
if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong threshold for option '--" . $th . "': " . $self->{option_results}->{$th});
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $operator = defined($1) && $1 ne '' ? $1 : '!=';
|
||||
my $state = defined($2) && $2 ne '' ? $2 : 'Success';
|
||||
$self->{thresholds}->{$th} = { state => $state, operator => $operator, out => $threshold{$th} };
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $ps = centreon::common::powershell::exchange::2010::activesyncmailbox::get_powershell(mailbox => $self->{option_results}->{mailbox},
|
||||
password => $self->{option_results}->{password},
|
||||
no_ps => $self->{option_results}->{no_ps},
|
||||
no_trust_ssl => $self->{option_results}->{no_trust_ssl}
|
||||
);
|
||||
$self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
|
||||
my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
|
||||
timeout => $self->{option_results}->{timeout},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options});
|
||||
if (defined($self->{option_results}->{ps_exec_only})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => $stdout);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
centreon::common::powershell::exchange::2010::activesyncmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check activesync to a mailbox.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout time for command execution (Default: 50 sec)
|
||||
|
||||
=item B<--no-ps>
|
||||
|
||||
Don't encode powershell. To be used with --command and 'type' command.
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Command to get information (Default: 'powershell.exe').
|
||||
Can be changed if you have output in a file. To be used with --no-ps option!!!
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: none).
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
|
||||
|
||||
=item B<--ps-exec-only>
|
||||
|
||||
Print powershell output.
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Critical threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--mailbox>
|
||||
|
||||
Set the mailbox to check (Required).
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Set the password for the mailbox (Required).
|
||||
|
||||
=item B<--no-trust-ssl>
|
||||
|
||||
By default, SSL certificate validy is not checked.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,195 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::exchange::2010::local::mode::databases;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::common::powershell::exchange::2010::databases;
|
||||
|
||||
my %threshold = ('warning_mapi' => 'warning', 'critical_mapi' => 'critical',
|
||||
'warning_mailflow' => 'warning', 'critical_mailflow' => 'critical');
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"no-ps" => { name => 'no_ps', },
|
||||
"no-mailflow" => { name => 'no_mailflow', },
|
||||
"no-mapi" => { name => 'no_mapi', },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
"command:s" => { name => 'command', default => 'powershell.exe' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
|
||||
"ps-exec-only" => { name => 'ps_exec_only', },
|
||||
"ps-database-filter:s" => { name => 'ps_database_filter', },
|
||||
"ps-database-test-filter:s" => { name => 'ps_database_test_filter', },
|
||||
"warning-mapi:s" => { name => 'warning_mapi', },
|
||||
"critical-mapi:s" => { name => 'critical_mapi', },
|
||||
"warning-mailflow:s" => { name => 'warning_mailflow', },
|
||||
"critical-mailflow:s" => { name => 'critical_mailflow', },
|
||||
});
|
||||
$self->{thresholds} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach my $th (keys %threshold) {
|
||||
next if (!defined($self->{option_results}->{$th}));
|
||||
if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) {
|
||||
$th =~ s/_/-/;
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong threshold for option '--" . $th . "': " . $self->{option_results}->{$th});
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $operator = defined($1) && $1 ne '' ? $1 : '!=';
|
||||
my $state = defined($2) && $2 ne '' ? $2 : 'Success';
|
||||
$self->{thresholds}->{$th} = { state => $state, operator => $operator, out => $threshold{$th} };
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $ps = centreon::common::powershell::exchange::2010::databases::get_powershell(no_mailflow => $self->{option_results}->{no_mailflow},
|
||||
no_ps => $self->{option_results}->{no_ps},
|
||||
no_mapi => $self->{option_results}->{no_mapi},
|
||||
filter_database => $self->{option_results}->{ps_database_filter},
|
||||
filter_database_test => $self->{option_results}->{ps_database_test_filter});
|
||||
$self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
|
||||
my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
|
||||
timeout => $self->{option_results}->{timeout},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options});
|
||||
if (defined($self->{option_results}->{ps_exec_only})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => $stdout);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
centreon::common::powershell::exchange::2010::databases::check($self, stdout => $stdout);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check: Exchange Databases are Mounted, Mapi/Mailflow Connectivity to all databases are working.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--no-mailflow>
|
||||
|
||||
Don't check mailflow connectivity.
|
||||
|
||||
=item B<--no-mapi>
|
||||
|
||||
Don't check mapi connectivity.
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout time for command execution (Default: 50 sec)
|
||||
|
||||
=item B<--no-ps>
|
||||
|
||||
Don't encode powershell. To be used with --command and 'type' command.
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Command to get information (Default: 'powershell.exe').
|
||||
Can be changed if you have output in a file. To be used with --no-ps option!!!
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: none).
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
|
||||
|
||||
=item B<--ps-exec-only>
|
||||
|
||||
Print powershell output.
|
||||
|
||||
=item B<--ps-database-filter>
|
||||
|
||||
Filter database (only wilcard '*' can be used. In Powershell).
|
||||
|
||||
=item B<--ps-database-test-filter>
|
||||
|
||||
Skip mapi/mailflow test (regexp can be used. In Powershell).
|
||||
|
||||
=item B<--warning-mapi>
|
||||
|
||||
Warning threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--critical-mapi>
|
||||
|
||||
Critical threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--warning-mailflow>
|
||||
|
||||
Warning threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--critical-mailflow>
|
||||
|
||||
Critical threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,176 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::exchange::2010::local::mode::imapmailbox;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::common::powershell::exchange::2010::imapmailbox;
|
||||
|
||||
my %threshold = ('warning' => 'warning', 'critical' => 'critical');
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"no-ps" => { name => 'no_ps', },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
"command:s" => { name => 'command', default => 'powershell.exe' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
|
||||
"ps-exec-only" => { name => 'ps_exec_only', },
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
"mailbox:s" => { name => 'mailbox', },
|
||||
"password:s" => { name => 'password', },
|
||||
});
|
||||
$self->{thresholds} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{mailbox}) || $self->{option_results}->{mailbox} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify '--mailbox' option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{password}) || $self->{option_results}->{password} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify '--password' option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
foreach my $th (keys %threshold) {
|
||||
next if (!defined($self->{option_results}->{$th}));
|
||||
if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong threshold for option '--" . $th . "': " . $self->{option_results}->{$th});
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $operator = defined($1) && $1 ne '' ? $1 : '!=';
|
||||
my $state = defined($2) && $2 ne '' ? $2 : 'Success';
|
||||
$self->{thresholds}->{$th} = { state => $state, operator => $operator, out => $threshold{$th} };
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $ps = centreon::common::powershell::exchange::2010::imapmailbox::get_powershell(mailbox => $self->{option_results}->{mailbox},
|
||||
password => $self->{option_results}->{password},
|
||||
no_ps => $self->{option_results}->{no_ps},
|
||||
);
|
||||
$self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
|
||||
my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
|
||||
timeout => $self->{option_results}->{timeout},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options});
|
||||
if (defined($self->{option_results}->{ps_exec_only})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => $stdout);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
centreon::common::powershell::exchange::2010::imapmailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check imap to a mailbox.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout time for command execution (Default: 50 sec)
|
||||
|
||||
=item B<--no-ps>
|
||||
|
||||
Don't encode powershell. To be used with --command and 'type' command.
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Command to get information (Default: 'powershell.exe').
|
||||
Can be changed if you have output in a file. To be used with --no-ps option!!!
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: none).
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
|
||||
|
||||
=item B<--ps-exec-only>
|
||||
|
||||
Print powershell output.
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Critical threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--mailbox>
|
||||
|
||||
Set the mailbox to check (Required).
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Set the password for the mailbox (Required).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,167 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::exchange::2010::local::mode::mapimailbox;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::common::powershell::exchange::2010::mapimailbox;
|
||||
|
||||
my %threshold = ('warning_mapi' => 'warning', 'critical_mapi' => 'critical');
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"no-ps" => { name => 'no_ps', },
|
||||
"timeout:s" => { name => 'timeout', default => 50 },
|
||||
"command:s" => { name => 'command', default => 'powershell.exe' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
|
||||
"ps-exec-only" => { name => 'ps_exec_only', },
|
||||
"warning-mapi:s" => { name => 'warning_mapi', },
|
||||
"critical-mapi:s" => { name => 'critical_mapi', },
|
||||
"mailbox:s" => { name => 'mailbox', },
|
||||
});
|
||||
$self->{thresholds} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{mailbox}) || $self->{option_results}->{mailbox} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify '--mailbox' option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
foreach my $th (keys %threshold) {
|
||||
next if (!defined($self->{option_results}->{$th}));
|
||||
if ($self->{option_results}->{$th} !~ /^(\!=|=){0,1}(.*){0,1}/) {
|
||||
$th =~ s/_/-/;
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong threshold for option '--" . $th . "': " . $self->{option_results}->{$th});
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $operator = defined($1) && $1 ne '' ? $1 : '!=';
|
||||
my $state = defined($2) && $2 ne '' ? $2 : 'Success';
|
||||
$self->{thresholds}->{$th} = { state => $state, operator => $operator, out => $threshold{$th} };
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $ps = centreon::common::powershell::exchange::2010::mapimailbox::get_powershell(mailbox => $self->{option_results}->{mailbox},
|
||||
no_ps => $self->{option_results}->{no_ps},
|
||||
);
|
||||
$self->{option_results}->{command_options} .= " " . $ps . " 2>&1";
|
||||
my $stdout = centreon::plugins::misc::windows_execute(output => $self->{output},
|
||||
timeout => $self->{option_results}->{timeout},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options});
|
||||
if (defined($self->{option_results}->{ps_exec_only})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => $stdout);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
centreon::common::powershell::exchange::2010::mapimailbox::check($self, stdout => $stdout, mailbox => $self->{option_results}->{mailbox});
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check mapi connection to a mailbox.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Set timeout time for command execution (Default: 50 sec)
|
||||
|
||||
=item B<--no-ps>
|
||||
|
||||
Don't encode powershell. To be used with --command and 'type' command.
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Command to get information (Default: 'powershell.exe').
|
||||
Can be changed if you have output in a file. To be used with --no-ps option!!!
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: none).
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
|
||||
|
||||
=item B<--ps-exec-only>
|
||||
|
||||
Print powershell output.
|
||||
|
||||
=item B<--warning-mapi>
|
||||
|
||||
Warning threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--critical-mapi>
|
||||
|
||||
Critical threshold
|
||||
(If set without value, it's: "!=Success". Need to change if your not US language.
|
||||
Regexp can be used)
|
||||
|
||||
=item B<--mailbox>
|
||||
|
||||
Set the mailbox to check (Required).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,68 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::exchange::2010::local::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
# $options->{options} = options object
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'activesync-mailbox' => 'apps::exchange::2010::local::mode::activesyncmailbox',
|
||||
'databases' => 'apps::exchange::2010::local::mode::databases',
|
||||
'imap-mailbox' => 'apps::exchange::2010::local::mode::imapmailbox',
|
||||
'mapi-mailbox' => 'apps::exchange::2010::local::mode::mapimailbox',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Windows Exchange 2010 locally.
|
||||
!!! Experimental system !!!
|
||||
|
||||
=cut
|
|
@ -106,8 +106,11 @@ sub manage_selection {
|
|||
while ($line =~ /\|([^|]+)\|([^|]+)\|([^|]+)\|(C|F)\|/g) {
|
||||
my ($drive, $serial, $temperature, $unit) = ($1, $2, $3, $4);
|
||||
|
||||
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$drive !~ /$self->{option_results}->{filter_name}/);
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$drive !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping drive '" . $drive . "': no matching filter name");
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{result}->{$drive} = {serial => $serial, temperature => $temperature, unit => $unit};
|
||||
}
|
||||
|
@ -117,17 +120,13 @@ sub run {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
my $drive_display = '';
|
||||
my $drive_display_append = '';
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$drive_display .= $drive_display_append . 'name = ' . $name . ' [temperature = ' . $self->{result}->{$name}->{temperature} . $self->{result}->{$name}->{unit} . ']';
|
||||
$drive_display_append = ', ';
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [temperature = " . $self->{result}->{$name}->{temperature} . $self->{result}->{$name}->{unit} . ']');
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List Drives: ' . $drive_display);
|
||||
$self->{output}->display(nolabel => 1);
|
||||
short_msg => 'List Drives:');
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -87,11 +87,18 @@ sub manage_selection {
|
|||
my $state = $obj->GetState();
|
||||
|
||||
if (defined($self->{option_results}->{filter_state}) && $state_map{$state} !~ /$self->{option_results}->{filter_state}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping application pool '" . $name . "': no matching filter state");
|
||||
next;
|
||||
}
|
||||
|
||||
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && $name ne $self->{option_results}->{name});
|
||||
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && $name !~ /$self->{option_results}->{name}/);
|
||||
if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && $name ne $self->{option_results}->{name}) {
|
||||
$self->{output}->output_add(long_msg => "Skipping application pool '" . $name . "': no matching filter name");
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && $name !~ /$self->{option_results}->{name}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping application pool '" . $name . "': no matching filter name (regexp)");
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{result}->{$name} = {AutoStart => $auto_start, State => $state};
|
||||
}
|
||||
|
@ -101,19 +108,15 @@ sub run {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
my $pools_display = '';
|
||||
my $pools_display_append = '';
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$pools_display .= $pools_display_append . 'name = ' . $name .
|
||||
' [AutoStart = ' . $self->{result}->{$name}->{AutoStart} . ', ' .
|
||||
'State = ' . $state_map{$self->{result}->{$name}->{State}} .
|
||||
']';
|
||||
$pools_display_append = ', ';
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [AutoStart = " . $self->{result}->{$name}->{AutoStart} . '] [' .
|
||||
'State = ' . $state_map{$self->{result}->{$name}->{State}} .
|
||||
']');
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List application pools: ' . $pools_display);
|
||||
$self->{output}->display(nolabel => 1);
|
||||
short_msg => 'List application pools:');
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -87,11 +87,18 @@ sub manage_selection {
|
|||
my $state = $obj->GetState();
|
||||
|
||||
if (defined($self->{option_results}->{filter_state}) && $state_map{$state} !~ /$self->{option_results}->{filter_state}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping site '" . $name . "': no matching filter state");
|
||||
next;
|
||||
}
|
||||
|
||||
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && $name ne $self->{option_results}->{name});
|
||||
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && $name !~ /$self->{option_results}->{name}/);
|
||||
if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && $name ne $self->{option_results}->{name}) {
|
||||
$self->{output}->output_add(long_msg => "Skipping site '" . $name . "': no matching filter name");
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && $name !~ /$self->{option_results}->{name}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping site '" . $name . "': no matching filter name (regexp)");
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{result}->{$name} = {AutoStart => $auto_start, State => $state};
|
||||
}
|
||||
|
@ -101,19 +108,15 @@ sub run {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
my $sites_display = '';
|
||||
my $sites_display_append = '';
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$sites_display .= $sites_display_append . 'name = ' . $name .
|
||||
' [AutoStart = ' . $self->{result}->{$name}->{AutoStart} . ', ' .
|
||||
'State = ' . $state_map{$self->{result}->{$name}->{State}} .
|
||||
']';
|
||||
$sites_display_append = ', ';
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [AutoStart = " . $self->{result}->{$name}->{AutoStart} . '] [' .
|
||||
'State = ' . $state_map{$self->{result}->{$name}->{State}} .
|
||||
']');
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List sites: ' . $sites_display);
|
||||
$self->{output}->display(nolabel => 1);
|
||||
short_msg => 'List sites:');
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ sub manage_selection {
|
|||
# AppPoolState -> 1=started, 2=starting, 3 = stopped, 4=stopping
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
if (defined($self->{option_results}->{filter_state}) && $state_map{$self->{result}->{$name}->{AppPoolState}} !~ /$self->{option_results}->{filter_state}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping application pool '" . $name . "': no matching filter state");
|
||||
delete $self->{result}->{$name};
|
||||
next;
|
||||
}
|
||||
|
@ -89,6 +90,7 @@ sub manage_selection {
|
|||
next if (!defined($self->{option_results}->{use_regexp}) && $name eq $self->{option_results}->{name});
|
||||
next if (defined($self->{option_results}->{use_regexp}) && $name =~ /$self->{option_results}->{name}/);
|
||||
|
||||
$self->{output}->output_add(long_msg => "Skipping application pool '" . $name . "': no matching filter name");
|
||||
delete $self->{result}->{$name};
|
||||
}
|
||||
}
|
||||
|
@ -99,19 +101,15 @@ sub run {
|
|||
$self->{wsman} = $options{wsman};
|
||||
|
||||
$self->manage_selection();
|
||||
my $pools_display = '';
|
||||
my $pools_display_append = '';
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$pools_display .= $pools_display_append . 'name = ' . $name .
|
||||
' [AutoStart = ' . $self->{result}->{$name}->{AppPoolAutoStart} . ',' .
|
||||
'State = ' . $state_map{$self->{result}->{$name}->{AppPoolState}} .
|
||||
']';
|
||||
$pools_display_append = ', ';
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [AutoStart = " . $self->{result}->{$name}->{AppPoolAutoStart} . '] [' .
|
||||
'State = ' . $state_map{$self->{result}->{$name}->{AppPoolState}} .
|
||||
']');
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List application pools: ' . $pools_display);
|
||||
$self->{output}->display(nolabel => 1);
|
||||
short_msg => 'List application pools:');
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,195 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::lmsensors::mode::fan;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.3.1.2'; # fan entry description
|
||||
my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.3.1.3'; # fan entry value (RPM)
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"name" => { name => 'use_name' },
|
||||
"sensor:s" => { name => 'sensor' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
});
|
||||
|
||||
$self->{Sensor_id_selected} = [];
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
$self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
|
||||
my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All Fans are ok.');
|
||||
}
|
||||
|
||||
foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
|
||||
my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
|
||||
my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId};
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Sensor '%s' Fan: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Sensor '%s' Fan: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
}
|
||||
|
||||
my $label = 'sensor_fan';
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label,
|
||||
value => $SensorValue,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
my $SensorId = $1;
|
||||
my $SensorDesc = $result->{$key};
|
||||
|
||||
next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorId !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/);
|
||||
next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc ne $self->{option_results}->{sensor});
|
||||
|
||||
|
||||
push @{$self->{Sensor_id_selected}}, $SensorId;
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
|
||||
if (defined($self->{option_results}->{sensor})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found.");
|
||||
};
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check LM-Sensors: Fan Sensors
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning (Fan Speed, U/min)
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical (Fan Speed, U/min)
|
||||
|
||||
=item B<--sensor>
|
||||
|
||||
Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter sensordesc (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,195 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::lmsensors::mode::misc;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.5.1.2'; # misc entry description
|
||||
my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.5.1.3'; # misc entry value
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"name" => { name => 'use_name' },
|
||||
"sensor:s" => { name => 'sensor' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
});
|
||||
|
||||
$self->{Sensor_id_selected} = [];
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
$self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
|
||||
my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All Sensors are ok.');
|
||||
}
|
||||
|
||||
foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
|
||||
my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
|
||||
my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId};
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Sensor '%s': %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Sensor '%s': %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
}
|
||||
|
||||
my $label = 'sensor_misc';
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label,
|
||||
value => $SensorValue,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
my $SensorId = $1;
|
||||
my $SensorDesc = $result->{$key};
|
||||
|
||||
next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorId !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/);
|
||||
next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc ne $self->{option_results}->{sensor});
|
||||
|
||||
|
||||
push @{$self->{Sensor_id_selected}}, $SensorId;
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
|
||||
if (defined($self->{option_results}->{sensor})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found.");
|
||||
};
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check LM-Sensors: Misc Sensors
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical
|
||||
|
||||
=item B<--sensor>
|
||||
|
||||
Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter sensordesc (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,195 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::lmsensors::mode::temperature;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.2.1.2'; # temperature entry description
|
||||
my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.2.1.3'; # temperature entry value (RPM)
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"name" => { name => 'use_name' },
|
||||
"sensor:s" => { name => 'sensor' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
});
|
||||
|
||||
$self->{Sensor_id_selected} = [];
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
$self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
|
||||
my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All Temperatures are ok.');
|
||||
}
|
||||
|
||||
foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
|
||||
my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
|
||||
my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId} / 1000;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Sensor '%s' Temperature: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Sensor '%s' Temperature: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
}
|
||||
|
||||
my $label = 'sensor_temperature';
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label,
|
||||
value => $SensorValue,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
my $SensorId = $1;
|
||||
my $SensorDesc = $result->{$key};
|
||||
|
||||
next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorId !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/);
|
||||
next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc ne $self->{option_results}->{sensor});
|
||||
|
||||
|
||||
push @{$self->{Sensor_id_selected}}, $SensorId;
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
|
||||
if (defined($self->{option_results}->{sensor})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found.");
|
||||
};
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check LM-Sensors: Temperature Sensors
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical
|
||||
|
||||
=item B<--sensor>
|
||||
|
||||
Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter sensordesc (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,195 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::lmsensors::mode::voltage;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
my $oid_SensorDesc = '.1.3.6.1.4.1.2021.13.16.4.1.2'; # voltage entry description
|
||||
my $oid_SensorValue = '.1.3.6.1.4.1.2021.13.16.4.1.3'; # voltage entry value (mV)
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"name" => { name => 'use_name' },
|
||||
"sensor:s" => { name => 'sensor' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
});
|
||||
|
||||
$self->{Sensor_id_selected} = [];
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
$self->{snmp}->load(oids => [$oid_SensorDesc, $oid_SensorValue], instances => $self->{Sensor_id_selected});
|
||||
my $SensorValueResult = $self->{snmp}->get_leef(nothing_quit => 1);
|
||||
|
||||
if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All Voltages are ok.');
|
||||
}
|
||||
|
||||
foreach my $SensorId (sort @{$self->{Sensor_id_selected}}) {
|
||||
my $SensorDesc = $SensorValueResult->{$oid_SensorDesc . '.' . $SensorId};
|
||||
my $SensorValue = $SensorValueResult->{$oid_SensorValue . '.' . $SensorId} / 1000;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $SensorValue, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Sensor '%s' Volt: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Sensor '%s' Volt: %s",
|
||||
$SensorDesc, $SensorValue));
|
||||
}
|
||||
|
||||
my $label = 'sensor_voltage';
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $SensorDesc if (!defined($self->{option_results}->{sensor}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => $label . $extra_label, unit => 'V',
|
||||
value => $SensorValue,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_SensorDesc, nothing_quit => 1);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
my $SensorId = $1;
|
||||
my $SensorDesc = $result->{$key};
|
||||
|
||||
next if (defined($self->{option_results}->{sensor}) && !defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorId !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/i);
|
||||
next if (defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc !~ /$self->{option_results}->{sensor}/);
|
||||
next if (defined($self->{option_results}->{use_name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $SensorDesc ne $self->{option_results}->{sensor});
|
||||
|
||||
|
||||
push @{$self->{Sensor_id_selected}}, $SensorId;
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{Sensor_id_selected}}) <= 0) {
|
||||
if (defined($self->{option_results}->{sensor})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found for '" . $self->{option_results}->{sensor} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No Sensors found.");
|
||||
};
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check LM-Sensors: Voltage Sensors
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning (Volt)
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical (Volt)
|
||||
|
||||
=item B<--sensor>
|
||||
|
||||
Set the Sensor Desc (number expected) ex: 1, 2,... (empty means 'check all sensors').
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows to use Sensor Desc name with option --sensor instead of Sensor Desc oid index.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter sensordesc (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,67 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::lmsensors::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_snmp);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
# $options->{options} = options object
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'temperature' => 'apps::lmsensors::mode::temperature',
|
||||
'fan' => 'apps::lmsensors::mode::fan',
|
||||
'voltage' => 'apps::lmsensors::mode::voltage',
|
||||
'misc' => 'apps::lmsensors::mode::misc',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check with SNMP LM-Sensors Status
|
||||
|
||||
=cut
|
|
@ -112,19 +112,15 @@ sub run {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
my $pools_display = '';
|
||||
my $pools_display_append = '';
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$pools_display .= $pools_display_append . 'name = ' . $name .
|
||||
' [AutoStart = ' . $self->{result}->{$name}->{AutoStart} . ', ' .
|
||||
'State = ' . $state_map{$self->{result}->{$name}->{State}} .
|
||||
']';
|
||||
$pools_display_append = ', ';
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [AutoStart = " . $self->{result}->{$name}->{AutoStart} . ', ' .
|
||||
'State = ' . $state_map{$self->{result}->{$name}->{State}} .
|
||||
']');
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List application pools: ' . $pools_display);
|
||||
$self->{output}->display(nolabel => 1);
|
||||
short_msg => 'List application pools:');
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -60,5 +60,6 @@ __END__
|
|||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Windows Microsoft Message Queuing locally.
|
||||
!!! Don't use it. Work on it (try to understand MSMQ :) !!!
|
||||
|
||||
=cut
|
||||
|
|
|
@ -0,0 +1,191 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package apps::nginx::serverstatus::mode::connections;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
my $maps = [
|
||||
{ counter => 'active', output => 'Active connections %d', match => 'Active connections:\s*(\d+)' },
|
||||
{ counter => 'reading', output => 'Reading connections %d', match => 'Reading:\s*(\d+)' },
|
||||
{ counter => 'writing', output => 'Writing connections %d', match => 'Writing:\s*(\d+)' },
|
||||
{ counter => 'waiting', output => 'Waiting connections %d', match => 'Waiting:\s*(\d+)' },
|
||||
];
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/nginx_status" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
foreach (@{$maps}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
'warning-' . $_->{counter} . ':s' => { name => 'warning_' . $_->{counter} },
|
||||
'critical-' . $_->{counter} . ':s' => { name => 'critical_' . $_->{counter} },
|
||||
});
|
||||
}
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (@{$maps}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-' . $_->{counter}, value => $self->{option_results}->{'warning_' . $_->{counter}})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-" . $_->{counter} . " threshold '" . $self->{option_results}->{'warning_' . $_->{counter}} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-' . $_->{counter}, value => $self->{option_results}->{'critical_' . $_->{counter}})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-" . $_->{counter} . " threshold '" . $self->{option_results}->{'critical_' . $_->{counter}} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
foreach (@{$maps}) {
|
||||
if ($webcontent !~ /$_->{match}/msi) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Cannot find " . $_->{counter} . " connections.");
|
||||
next;
|
||||
}
|
||||
my $value = $1;
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical-' . $_->{counter}, 'exit_litteral' => 'critical' }, { label => 'warning-' . $_->{counter}, 'exit_litteral' => 'warning' }]);
|
||||
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf($_->{output}, $value));
|
||||
|
||||
$self->{output}->perfdata_add(label => $_->{counter},
|
||||
value => $value,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter}),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_->{counter}),
|
||||
min => 0);
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check current connections: active, reading, writing, waiting.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Protocol to use http or https, http is default
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/nginx_status')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold. Can be: 'active', 'waiting', 'writing', 'reading'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold. Can be: 'active', 'waiting', 'writing', 'reading'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,236 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package apps::nginx::serverstatus::mode::requests;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
my $maps = [
|
||||
{ counter => 'accepts', output => 'Connections accepted per seconds %.2f', match => 'server accepts handled requests.*?(\d+)' },
|
||||
{ counter => 'handled', output => 'Connections handled per serconds %.2f', match => 'server accepts handled requests.*?\d+\s+(\d+)' },
|
||||
{ counter => 'requests', output => 'Requests per seconds %.2f', match => 'server accepts handled requests.*?\d+\s+\d+\s+(\d+)' },
|
||||
];
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/nginx_status" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
foreach (@{$maps}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
'warning-' . $_->{counter} . ':s' => { name => 'warning_' . $_->{counter} },
|
||||
'critical-' . $_->{counter} . ':s' => { name => 'critical_' . $_->{counter} },
|
||||
});
|
||||
}
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (@{$maps}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-' . $_->{counter}, value => $self->{option_results}->{'warning_' . $_->{counter}})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-" . $_->{counter} . " threshold '" . $self->{option_results}->{'warning_' . $_->{counter}} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-' . $_->{counter}, value => $self->{option_results}->{'critical_' . $_->{counter}})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-" . $_->{counter} . " threshold '" . $self->{option_results}->{'critical_' . $_->{counter}} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my ($buffer_creation, $exit) = (0, 0);
|
||||
my $new_datas = {};
|
||||
my $old_datas = {};
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'nginx_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode});
|
||||
$old_datas->{timestamp} = $self->{statefile_value}->get(name => 'timestamp');
|
||||
$new_datas->{timestamp} = time();
|
||||
foreach (@{$maps}) {
|
||||
if ($webcontent !~ /$_->{match}/msi) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Cannot find " . $_->{counter} . " information.");
|
||||
next;
|
||||
}
|
||||
|
||||
$new_datas->{$_->{counter}} = $1;
|
||||
my $tmp_value = $self->{statefile_value}->get(name => $_->{counter});
|
||||
if (!defined($tmp_value)) {
|
||||
$buffer_creation = 1;
|
||||
next;
|
||||
}
|
||||
if ($new_datas->{$_->{counter}} < $tmp_value) {
|
||||
$buffer_creation = 1;
|
||||
next;
|
||||
}
|
||||
|
||||
$exit = 1;
|
||||
$old_datas->{$_->{counter}} = $tmp_value;
|
||||
}
|
||||
|
||||
$self->{statefile_value}->write(data => $new_datas);
|
||||
if ($buffer_creation == 1) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
if ($exit == 0) {
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (@{$maps}) {
|
||||
# In buffer creation.
|
||||
next if (!defined($old_datas->{$_->{counter}}));
|
||||
if ($new_datas->{$_->{counter}} - $old_datas->{$_->{counter}} == 0) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Counter '" . $_->{counter} . "' not moved. Have to wait.");
|
||||
next;
|
||||
}
|
||||
|
||||
my $delta_time = $new_datas->{timestamp} - $old_datas->{timestamp};
|
||||
$delta_time = 1 if ($delta_time <= 0);
|
||||
|
||||
my $value = ($new_datas->{$_->{counter}} - $old_datas->{$_->{counter}}) / $delta_time;
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical-' . $_->{counter}, 'exit_litteral' => 'critical' }, { label => 'warning-' . $_->{counter}, 'exit_litteral' => 'warning' }]);
|
||||
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf($_->{output}, $value));
|
||||
|
||||
$self->{output}->perfdata_add(label => $_->{counter},
|
||||
value => sprintf('%.2f', $value),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter}),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_->{counter}),
|
||||
min => 0);
|
||||
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Nginx Request statistics: number of accepted connections per seconds, number of handled connections per seconds, number of requests per seconds.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/nginx_status')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold. Can be: 'accepts', 'handled', 'requests'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold. Can be: 'accepts', 'handled', 'requests'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,175 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package apps::nginx::serverstatus::mode::responsetime;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/nginx_status" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $timing0 = [gettimeofday];
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self, connection_exit => 'critical');
|
||||
|
||||
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||
|
||||
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,
|
||||
short_msg => sprintf("Response time %fs ", $timeelapsed));
|
||||
$self->{output}->perfdata_add(label => "time",
|
||||
value => $timeelapsed,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Nginx WebServer statistics informations
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/nginx_status')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in seconds (nginx_status page response time)
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in seconds (nginx_status page response time)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,66 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::nginx::serverstatus::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
# $options->{options} = options object
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'connections' => 'apps::nginx::serverstatus::mode::connections',
|
||||
'responsetime' => 'apps::nginx::serverstatus::mode::responsetime',
|
||||
'requests' => 'apps::nginx::serverstatus::mode::requests',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Nginx Web Servers through HttpStubStatusModule Module
|
||||
|
||||
=cut
|
|
@ -0,0 +1,304 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::pfsense::snmp::mode::blockedpackets;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $oid_pfsenseInterfaceName = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.2';
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning-in:s" => { name => 'warning_in', },
|
||||
"warning-out:s" => { name => 'warning_out', },
|
||||
"critical-in:s" => { name => 'critical_in', },
|
||||
"critical-out:s" => { name => 'critical_out', },
|
||||
"name" => { name => 'use_name' },
|
||||
"interface:s" => { name => 'interface' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
});
|
||||
|
||||
$self->{interface_id_selected} = [];
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning in threshold '" . $self->{option_results}->{warning_in} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-out', value => $self->{option_results}->{warning_out})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning out threshold '" . $self->{option_results}->{warning_out} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-in', value => $self->{option_results}->{critical_in})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical in threshold '" . $self->{option_results}->{critical_in} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-out', value => $self->{option_results}->{critical_out})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical out threshold '" . $self->{option_results}->{critical_out} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
if ($self->{snmp}->is_snmpv1()) {
|
||||
$self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
my $oid_pfsenseBlockedInPackets = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.12';
|
||||
my $oid_pfsenseBlockedOutPackets = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.14';
|
||||
my ($result, $valueIn, $valueOut);
|
||||
|
||||
my $new_datas = {};
|
||||
$self->{statefile_value}->read(statefile => "pfsense_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{interface}) ? md5_hex($self->{option_results}->{interface}) : md5_hex('all')));
|
||||
|
||||
$self->{snmp}->load(oids => [$oid_pfsenseBlockedInPackets, $oid_pfsenseBlockedOutPackets],
|
||||
instances => $self->{interface_id_selected});
|
||||
$result = $self->{snmp}->get_leef();
|
||||
|
||||
$new_datas->{last_timestamp} = time();
|
||||
my $old_timestamp;
|
||||
if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All interfaces are ok.');
|
||||
}
|
||||
|
||||
foreach (sort @{$self->{interface_id_selected}}) {
|
||||
my $display_value = $self->{names}->{$_};
|
||||
|
||||
#################
|
||||
# New values
|
||||
#################
|
||||
$new_datas->{'in_blocked_' . $_} = $result->{$oid_pfsenseBlockedInPackets . "." . $_};
|
||||
$new_datas->{'out_blocked_' . $_} = $result->{$oid_pfsenseBlockedOutPackets . "." . $_};
|
||||
|
||||
################
|
||||
# Old values
|
||||
################
|
||||
my @getting = ('in_blocked', 'out_blocked');
|
||||
my $old_datas = {};
|
||||
$old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
foreach my $key (@getting) {
|
||||
$old_datas->{$key} = $self->{statefile_value}->get(name => $key . '_' . $_);
|
||||
if (!defined($old_datas->{$key}) || $new_datas->{$key . '_' . $_} < $old_datas->{$key}) {
|
||||
# We set 0. Has reboot.
|
||||
$old_datas->{$key} = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined($old_timestamp)) {
|
||||
next;
|
||||
}
|
||||
my $time_delta = $new_datas->{last_timestamp} - $old_timestamp;
|
||||
if ($time_delta <= 0) {
|
||||
# At least one second. two fast calls ;)
|
||||
$time_delta = 1;
|
||||
}
|
||||
|
||||
###########
|
||||
|
||||
my $in_blocked_absolute = $new_datas->{'in_blocked_' . $_} - $old_datas->{in_blocked};
|
||||
my $out_blocked_absolute = $new_datas->{'out_blocked_' . $_} - $old_datas->{out_blocked};
|
||||
my $in_blocked_absolute_per_sec = $in_blocked_absolute / $time_delta;
|
||||
my $out_blocked_absolute_per_sec = $out_blocked_absolute / $time_delta;
|
||||
|
||||
###############
|
||||
# Manage Output
|
||||
###############
|
||||
|
||||
my $exit1 = $self->{perfdata}->threshold_check(value => $in_blocked_absolute_per_sec, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
|
||||
my $exit2 = $self->{perfdata}->threshold_check(value => $out_blocked_absolute_per_sec, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
|
||||
$self->{output}->output_add(long_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s [%i packets], Out Blocked : %.2f /s [%i packets]", $display_value,
|
||||
$in_blocked_absolute_per_sec, $in_blocked_absolute,
|
||||
$out_blocked_absolute_per_sec, $out_blocked_absolute));
|
||||
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s [%i packets], Out Blocked : %.2f /s [%i packets]", $display_value,
|
||||
$in_blocked_absolute_per_sec, $in_blocked_absolute,
|
||||
$out_blocked_absolute_per_sec, $out_blocked_absolute));
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $display_value if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => 'packets_blocked_in_per_sec' . $extra_label,
|
||||
value => sprintf("%.2f", $in_blocked_absolute_per_sec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in'),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => 'packets_blocked_out_per_sec' . $extra_label,
|
||||
value => sprintf("%.2f", $out_blocked_absolute_per_sec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out'),
|
||||
min => 0);
|
||||
|
||||
}
|
||||
|
||||
$self->{statefile_value}->write(data => $new_datas);
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$all_ids = [];
|
||||
$self->{names} = {};
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_pfsenseInterfaceName, nothing_quit => 1);
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /\.([0-9]+)$/);
|
||||
push @{$all_ids}, $1;
|
||||
$self->{names}->{$1} = $self->{output}->to_utf8($result->{$key});
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) {
|
||||
# get by ID
|
||||
push @{$self->{interface_id_selected}}, $self->{option_results}->{interface};
|
||||
if (!defined($self->{names}->{$self->{option_results}->{interface}})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No interface found for id '" . $self->{option_results}->{interface} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
} else {
|
||||
foreach my $i (@{$all_ids}) {
|
||||
my $filter_name = $self->{names}->{$i};
|
||||
next if (!defined($filter_name));
|
||||
if (!defined($self->{option_results}->{interface})) {
|
||||
push @{$self->{interface_id_selected}}, $i;
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/i) {
|
||||
push @{$self->{interface_id_selected}}, $i;
|
||||
}
|
||||
if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/) {
|
||||
push @{$self->{interface_id_selected}}, $i;
|
||||
}
|
||||
if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{interface}) {
|
||||
push @{$self->{interface_id_selected}}, $i;
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{interface_id_selected}}) <= 0) {
|
||||
if (defined($self->{option_results}->{interface})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No interface found for name '" . $self->{option_results}->{interface} . "' (maybe you should reload cache file).");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No interface found (maybe you should reload cache file).");
|
||||
}
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check pfSense blocked packets.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-in>
|
||||
|
||||
Threshold warning for input blocked packets.
|
||||
|
||||
=item B<--warning-out>
|
||||
|
||||
Threshold warning for output blocked packets.
|
||||
|
||||
=item B<--critical-in>
|
||||
|
||||
Threshold critical for input blocked packets.
|
||||
|
||||
=item B<--critical-out>
|
||||
|
||||
Threshold critical for output blocked packets.
|
||||
|
||||
=item B<--interface>
|
||||
|
||||
Set the interface (number expected) ex: 1, 2,... (empty means 'check all interface').
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Allows to use interface name with option --interface instead of interface oid index.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter interfaces (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,146 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::pfsense::snmp::mode::memorydroppedpackets;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
});
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
$self->{hostname} = $self->{snmp}->get_hostname();
|
||||
$self->{snmp_port} = $self->{snmp}->get_port();
|
||||
|
||||
my $oid_pfsenseMemDropPackets = '.1.3.6.1.4.1.12325.1.200.1.2.6.0';
|
||||
my ($result, $value);
|
||||
|
||||
$result = $self->{snmp}->get_leef(oids => [ $oid_pfsenseMemDropPackets ], nothing_quit => 1);
|
||||
$value = $result->{$oid_pfsenseMemDropPackets};
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'pfsense_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode});
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
my $old_memDropPackets = $self->{statefile_value}->get(name => 'memDropPackets');
|
||||
|
||||
my $new_datas = {};
|
||||
$new_datas->{last_timestamp} = time();
|
||||
$new_datas->{memDropPackets} = $value;
|
||||
|
||||
$self->{statefile_value}->write(data => $new_datas);
|
||||
if (!defined($old_timestamp) || !defined($old_memDropPackets)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
$old_memDropPackets = 0 if ($old_memDropPackets > $new_datas->{memDropPackets});
|
||||
my $delta_time = $new_datas->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0);
|
||||
|
||||
my $memDropPacketsPerSec = ($new_datas->{memDropPackets} - $old_memDropPackets) / $delta_time;
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $memDropPacketsPerSec,
|
||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->perfdata_add(label => 'dropped_packets_Per_Sec',
|
||||
value => sprintf("%.2f", $memDropPacketsPerSec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("Dropped packets due to memory limitations : %.2f /s",
|
||||
$memDropPacketsPerSec));
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check number of packets per second dropped due to memory limitations.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning for dropped packets in packets per second.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical for dropped packets in packets per second.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,137 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::pfsense::snmp::mode::runtime;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use POSIX;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
"seconds" => { name => 'seconds', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
my $oid_pfsenseStatus = '.1.3.6.1.4.1.12325.1.200.1.1.1.0';
|
||||
my $oid_pfsenseRuntime = '.1.3.6.1.4.1.12325.1.200.1.1.2.0';
|
||||
my ($result, $valueStatus, $valueRuntime);
|
||||
|
||||
$result = $self->{snmp}->get_leef(oids => [ $oid_pfsenseStatus, $oid_pfsenseRuntime ], nothing_quit => 1);
|
||||
$valueStatus = $result->{$oid_pfsenseStatus};
|
||||
$valueRuntime = $result->{$oid_pfsenseRuntime};
|
||||
|
||||
if ($valueStatus == 1) {
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $valueRuntime,
|
||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->perfdata_add(label => 'runtime',
|
||||
value => floor($valueRuntime / 100),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("PfSense running since : %s",
|
||||
defined($self->{option_results}->{seconds}) ? floor($valueRuntime / 100) . " seconds" : floor($valueRuntime / 86400 / 100) . " days" ));
|
||||
|
||||
} else {
|
||||
$self->{output}->perfdata_add(label => 'runtime',
|
||||
value => 0,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
$self->{output}->output_add(severity => 'critical',
|
||||
short_msg => sprintf("PfSense not running."));
|
||||
|
||||
}
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check pfSense runtime.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in seconds.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in seconds.
|
||||
|
||||
=item B<--seconds>
|
||||
|
||||
Display runtime in seconds.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,66 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::pfsense::snmp::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_snmp);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
# $options->{options} = options object
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'runtime' => 'apps::pfsense::snmp::mode::runtime',
|
||||
'memory-dropped-packets' => 'apps::pfsense::snmp::mode::memorydroppedpackets',
|
||||
'blocked-packets' => 'apps::pfsense::snmp::mode::blockedpackets',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check pfSense in SNMP.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,189 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package apps::protocols::http::mode::expectedcontent;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"ntlm" => { name => 'ntlm' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"expected-string:s" => { name => 'expected_string' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-bytes', value => $self->{option_results}->{warning_bytes})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-bytes threshold '" . $self->{option_results}->{warning_bytes} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-bytes', value => $self->{option_results}->{critical_bytes})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-bytes threshold '" . $self->{option_results}->{critical_bytes} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-access', value => $self->{option_results}->{warning_access})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-access threshold '" . $self->{option_results}->{warning_access} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-access', value => $self->{option_results}->{critical_access})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_access} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to specify hostname.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{expected_string})) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to specify --expected-string option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$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}->{credentials})) && (defined($self->{option_results}->{ntlm}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "--ntlm option must be used with --credentials option");
|
||||
$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);
|
||||
}
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
$self->{output}->output_add(long_msg => $webcontent);
|
||||
|
||||
if ($webcontent =~ /$self->{option_results}->{expected_string}/mi) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("'%s' is present in content.", $self->{option_results}->{expected_string}));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
} else {
|
||||
$self->{output}->output_add(severity => 'Critical',
|
||||
short_msg => sprintf("'%s' is not present in content.", $self->{option_results}->{expected_string}));
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Webpage content
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the Webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Webserver
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get Webpage (Default: '/')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access webpage over basic authentification
|
||||
|
||||
=item B<--ntlm>
|
||||
|
||||
Specify this option if you access webpage over ntlm authentification (Use with --credentials option)
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,186 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package apps::protocols::http::mode::responsetime;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"ntlm" => { name => 'ntlm' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials 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);
|
||||
}
|
||||
|
||||
my $timing0 = [gettimeofday];
|
||||
|
||||
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,
|
||||
short_msg => sprintf("Response time %.3fs", $timeelapsed));
|
||||
$self->{output}->perfdata_add(label => "time",
|
||||
value => sprintf('%.3f', $timeelapsed),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Webpage Time Response
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Webserver
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get webpage (Default: '/')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access webpage over basic authentification
|
||||
|
||||
=item B<--ntlm>
|
||||
|
||||
Specify this option if you access webpage over ntlm authentification (Use with --credentials option)
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in seconds (Webpage response time)
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in seconds (Webpage response time)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,65 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::protocols::http::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
# $options->{options} = options object
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'response-time' => 'apps::protocols::http::mode::responsetime',
|
||||
'expected-content' => 'apps::protocols::http::mode::expectedcontent',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check HTTP or HTTPS webpage.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,115 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::protocols::imap::lib::imap;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use Net::IMAP::Simple;
|
||||
|
||||
my $imap_handle;
|
||||
|
||||
sub quit {
|
||||
$imap_handle->quit;
|
||||
}
|
||||
|
||||
sub search {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (!defined($imap_handle->select($self->{option_results}->{folder}))) {
|
||||
my $output = $imap_handle->errstr;
|
||||
$output =~ s/\r//g;
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Folder Select Error: ' . $output);
|
||||
quit();
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @ids = $imap_handle->search($self->{option_results}->{search});
|
||||
|
||||
if (defined($self->{option_results}->{delete})) {
|
||||
foreach my $msg_num (@ids) {
|
||||
$imap_handle->delete($msg_num);
|
||||
}
|
||||
$imap_handle->expunge_mailbox();
|
||||
}
|
||||
|
||||
return scalar(@ids);
|
||||
}
|
||||
|
||||
sub connect {
|
||||
my ($self, %options) = @_;
|
||||
my %imap_options = ();
|
||||
|
||||
my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
|
||||
$imap_options{port} = $self->{option_results}->{port} if (defined($self->{option_results}->{port}));
|
||||
$imap_options{use_ssl} = 1 if (defined($self->{option_results}->{use_ssl}));
|
||||
$imap_options{timeout} = $self->{option_results}->{timeout} if (defined($self->{option_results}->{timeout}));
|
||||
|
||||
if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '' &&
|
||||
!defined($self->{option_results}->{password})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set --password option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$imap_handle = Net::IMAP::Simple->new($self->{option_results}->{hostname},
|
||||
%imap_options
|
||||
);
|
||||
|
||||
|
||||
if (!defined($imap_handle)) {
|
||||
$self->{output}->output_add(severity => $connection_exit,
|
||||
short_msg => 'Unable to connect to IMAP: ' . $Net::IMAP::Simple::errstr);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '') {
|
||||
if (!$imap_handle->login($self->{option_results}->{username}, $self->{option_results}->{password})) {
|
||||
# Exchange put '\r'...
|
||||
my $output = $imap_handle->errstr;
|
||||
$output =~ s/\r//g;
|
||||
$self->{output}->output_add(severity => $connection_exit,
|
||||
short_msg => 'Login failed: ' . $output);
|
||||
quit();
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,152 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::protocols::imap::mode::login;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
use apps::protocols::imap::lib::imap;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"ssl" => { name => 'use_ssl' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => '30' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $timing0 = [gettimeofday];
|
||||
|
||||
apps::protocols::imap::lib::imap::connect($self, connection_exit => 'critical');
|
||||
apps::protocols::imap::lib::imap::quit();
|
||||
|
||||
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
|
||||
|
||||
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,
|
||||
short_msg => sprintf("Response time %.3f ", $timeelapsed));
|
||||
$self->{output}->perfdata_add(label => "time",
|
||||
value => sprintf('%.3f', $timeelapsed),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Connection (also login) to an IMAP Server.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the imap host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used
|
||||
|
||||
=item B<--ssl>
|
||||
|
||||
Use SSL connection.
|
||||
(no attempt is made to check the certificate validity by default).
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for authentification
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for authentification
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Connection timeout in seconds (Default: 30)
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in seconds
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in seconds
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,168 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::protocols::imap::mode::searchmessage;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::protocols::imap::lib::imap;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"ssl" => { name => 'use_ssl' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => '30' },
|
||||
"search:s" => { name => 'search' },
|
||||
"delete" => { name => 'delete' },
|
||||
"folder:s" => { name => 'folder', default => 'INBOX' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the --hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{search})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the --search option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
apps::protocols::imap::lib::imap::connect($self);
|
||||
my ($num) = apps::protocols::imap::lib::imap::search($self);
|
||||
apps::protocols::imap::lib::imap::quit();
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $num,
|
||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("%d message found(s)", $num));
|
||||
$self->{output}->perfdata_add(label => "numbers",
|
||||
value => $num,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check messages in a mailbox with IMAP filter.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the imap host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used
|
||||
|
||||
=item B<--ssl>
|
||||
|
||||
Use SSL connection.
|
||||
(no attempt is made to check the certificate validity by default).
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for authentification
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for authentification
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Connection timeout in seconds (Default: 30)
|
||||
|
||||
=item B<--search>
|
||||
|
||||
Set the search string (Required)
|
||||
|
||||
=item B<--delete>
|
||||
|
||||
Delete messages found
|
||||
|
||||
=item B<--folder>
|
||||
|
||||
Set IMAP folder (Default: 'INBOX')
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning of number messages found
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical of number message found
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,64 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::protocols::imap::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
# $options->{options} = options object
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'login' => 'apps::protocols::imap::mode::login',
|
||||
'search-message' => 'apps::protocols::imap::mode::searchmessage',
|
||||
);
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check an IMAP server.
|
||||
|
||||
=cut
|
|
@ -35,13 +35,12 @@
|
|||
# Based on Apache Mode by Simon BOMM
|
||||
####################################################################################
|
||||
|
||||
package apps::tomcat::web::mode::application;
|
||||
package apps::tomcat::web::mode::applications;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::tomcat::web::mode::libconnect;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -52,15 +51,14 @@ sub new {
|
|||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '23002' },
|
||||
"port:s" => { name => 'port', default => '8080' },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"path:s" => { name => 'path', default => '/manager/text/list' },
|
||||
"realm:s" => { name => 'realm', default => 'Tomcat Manager Application' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/manager/text/list' },
|
||||
"name:s" => { name => 'name' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
|
@ -94,9 +92,9 @@ sub check_options {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = apps::tomcat::web::mode::libconnect::connect($self);
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
|
||||
while ($webcontent =~ m/\/(.*):(.*):(.*):(.*)/g) {
|
||||
while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {
|
||||
my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
|
||||
|
||||
next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' &&
|
||||
|
@ -204,17 +202,13 @@ Specify username for basic authentification (Mandatory if --credentials is speci
|
|||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--realm>
|
||||
|
||||
Credentials Realm (Default: 'Tomcat Manager Application')
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--path>
|
||||
=item B<--urlpath>
|
||||
|
||||
Path to the Tomcat Manager List (Default: '/manager/text/list')
|
||||
Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
|
||||
Tomcat 6: '/manager/list'
|
||||
Tomcat 7: '/manager/text/list'
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
# Based on Apache Mode by Simon BOMM
|
||||
####################################################################################
|
||||
|
||||
package apps::tomcat::web::mode::libconnect;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use LWP::UserAgent;
|
||||
|
||||
sub connect {
|
||||
my ($self, %options) = @_;
|
||||
my $ua = LWP::UserAgent->new( protocols_allowed => ['http','https'], timeout => $self->{option_results}->{timeout});
|
||||
my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
|
||||
|
||||
my $response;
|
||||
my $content;
|
||||
|
||||
if (defined $self->{option_results}->{credentials}) {
|
||||
#$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}->{realm},$self->{option_results}->{username},$self->{option_results}->{password});
|
||||
}
|
||||
|
||||
if ($self->{option_results}->{proto} eq "https") {
|
||||
if (defined $self->{option_results}->{proxyurl}) {
|
||||
$ua->proxy(['https'], $self->{option_results}->{proxyurl});
|
||||
$response = $ua->get('https://'.$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.$self->{option_results}->{path});
|
||||
} else {
|
||||
$response = $ua->get('https://'.$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.$self->{option_results}->{path});
|
||||
}
|
||||
} else {
|
||||
if (defined $self->{option_results}->{proxyurl}) {
|
||||
$ua->proxy(['http'], $self->{option_results}->{proxyurl});
|
||||
$response = $ua->get($self->{option_results}->{proto}."://" .$self->{option_results}->{hostname}.$self->{option_results}->{path});
|
||||
} else {
|
||||
$response = $ua->get('http://'.$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.$self->{option_results}->{path});
|
||||
}
|
||||
}
|
||||
|
||||
if ($response->is_success) {
|
||||
$content = $response->content;
|
||||
return $content;
|
||||
} else {
|
||||
$self->{output}->output_add(severity => $connection_exit,
|
||||
short_msg => $response->status_line);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -38,10 +38,9 @@
|
|||
package apps::tomcat::web::mode::listapplication;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::tomcat::web::mode::libconnect;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -52,15 +51,14 @@ sub new {
|
|||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '23002' },
|
||||
"port:s" => { name => 'port', default => '8080' },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"path:s" => { name => 'path', default => '/manager/text/list' },
|
||||
"realm:s" => { name => 'realm', default => 'Tomcat Manager Application' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/manager/text/list' },
|
||||
"filter-name:s" => { name => 'filter_name', },
|
||||
"filter-state:s" => { name => 'filter_state', },
|
||||
"filter-path:s" => { name => 'filter_path', },
|
||||
|
@ -93,17 +91,26 @@ sub check_options {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = apps::tomcat::web::mode::libconnect::connect($self);
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
|
||||
while ($webcontent =~ m/\/(.*):(.*):(.*):(.*)/g) {
|
||||
while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {
|
||||
my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
|
||||
|
||||
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$context !~ /$self->{option_results}->{filter_name}/);
|
||||
next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
|
||||
$state !~ /$self->{option_results}->{filter_state}/);
|
||||
next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' &&
|
||||
$contextpath !~ /$self->{option_results}->{filter_path}/);
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$context !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping context '" . $context . "': no matching filter name");
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
|
||||
$state !~ /$self->{option_results}->{filter_state}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping context '" . $context . "': no matching filter state");
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' &&
|
||||
$contextpath !~ /$self->{option_results}->{filter_path}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping context '" . $context . "': no matching filter path");
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{result}->{$context} = {state => $state, sessions => $sessions, contextpath => $contextpath};
|
||||
}
|
||||
|
@ -113,16 +120,13 @@ sub run {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
my $context_display = '';
|
||||
my $context_display_append = '';
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$context_display .= $context_display_append . 'name = ' . $name . ' [state = ' . $self->{result}->{$name}->{state} . ']';
|
||||
$context_display_append = ', ';
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [state = " . $self->{result}->{$name}->{state} . ']');
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List Contexts: ' . $context_display);
|
||||
$self->{output}->display(nolabel => 1);
|
||||
short_msg => 'List Contexts:');
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
|
@ -181,17 +185,13 @@ Specify username for basic authentification (Mandatory if --credentials is speci
|
|||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--realm>
|
||||
|
||||
Credentials Realm (Default: 'Tomcat Manager Application')
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--path>
|
||||
=item B<--url-path>
|
||||
|
||||
Path to the Tomcat Manager List (Default: '/manager/text/list')
|
||||
Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
|
||||
Tomcat 6: '/manager/list'
|
||||
Tomcat 7: '/manager/text/list'
|
||||
|
||||
|
|
|
@ -0,0 +1,255 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::tomcat::web::mode::memory;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use XML::XPath;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '8080' },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
$self->{hostname} = undef;
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
my %xpath_to_check = (
|
||||
memMax => '/status/jvm/memory/@max',
|
||||
memFree => '/status/jvm/memory/@free',
|
||||
memTotal => '/status/jvm/memory/@total',
|
||||
);
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my $port = $self->{option_results}->{port};
|
||||
|
||||
#EXAMPLE 1:
|
||||
#<status>
|
||||
# <connector name="http-0">
|
||||
# <threadInfo currentThreadCount="0" currentThreadsBusy="0" maxThreads="200"/>
|
||||
# <requestInfo bytesReceived="0" bytesSent="0" errorCount="0" maxTime="0" processingTime="0" requestCount="0"/>
|
||||
# <workers></workers>
|
||||
# </connector>
|
||||
# <connector name="http-8080">
|
||||
# <threadInfo currentThreadCount="158" currentThreadsBusy="10" maxThreads="200"/>
|
||||
# <requestInfo bytesReceived="297" bytesSent="19350704517" errorCount="192504" maxTime="249349" processingTime="2242513592" requestCount="983650"/>
|
||||
# <workers>
|
||||
# </workers>
|
||||
# </connector>
|
||||
#</status>
|
||||
|
||||
#EXAMPLE 2:
|
||||
#<status>
|
||||
#<jvm>
|
||||
# <memory free='409303928' total='518979584' max='518979584'/>
|
||||
# <memorypool name='Eden Space' type='Heap memory' usageInit='143130624' usageCommitted='143130624' usageMax='143130624' usageUsed='56881560'/>
|
||||
# <memorypool name='Survivor Space' type='Heap memory' usageInit='17891328' usageCommitted='17891328' usageMax='17891328' usageUsed='17891328'/>
|
||||
# <memorypool name='Tenured Gen' type='Heap memory' usageInit='357957632' usageCommitted='357957632' usageMax='357957632' usageUsed='34902768'/>
|
||||
# <memorypool name='Code Cache' type='Non-heap memory' usageInit='2555904' usageCommitted='2555904' usageMax='50331648' usageUsed='1899840'/>
|
||||
# <memorypool name='Perm Gen' type='Non-heap memory' usageInit='21757952' usageCommitted='21757952' usageMax='85983232' usageUsed='21372688'/>
|
||||
#</jvm>
|
||||
#<connector name='"http-bio-10.1.80.149-22002"'><threadInfo maxThreads="5" currentThreadCount="2" currentThreadsBusy="1" />
|
||||
# <requestInfo maxTime="1216" processingTime="1216" requestCount="1" errorCount="1" bytesReceived="0" bytesSent="2474" />
|
||||
# <workers>
|
||||
# <worker stage="S" requestProcessingTime="23" requestBytesSent="0" requestBytesReceived="0" remoteAddr="10.1.80.149" virtualHost="examplehost" method="GET" currentUri="/manager/status" currentQueryString="XML=true" protocol="HTTP/1.1" />
|
||||
# </workers>
|
||||
#</connector>
|
||||
#<connector name='"ajp-bio-10.1.80.149-22001"'><threadInfo maxThreads="150" currentThreadCount="0" currentThreadsBusy="0" />
|
||||
# <requestInfo maxTime="0" processingTime="0" requestCount="0" errorCount="0" bytesReceived="0" bytesSent="0" />
|
||||
# <workers>
|
||||
# </workers>
|
||||
#</connector>
|
||||
#</status>
|
||||
|
||||
#GET XML DATA
|
||||
my $xpath = XML::XPath->new( xml => $webcontent );
|
||||
my %xpath_check_results;
|
||||
|
||||
foreach my $xpath_check ( keys %xpath_to_check ) {
|
||||
my $singlepath = $xpath_to_check{$xpath_check};
|
||||
$singlepath =~ s{\$port}{$port};
|
||||
my $nodeset = $xpath->find($singlepath);
|
||||
|
||||
foreach my $node ($nodeset->get_nodelist) {
|
||||
my $value = $node->string_value();
|
||||
if ( $value =~ /^"?([0-9.]+)"?$/ ) {
|
||||
$self->{result}->{$xpath_check} = $1;
|
||||
} else {
|
||||
$self->{result}->{$xpath_check} = "not_numeric";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
my $memTotal = $self->{result}->{memTotal};
|
||||
my $memFree = $self->{result}->{memFree};
|
||||
my $memMax = $self->{result}->{memMax};
|
||||
my $memUsed = $memTotal - $memFree;
|
||||
my $memUsed_prct = $memUsed * 100 / $memTotal;
|
||||
|
||||
if (!defined($memTotal) || !defined($memFree) || !defined($memUsed) || !defined($memUsed_prct)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Some informations missing.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $memUsed_prct, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
my ($memTotal_value, $memTotal_unit) = $self->{perfdata}->change_bytes(value => $memTotal);
|
||||
my ($memFree_value, $memFree_unit) = $self->{perfdata}->change_bytes(value => $memFree);
|
||||
my ($memMax_value, $memMax_unit) = $self->{perfdata}->change_bytes(value => $memMax);
|
||||
my ($memUsed_value, $memUsed_unit) = $self->{perfdata}->change_bytes(value => $memUsed);
|
||||
|
||||
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Memory used %s (%.2f%%)",
|
||||
$memUsed_value . " " . $memUsed_unit, $memUsed_prct));
|
||||
|
||||
$self->{output}->perfdata_add(label => "used",
|
||||
value => $memUsed,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $memTotal),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $memTotal),
|
||||
min => 0, max => $memTotal);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Tomcat Application Servers Memory Usage
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Address or FQDN of the Tomcat Application Server
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Tomcat
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Protocol used http or https
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in percent.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in percent.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,431 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::tomcat::web::mode::requestinfo;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use XML::XPath;
|
||||
use URI::Escape;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '8080' },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
|
||||
"name:s" => { name => 'name' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
"warning-maxtime:s" => { name => 'warning_maxtime' },
|
||||
"critical-maxtime:s" => { name => 'critical_maxtime' },
|
||||
"warning-processingtime:s" => { name => 'warning_processingtime' },
|
||||
"critical-processingtime:s" => { name => 'critical_processingtime' },
|
||||
"warning-requestcount:s" => { name => 'warning_requestcount' },
|
||||
"critical-requestcount:s" => { name => 'critical_requestcount' },
|
||||
"warning-errorcount:s" => { name => 'warning_errorcount' },
|
||||
"critical-errorcount:s" => { name => 'critical_errorcount' },
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
$self->{hostname} = undef;
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
#MaxTime
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-maxtime', value => $self->{option_results}->{warning_maxtime})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-maxtime' threshold '" . $self->{option_results}->{warning_maxtime} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-maxtime', value => $self->{option_results}->{critical_maxtime})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-maxtime' threshold '" . $self->{option_results}->{critical_maxtime} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
#processingTime
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-processingtime', value => $self->{option_results}->{warning_processingtime})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-processingtime' threshold '" . $self->{option_results}->{warning_processingtime} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-processingtime', value => $self->{option_results}->{critical_processingtime})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-processingtime' threshold '" . $self->{option_results}->{critical_processingtime} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
#requestCount
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-requestcount', value => $self->{option_results}->{warning_requestcount})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-requestcount' threshold '" . $self->{option_results}->{warning_requestcount} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-requestcount', value => $self->{option_results}->{critical_requestcount})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-requestcount' threshold '" . $self->{option_results}->{critical_requestcount} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
#errorCount
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-errorcount', value => $self->{option_results}->{warning_errorcount})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning 'warning-errorcount' threshold '" . $self->{option_results}->{warning_errorcount} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-errorcount', value => $self->{option_results}->{critical_errorcount})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical 'critical-errorcount' threshold '" . $self->{option_results}->{critical_errorcount} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
$self->{hostname} = $self->{option_results}->{hostname};
|
||||
if (!defined($self->{hostname})) {
|
||||
$self->{hostname} = 'me';
|
||||
}
|
||||
}
|
||||
|
||||
my %xpath_to_check = (
|
||||
requestInfo_maxTime => '/status/connector/requestInfo/@maxTime', #
|
||||
requestInfo_processingTime => '/status/connector/requestInfo/@processingTime', #to last
|
||||
requestInfo_requestCount => '/status/connector/requestInfo/@requestCount', #to last
|
||||
requestInfo_errorCount => '/status/connector/requestInfo/@errorCount', #to last
|
||||
);
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my $port = $self->{option_results}->{port};
|
||||
|
||||
#EXAMPLE 1:
|
||||
#<status>
|
||||
# <connector name="http-0">
|
||||
# <threadInfo currentThreadCount="0" currentThreadsBusy="0" maxThreads="200"/>
|
||||
# <requestInfo bytesReceived="0" bytesSent="0" errorCount="0" maxTime="0" processingTime="0" requestCount="0"/>
|
||||
# <workers></workers>
|
||||
# </connector>
|
||||
# <connector name="http-8080">
|
||||
# <threadInfo currentThreadCount="158" currentThreadsBusy="10" maxThreads="200"/>
|
||||
# <requestInfo bytesReceived="297" bytesSent="19350704517" errorCount="192504" maxTime="249349" processingTime="2242513592" requestCount="983650"/>
|
||||
# <workers>
|
||||
# </workers>
|
||||
# </connector>
|
||||
#</status>
|
||||
|
||||
#EXAMPLE 2:
|
||||
#<status>
|
||||
#<jvm>
|
||||
# <memory free='409303928' total='518979584' max='518979584'/>
|
||||
# <memorypool name='Eden Space' type='Heap memory' usageInit='143130624' usageCommitted='143130624' usageMax='143130624' usageUsed='56881560'/>
|
||||
# <memorypool name='Survivor Space' type='Heap memory' usageInit='17891328' usageCommitted='17891328' usageMax='17891328' usageUsed='17891328'/>
|
||||
# <memorypool name='Tenured Gen' type='Heap memory' usageInit='357957632' usageCommitted='357957632' usageMax='357957632' usageUsed='34902768'/>
|
||||
# <memorypool name='Code Cache' type='Non-heap memory' usageInit='2555904' usageCommitted='2555904' usageMax='50331648' usageUsed='1899840'/>
|
||||
# <memorypool name='Perm Gen' type='Non-heap memory' usageInit='21757952' usageCommitted='21757952' usageMax='85983232' usageUsed='21372688'/>
|
||||
#</jvm>
|
||||
#<connector name='"http-bio-10.1.80.149-22002"'><threadInfo maxThreads="5" currentThreadCount="2" currentThreadsBusy="1" />
|
||||
# <requestInfo maxTime="1216" processingTime="1216" requestCount="1" errorCount="1" bytesReceived="0" bytesSent="2474" />
|
||||
# <workers>
|
||||
# <worker stage="S" requestProcessingTime="23" requestBytesSent="0" requestBytesReceived="0" remoteAddr="10.1.80.149" virtualHost="examplehost" method="GET" currentUri="/manager/status" currentQueryString="XML=true" protocol="HTTP/1.1" />
|
||||
# </workers>
|
||||
#</connector>
|
||||
#<connector name='"ajp-bio-10.1.80.149-22001"'><threadInfo maxThreads="150" currentThreadCount="0" currentThreadsBusy="0" />
|
||||
# <requestInfo maxTime="0" processingTime="0" requestCount="0" errorCount="0" bytesReceived="0" bytesSent="0" />
|
||||
# <workers>
|
||||
# </workers>
|
||||
#</connector>
|
||||
#</status>
|
||||
|
||||
#GET XML DATA
|
||||
my $xpath = XML::XPath->new( xml => $webcontent );
|
||||
my %xpath_check_results;
|
||||
|
||||
foreach my $xpath_check ( keys %xpath_to_check ) {
|
||||
my $singlepath = $xpath_to_check{$xpath_check};
|
||||
$singlepath =~ s{\$port}{$port};
|
||||
my $nodeset = $xpath->find($singlepath);
|
||||
|
||||
foreach my $node ($nodeset->get_nodelist) {
|
||||
my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
|
||||
$connector_name =~ s/^["'\s]+//;
|
||||
$connector_name =~ s/["'\s]+$//;
|
||||
$connector_name = uri_unescape($connector_name);
|
||||
|
||||
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $connector_name !~ /$self->{option_results}->{name}/i);
|
||||
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $connector_name !~ /$self->{option_results}->{name}/);
|
||||
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $connector_name ne $self->{option_results}->{name});
|
||||
|
||||
my $value = $node->string_value();
|
||||
if ( $value =~ /^"?([0-9.]+)"?$/ ) {
|
||||
$self->{result}->{$connector_name}{$xpath_check} = $1;
|
||||
} else {
|
||||
$self->{result}->{$connector_name}{$xpath_check} = "not_numeric";
|
||||
};
|
||||
};
|
||||
|
||||
if (scalar(keys %{$self->{result}}) <= 0) {
|
||||
if (defined($self->{option_results}->{name})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No information found.");
|
||||
}
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
my $new_datas = {};
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$new_datas->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All requestInfo Data are ok.');
|
||||
}
|
||||
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$new_datas->{'requestInfo_processingTime_' . $name} = $self->{result}->{$name}->{requestInfo_processingTime};
|
||||
$new_datas->{'requestInfo_requestCount_' . $name} = $self->{result}->{$name}->{requestInfo_requestCount};
|
||||
$new_datas->{'requestInfo_errorCount_' . $name} = $self->{result}->{$name}->{requestInfo_errorCount};
|
||||
|
||||
my $requestInfo_processingTime = $self->{statefile_value}->get(name => 'requestInfo_processingTime_' . $name);
|
||||
my $requestInfo_requestCount = $self->{statefile_value}->get(name => 'requestInfo_requestCount_' . $name);
|
||||
my $requestInfo_errorCount = $self->{statefile_value}->get(name => 'requestInfo_errorCount_' . $name);
|
||||
|
||||
if (!defined($old_timestamp) || !defined($requestInfo_processingTime) || !defined($requestInfo_requestCount) || !defined($requestInfo_errorCount)) {
|
||||
next;
|
||||
}
|
||||
if ($new_datas->{'requestInfo_processingTime_' . $name} < $requestInfo_processingTime) {
|
||||
# We set 0. Has reboot.
|
||||
$requestInfo_processingTime = 0;
|
||||
}
|
||||
if ($new_datas->{'requestInfo_requestCount_' . $name} < $requestInfo_requestCount) {
|
||||
# We set 0. Has reboot.
|
||||
$requestInfo_requestCount = 0;
|
||||
}
|
||||
if ($new_datas->{'requestInfo_errorCount_' . $name} < $requestInfo_errorCount) {
|
||||
# We set 0. Has reboot.
|
||||
$requestInfo_errorCount = 0;
|
||||
}
|
||||
|
||||
my $time_delta = $new_datas->{last_timestamp} - $old_timestamp;
|
||||
if ($time_delta <= 0) {
|
||||
# At least one second. two fast calls ;)
|
||||
$time_delta = 1;
|
||||
}
|
||||
|
||||
my $requestInfo_maxTime = $self->{result}->{$name}->{requestInfo_maxTime};
|
||||
|
||||
my $requestInfo_processingTime_absolute_per_sec = ($new_datas->{'requestInfo_processingTime_' . $name} - $requestInfo_processingTime) / $time_delta;
|
||||
my $requestInfo_requestCount_absolute_per_sec = ($new_datas->{'requestInfo_requestCount_' . $name} - $requestInfo_requestCount) / $time_delta;
|
||||
my $requestInfo_errorCount_absolute_per_sec = ($new_datas->{'requestInfo_errorCount_' . $name} - $requestInfo_errorCount) / $time_delta;
|
||||
|
||||
my $exit1 = $self->{perfdata}->threshold_check(value => $requestInfo_maxTime, threshold => [ { label => 'critical-maxtime', 'exit_litteral' => 'critical' }, { label => 'warning-maxtime', exit_litteral => 'warning' } ]);
|
||||
my $exit2 = $self->{perfdata}->threshold_check(value => $requestInfo_processingTime_absolute_per_sec, threshold => [ { label => 'critical-processingtime', 'exit_litteral' => 'critical' }, { label => 'warning-processingtime', exit_litteral => 'warning' } ]);
|
||||
my $exit3 = $self->{perfdata}->threshold_check(value => $requestInfo_requestCount_absolute_per_sec, threshold => [ { label => 'critical-requestcount', 'exit_litteral' => 'critical' }, { label => 'warning-requestcount', exit_litteral => 'warning' } ]);
|
||||
my $exit4 = $self->{perfdata}->threshold_check(value => $requestInfo_errorCount_absolute_per_sec, threshold => [ { label => 'critical-errorcount', 'exit_litteral' => 'critical' }, { label => 'warning-errorcount', exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4 ]);
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Connector '%s' maxTime : %s, processingTime : %.3f, requestCount : %.2f, errorCount : %.2f", $name, $requestInfo_maxTime, $requestInfo_processingTime_absolute_per_sec, $requestInfo_requestCount_absolute_per_sec, $requestInfo_errorCount_absolute_per_sec));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Connector '%s' maxTime : %s, processingTime : %.3f, requestCount : %.2f, errorCount : %.2f", $name,
|
||||
$requestInfo_maxTime,
|
||||
$requestInfo_processingTime_absolute_per_sec,
|
||||
$requestInfo_requestCount_absolute_per_sec,
|
||||
$requestInfo_errorCount_absolute_per_sec));
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => 'maxTime' . $extra_label,
|
||||
value => sprintf("%.2f", $self->{result}->{$name}->{requestInfo_maxTime}),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
|
||||
$self->{output}->perfdata_add(label => 'processingTime' . $extra_label,
|
||||
value => sprintf("%.3f", $requestInfo_processingTime_absolute_per_sec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
|
||||
$self->{output}->perfdata_add(label => 'requestCount' . $extra_label,
|
||||
value => sprintf("%.2f", $requestInfo_requestCount_absolute_per_sec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => 'errorCount' . $extra_label,
|
||||
value => sprintf("%.2f", $requestInfo_errorCount_absolute_per_sec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
};
|
||||
|
||||
$self->{statefile_value}->write(data => $new_datas);
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Tomcat Application Servers Requestinfo Threadsinformation for each Connector
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Address or FQDN of the Tomcat Application Server
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Tomcat
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Protocol used http or https
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Set the filter name (empty means 'check all contexts')
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=item B<--warning-maxtime>
|
||||
|
||||
Threshold warning for maxTime
|
||||
|
||||
=item B<--critical-maxtime>
|
||||
|
||||
Threshold critical for maxTime
|
||||
|
||||
=item B<--warning-processingtime>
|
||||
|
||||
Threshold warning for ProcessingTime
|
||||
|
||||
=item B<--critical-processingtime>
|
||||
|
||||
Threshold critical for ProcessingTime
|
||||
|
||||
=item B<--warning-requestcount>
|
||||
|
||||
Threshold warning for requestCount
|
||||
|
||||
=item B<--critical-requestcount>
|
||||
|
||||
Threshold critical for requestCount
|
||||
|
||||
=item B<--warning-errorcount>
|
||||
|
||||
Threshold warning for errorCount
|
||||
|
||||
=item B<--critical-errorcount>
|
||||
|
||||
Threshold critical for errorCount
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -38,10 +38,9 @@
|
|||
package apps::tomcat::web::mode::sessions;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use apps::tomcat::web::mode::libconnect;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -52,15 +51,14 @@ sub new {
|
|||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '23002' },
|
||||
"port:s" => { name => 'port', default => '8080' },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"path:s" => { name => 'path', default => '/manager/text/list' },
|
||||
"realm:s" => { name => 'realm', default => 'Tomcat Manager Application' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/manager/text/list' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"name:s" => { name => 'name' },
|
||||
|
@ -105,9 +103,9 @@ sub check_options {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = apps::tomcat::web::mode::libconnect::connect($self);
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
|
||||
while ($webcontent =~ m/\/(.*):(.*):(.*):(.*)/g) {
|
||||
while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) {
|
||||
my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4);
|
||||
|
||||
next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
|
||||
|
@ -127,9 +125,9 @@ sub manage_selection {
|
|||
|
||||
if (scalar(keys %{$self->{result}}) <= 0) {
|
||||
if (defined($self->{option_results}->{name})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No contexts found for name '" . $self->{option_results}->{name} . "'.");
|
||||
$self->{output}->add_option_msg(short_msg => "No session information found for name '" . $self->{option_results}->{name} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No contexts found.");
|
||||
$self->{output}->add_option_msg(short_msg => "No session information found.");
|
||||
}
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
@ -142,7 +140,7 @@ sub run {
|
|||
|
||||
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All Contexts are ok.');
|
||||
short_msg => 'All Sessions are ok.');
|
||||
};
|
||||
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
|
@ -207,17 +205,13 @@ Specify username for basic authentification (Mandatory if --credentials is speci
|
|||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--realm>
|
||||
|
||||
Credentials Realm (Default: 'Tomcat Manager Application')
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--path>
|
||||
=item B<--urlpath>
|
||||
|
||||
Path to the Tomcat Manager List (Default: '/manager/text/list')
|
||||
Path to the Tomcat Manager List (Default: Tomcat 7 '/manager/text/list')
|
||||
Tomcat 6: '/manager/list'
|
||||
Tomcat 7: '/manager/text/list'
|
||||
|
||||
|
|
|
@ -0,0 +1,302 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::tomcat::web::mode::threads;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use XML::XPath;
|
||||
use URI::Escape;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '8080' },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"name:s" => { name => 'name' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
$self->{hostname} = undef;
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
my %xpath_to_check = (
|
||||
maxThreads => '/status/connector/threadInfo/@maxThreads',
|
||||
currentThreadCount => '/status/connector/threadInfo/@currentThreadCount',
|
||||
currentThreadsBusy => '/status/connector/threadInfo/@currentThreadsBusy',
|
||||
);
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my $port = $self->{option_results}->{port};
|
||||
|
||||
#EXAMPLE 1:
|
||||
#<status>
|
||||
# <connector name="http-0">
|
||||
# <threadInfo currentThreadCount="0" currentThreadsBusy="0" maxThreads="200"/>
|
||||
# <requestInfo bytesReceived="0" bytesSent="0" errorCount="0" maxTime="0" processingTime="0" requestCount="0"/>
|
||||
# <workers></workers>
|
||||
# </connector>
|
||||
# <connector name="http-8080">
|
||||
# <threadInfo currentThreadCount="158" currentThreadsBusy="10" maxThreads="200"/>
|
||||
# <requestInfo bytesReceived="297" bytesSent="19350704517" errorCount="192504" maxTime="249349" processingTime="2242513592" requestCount="983650"/>
|
||||
# <workers>
|
||||
# </workers>
|
||||
# </connector>
|
||||
#</status>
|
||||
|
||||
#EXAMPLE 2:
|
||||
#<status>
|
||||
#<jvm>
|
||||
# <memory free='409303928' total='518979584' max='518979584'/>
|
||||
# <memorypool name='Eden Space' type='Heap memory' usageInit='143130624' usageCommitted='143130624' usageMax='143130624' usageUsed='56881560'/>
|
||||
# <memorypool name='Survivor Space' type='Heap memory' usageInit='17891328' usageCommitted='17891328' usageMax='17891328' usageUsed='17891328'/>
|
||||
# <memorypool name='Tenured Gen' type='Heap memory' usageInit='357957632' usageCommitted='357957632' usageMax='357957632' usageUsed='34902768'/>
|
||||
# <memorypool name='Code Cache' type='Non-heap memory' usageInit='2555904' usageCommitted='2555904' usageMax='50331648' usageUsed='1899840'/>
|
||||
# <memorypool name='Perm Gen' type='Non-heap memory' usageInit='21757952' usageCommitted='21757952' usageMax='85983232' usageUsed='21372688'/>
|
||||
#</jvm>
|
||||
#<connector name='"http-bio-10.1.80.149-22002"'><threadInfo maxThreads="5" currentThreadCount="2" currentThreadsBusy="1" />
|
||||
# <requestInfo maxTime="1216" processingTime="1216" requestCount="1" errorCount="1" bytesReceived="0" bytesSent="2474" />
|
||||
# <workers>
|
||||
# <worker stage="S" requestProcessingTime="23" requestBytesSent="0" requestBytesReceived="0" remoteAddr="10.1.80.149" virtualHost="examplehost" method="GET" currentUri="/manager/status" currentQueryString="XML=true" protocol="HTTP/1.1" />
|
||||
# </workers>
|
||||
#</connector>
|
||||
#<connector name='"ajp-bio-10.1.80.149-22001"'><threadInfo maxThreads="150" currentThreadCount="0" currentThreadsBusy="0" />
|
||||
# <requestInfo maxTime="0" processingTime="0" requestCount="0" errorCount="0" bytesReceived="0" bytesSent="0" />
|
||||
# <workers>
|
||||
# </workers>
|
||||
#</connector>
|
||||
#</status>
|
||||
|
||||
#GET XML DATA
|
||||
my $xpath = XML::XPath->new( xml => $webcontent );
|
||||
my %xpath_check_results;
|
||||
|
||||
foreach my $xpath_check ( keys %xpath_to_check ) {
|
||||
my $singlepath = $xpath_to_check{$xpath_check};
|
||||
$singlepath =~ s{\$port}{$port};
|
||||
my $nodeset = $xpath->find($singlepath);
|
||||
|
||||
foreach my $node ($nodeset->get_nodelist) {
|
||||
my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
|
||||
$connector_name =~ s/^["'\s]+//;
|
||||
$connector_name =~ s/["'\s]+$//;
|
||||
$connector_name = uri_unescape($connector_name);
|
||||
|
||||
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $connector_name !~ /$self->{option_results}->{name}/i);
|
||||
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $connector_name !~ /$self->{option_results}->{name}/);
|
||||
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $connector_name ne $self->{option_results}->{name});
|
||||
|
||||
my $value = $node->string_value();
|
||||
if ( $value =~ /^"?([0-9.]+)"?$/ ) {
|
||||
$self->{result}->{$connector_name}{$xpath_check} = $1;
|
||||
} else {
|
||||
$self->{result}->{$connector_name}{$xpath_check} = "not_numeric";
|
||||
};
|
||||
};
|
||||
|
||||
if (scalar(keys %{$self->{result}}) <= 0) {
|
||||
if (defined($self->{option_results}->{name})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No information found.");
|
||||
}
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All Threads are ok.');
|
||||
};
|
||||
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $self->{result}->{$name}->{currentThreadsBusy}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Thread '%s' currentThreadsBusy : %s", $name,
|
||||
$self->{result}->{$name}->{currentThreadsBusy}));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Thread '%s' currentThreadsBusy : %s", $name,
|
||||
$self->{result}->{$name}->{currentThreadsBusy}));
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(label => 'currentThreadsBusy' . $extra_label,
|
||||
value => $self->{result}->{$name}->{currentThreadsBusy},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0,
|
||||
max => $self->{result}->{$name}->{maxThreads});
|
||||
|
||||
$self->{output}->perfdata_add(label => 'currentThreadCount' . $extra_label,
|
||||
value => $self->{result}->{$name}->{currentThreadCount},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0,
|
||||
max => $self->{result}->{$name}->{maxThreads});
|
||||
};
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Tomcat Application Servers Threads for each Connector
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Address or FQDN of the Tomcat Application Server
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Tomcat
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Protocol used http or https
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning Threshold for Number of Threads
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Critical Threshold for Number of Threads
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Set the filter name (empty means 'check all contexts')
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,402 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::tomcat::web::mode::traffic;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use XML::XPath;
|
||||
use URI::Escape;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', default => '8080' },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
|
||||
"name:s" => { name => 'name' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
"speed:s" => { name => 'speed' },
|
||||
"warning-in:s" => { name => 'warning_in' },
|
||||
"critical-in:s" => { name => 'critical_in' },
|
||||
"warning-out:s" => { name => 'warning_out' },
|
||||
"critical-out:s" => { name => 'critical_out' },
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
$self->{hostname} = undef;
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{option_results}->{proto} ne 'http') && ($self->{option_results}->{proto} ne 'https')) {
|
||||
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning 'in' threshold '" . $self->{option_results}->{warning_in} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-in', value => $self->{option_results}->{critical_in})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical 'in' threshold '" . $self->{option_results}->{critical_in} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-out', value => $self->{option_results}->{warning_out})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning 'out' threshold '" . $self->{option_results}->{warning_out} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-out', value => $self->{option_results}->{critical_out})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical 'out' threshold '" . $self->{option_results}->{critical_out} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '' && $self->{option_results}->{speed} !~ /^[0-9]+(\.[0-9]+){0,1}$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Speed must be a positive number '" . $self->{option_results}->{speed} . "' (can be a float also).");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{option_results}->{units}) && $self->{option_results}->{units} eq '%' &&
|
||||
(!defined($self->{option_results}->{speed}) || $self->{option_results}->{speed} eq '')) {
|
||||
$self->{output}->add_option_msg(short_msg => "To use percent, you need to set --speed option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
$self->{hostname} = $self->{option_results}->{hostname};
|
||||
if (!defined($self->{hostname})) {
|
||||
$self->{hostname} = 'me';
|
||||
}
|
||||
}
|
||||
|
||||
my %xpath_to_check = (
|
||||
in => '/status/connector/requestInfo/@bytesReceived',
|
||||
out => '/status/connector/requestInfo/@bytesSent',
|
||||
);
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my $port = $self->{option_results}->{port};
|
||||
|
||||
#EXAMPLE 1:
|
||||
#<status>
|
||||
# <connector name="http-0">
|
||||
# <threadInfo currentThreadCount="0" currentThreadsBusy="0" maxThreads="200"/>
|
||||
# <requestInfo bytesReceived="0" bytesSent="0" errorCount="0" maxTime="0" processingTime="0" requestCount="0"/>
|
||||
# <workers></workers>
|
||||
# </connector>
|
||||
# <connector name="http-8080">
|
||||
# <threadInfo currentThreadCount="158" currentThreadsBusy="10" maxThreads="200"/>
|
||||
# <requestInfo bytesReceived="297" bytesSent="19350704517" errorCount="192504" maxTime="249349" processingTime="2242513592" requestCount="983650"/>
|
||||
# <workers>
|
||||
# </workers>
|
||||
# </connector>
|
||||
#</status>
|
||||
|
||||
#EXAMPLE 2:
|
||||
#<status>
|
||||
#<jvm>
|
||||
# <memory free='409303928' total='518979584' max='518979584'/>
|
||||
# <memorypool name='Eden Space' type='Heap memory' usageInit='143130624' usageCommitted='143130624' usageMax='143130624' usageUsed='56881560'/>
|
||||
# <memorypool name='Survivor Space' type='Heap memory' usageInit='17891328' usageCommitted='17891328' usageMax='17891328' usageUsed='17891328'/>
|
||||
# <memorypool name='Tenured Gen' type='Heap memory' usageInit='357957632' usageCommitted='357957632' usageMax='357957632' usageUsed='34902768'/>
|
||||
# <memorypool name='Code Cache' type='Non-heap memory' usageInit='2555904' usageCommitted='2555904' usageMax='50331648' usageUsed='1899840'/>
|
||||
# <memorypool name='Perm Gen' type='Non-heap memory' usageInit='21757952' usageCommitted='21757952' usageMax='85983232' usageUsed='21372688'/>
|
||||
#</jvm>
|
||||
#<connector name='"http-bio-10.1.80.149-22002"'><threadInfo maxThreads="5" currentThreadCount="2" currentThreadsBusy="1" />
|
||||
# <requestInfo maxTime="1216" processingTime="1216" requestCount="1" errorCount="1" bytesReceived="0" bytesSent="2474" />
|
||||
# <workers>
|
||||
# <worker stage="S" requestProcessingTime="23" requestBytesSent="0" requestBytesReceived="0" remoteAddr="10.1.80.149" virtualHost="examplehost" method="GET" currentUri="/manager/status" currentQueryString="XML=true" protocol="HTTP/1.1" />
|
||||
# </workers>
|
||||
#</connector>
|
||||
#<connector name='"ajp-bio-10.1.80.149-22001"'><threadInfo maxThreads="150" currentThreadCount="0" currentThreadsBusy="0" />
|
||||
# <requestInfo maxTime="0" processingTime="0" requestCount="0" errorCount="0" bytesReceived="0" bytesSent="0" />
|
||||
# <workers>
|
||||
# </workers>
|
||||
#</connector>
|
||||
#</status>
|
||||
|
||||
#GET XML DATA
|
||||
my $xpath = XML::XPath->new( xml => $webcontent );
|
||||
my %xpath_check_results;
|
||||
|
||||
foreach my $xpath_check ( keys %xpath_to_check ) {
|
||||
my $singlepath = $xpath_to_check{$xpath_check};
|
||||
$singlepath =~ s{\$port}{$port};
|
||||
my $nodeset = $xpath->find($singlepath);
|
||||
|
||||
foreach my $node ($nodeset->get_nodelist) {
|
||||
my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
|
||||
$connector_name =~ s/^["'\s]+//;
|
||||
$connector_name =~ s/["'\s]+$//;
|
||||
$connector_name = uri_unescape($connector_name);
|
||||
|
||||
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $connector_name !~ /$self->{option_results}->{name}/i);
|
||||
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $connector_name !~ /$self->{option_results}->{name}/);
|
||||
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $connector_name ne $self->{option_results}->{name});
|
||||
|
||||
my $value = $node->string_value();
|
||||
if ( $value =~ /^"?([0-9.]+)"?$/ ) {
|
||||
$self->{result}->{$connector_name}{$xpath_check} = $1;
|
||||
} else {
|
||||
$self->{result}->{$connector_name}{$xpath_check} = "not_numeric";
|
||||
};
|
||||
};
|
||||
|
||||
if (scalar(keys %{$self->{result}}) <= 0) {
|
||||
if (defined($self->{option_results}->{name})) {
|
||||
$self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'.");
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "No information found.");
|
||||
}
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
|
||||
my $new_datas = {};
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$new_datas->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All traffic are ok.');
|
||||
}
|
||||
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$new_datas->{'in_' . $name} = $self->{result}->{$name}->{in} * 8;
|
||||
$new_datas->{'out_' . $name} = $self->{result}->{$name}->{out} * 8;
|
||||
|
||||
my $old_in = $self->{statefile_value}->get(name => 'in_' . $name);
|
||||
my $old_out = $self->{statefile_value}->get(name => 'out_' . $name);
|
||||
if (!defined($old_timestamp) || !defined($old_in) || !defined($old_out)) {
|
||||
next;
|
||||
}
|
||||
if ($new_datas->{'in_' . $name} < $old_in) {
|
||||
# We set 0. Has reboot.
|
||||
$old_in = 0;
|
||||
}
|
||||
if ($new_datas->{'out_' . $name} < $old_out) {
|
||||
# We set 0. Has reboot.
|
||||
$old_out = 0;
|
||||
}
|
||||
|
||||
my $time_delta = $new_datas->{last_timestamp} - $old_timestamp;
|
||||
if ($time_delta <= 0) {
|
||||
# At least one second. two fast calls ;)
|
||||
$time_delta = 1;
|
||||
}
|
||||
my $in_absolute_per_sec = ($new_datas->{'in_' . $name} - $old_in) / $time_delta;
|
||||
my $out_absolute_per_sec = ($new_datas->{'out_' . $name} - $old_out) / $time_delta;
|
||||
|
||||
my ($exit, $interface_speed, $in_prct, $out_prct);
|
||||
if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
|
||||
$interface_speed = $self->{option_results}->{speed} * 1000000;
|
||||
$in_prct = $in_absolute_per_sec * 100 / ($self->{option_results}->{speed} * 1000000);
|
||||
$out_prct = $out_absolute_per_sec * 100 / ($self->{option_results}->{speed} * 1000000);
|
||||
if ($self->{option_results}->{units} eq '%') {
|
||||
my $exit1 = $self->{perfdata}->threshold_check(value => $in_prct, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
|
||||
my $exit2 = $self->{perfdata}->threshold_check(value => $out_prct, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
|
||||
$exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
|
||||
}
|
||||
$in_prct = sprintf("%.2f", $in_prct);
|
||||
$out_prct = sprintf("%.2f", $out_prct);
|
||||
} else {
|
||||
my $exit1 = $self->{perfdata}->threshold_check(value => $in_absolute_per_sec, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
|
||||
my $exit2 = $self->{perfdata}->threshold_check(value => $out_absolute_per_sec, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
|
||||
$exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
|
||||
$in_prct = '-';
|
||||
$out_prct = '-';
|
||||
}
|
||||
|
||||
###########
|
||||
# Manage Output
|
||||
###########
|
||||
|
||||
my ($in_value, $in_unit) = $self->{perfdata}->change_bytes(value => $in_absolute_per_sec, network => 1);
|
||||
my ($out_value, $out_unit) = $self->{perfdata}->change_bytes(value => $out_absolute_per_sec, network => 1);
|
||||
$self->{output}->output_add(long_msg => sprintf("Connector '%s' Traffic In : %s/s (%s %%), Out : %s/s (%s %%) ", $name,
|
||||
$in_value . $in_unit, $in_prct,
|
||||
$out_value . $out_unit, $out_prct));
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Connector '%s' Traffic In : %s/s (%s %%), Out : %s/s (%s %%) ", $name,
|
||||
$in_value . $in_unit, $in_prct,
|
||||
$out_value . $out_unit, $out_prct));
|
||||
}
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
|
||||
|
||||
$self->{output}->perfdata_add(label => 'traffic_in' . $extra_label, unit => 'b/s',
|
||||
value => sprintf("%.2f", $in_absolute_per_sec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in', total => $interface_speed),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in', total => $interface_speed),
|
||||
min => 0, max => $interface_speed);
|
||||
$self->{output}->perfdata_add(label => 'traffic_out' . $extra_label, unit => 'b/s',
|
||||
value => sprintf("%.2f", $out_absolute_per_sec),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out', total => $interface_speed),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out', total => $interface_speed),
|
||||
min => 0, max => $interface_speed);
|
||||
}
|
||||
|
||||
$self->{statefile_value}->write(data => $new_datas);
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Tomcat Application Servers Traffic for each Connector
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Address or FQDN of the Tomcat Application Server
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Tomcat
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Protocol used http or https
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Set the filter name (empty means 'check all contexts')
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter (with option --name).
|
||||
|
||||
=item B<--regexp-isensitive>
|
||||
|
||||
Allows to use regexp non case-sensitive (with --regexp).
|
||||
|
||||
=item B<--warning-in>
|
||||
|
||||
Threshold warning in percent for 'in' traffic.
|
||||
|
||||
=item B<--critical-in>
|
||||
|
||||
Threshold critical in percent for 'in' traffic.
|
||||
|
||||
=item B<--warning-out>
|
||||
|
||||
Threshold warning in percent for 'out' traffic.
|
||||
|
||||
=item B<--critical-out>
|
||||
|
||||
Threshold critical in percent for 'out' traffic.
|
||||
|
||||
=item B<--speed>
|
||||
|
||||
Set Connector Interface speed (in Mb).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -31,8 +31,6 @@
|
|||
# For more information : contact@centreon.com
|
||||
# Author : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
# Based on Apache Mode by Simon BOMM
|
||||
####################################################################################
|
||||
|
||||
package apps::tomcat::web::plugin;
|
||||
|
@ -49,11 +47,13 @@ sub new {
|
|||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'application' => 'apps::tomcat::web::mode::application',
|
||||
'applications' => 'apps::tomcat::web::mode::applications',
|
||||
'list-application' => 'apps::tomcat::web::mode::listapplication',
|
||||
'sessions' => 'apps::tomcat::web::mode::sessions',
|
||||
'threads' => 'apps::tomcat::web::mode::threads',
|
||||
'requestinfo' => 'apps::tomcat::web::mode::requestinfo',
|
||||
'memory' => 'apps::tomcat::web::mode::memory',
|
||||
'traffic' => 'apps::tomcat::web::mode::traffic',
|
||||
);
|
||||
|
||||
return $self;
|
||||
|
|
|
@ -0,0 +1,311 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::backend;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
backend_conn => { thresholds => {
|
||||
warning_conn => { label => 'warning-conn', exit_value => 'warning' },
|
||||
critical_conn => { label => 'critical-conn', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. success: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
backend_unhealthy => { thresholds => {
|
||||
warning_unhealthy => { label => 'warning-unhealthy', exit_value => 'warning' },
|
||||
critical_unhealthy => { label => 'critical-unhealthy', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. not attempted: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
backend_busy => { thresholds => {
|
||||
warning_busy => { label => 'warning-busy', exit_value => 'warning' },
|
||||
critical_busy => { label => 'critical-busy', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. too many: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
backend_fail => { thresholds => {
|
||||
warning_fail => { label => 'warning-fail', exit_value => 'warning' },
|
||||
critical_fail => { label => 'critical-fail', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. failures: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
backend_reuse => { thresholds => {
|
||||
warning_reuse => { label => 'warning-reuse', exit_value => 'warning' },
|
||||
critical_reuse => { label => 'critical-reuse', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. reuses: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
backend_toolate => { thresholds => {
|
||||
warning_toolate => { label => 'warning-toolate', exit_value => 'warning' },
|
||||
critical_toolate => { label => 'critical-toolate', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. was closed: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
backend_recycle => { thresholds => {
|
||||
warning_recycle => { label => 'warning-recycle', exit_value => 'warning' },
|
||||
critical_recycle => { label => 'critical-recycle', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. recycles: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
backend_retry => { thresholds => {
|
||||
warning_retry => { label => 'warning-retry', exit_value => 'warning' },
|
||||
critical_retry => { label => 'critical-retry', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. retry: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
backend_req => { thresholds => {
|
||||
warning_req => { label => 'warning-req', exit_value => 'warning' },
|
||||
critical_req => { label => 'critical-req', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend requests made: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
conn => Backend conn. success,
|
||||
unhealthy => Backend conn. not attempted,
|
||||
busy => Backend conn. too many,
|
||||
fail => Backend conn. failures,
|
||||
reuse => Backend conn. reuses,
|
||||
toolate => Backend conn. was closed,
|
||||
recycle => Backend conn. recycles,
|
||||
retry => Backend conn. retry,
|
||||
req => Backend requests made
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
conn => Backend conn. success,
|
||||
unhealthy => Backend conn. not attempted,
|
||||
busy => Backend conn. too many,
|
||||
fail => Backend conn. failures,
|
||||
reuse => Backend conn. reuses,
|
||||
toolate => Backend conn. was closed,
|
||||
recycle => Backend conn. recycles,
|
||||
retry => Backend conn. retry,
|
||||
req => Backend requests made
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,284 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::bans;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
n_ban => { thresholds => {
|
||||
warning_total => { label => 'warning-total', exit_value => 'warning' },
|
||||
critical_total => { label => 'critical-total', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N total active bans: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_ban_add => { thresholds => {
|
||||
warning_add => { label => 'warning-add', exit_value => 'warning' },
|
||||
critical_add => { label => 'critical-add', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N new bans added: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_ban_retire => { thresholds => {
|
||||
warning_retire => { label => 'warning-retire', exit_value => 'warning' },
|
||||
critical_retire => { label => 'critical-retire', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N old bans deleted: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_ban_obj_test => { thresholds => {
|
||||
warning_objtest => { label => 'warning-objtest', exit_value => 'warning' },
|
||||
critical_objtest => { label => 'critical-objtest', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N objects tested: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_ban_re_test => { thresholds => {
|
||||
warning_retest => { label => 'warning-retest', exit_value => 'warning' },
|
||||
critical_retest => { label => 'critical-retest', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N regexps tested against: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_ban_dups => { thresholds => {
|
||||
warning_dups => { label => 'warning-dups', exit_value => 'warning' },
|
||||
critical_dups => { label => 'critical-dups', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N duplicate bans removed: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
total => N total active bans,
|
||||
add => N new bans added,
|
||||
retire => N old bans deleted,
|
||||
objtest => N objects tested,
|
||||
retest => N regexps tested against,
|
||||
dups => N duplicate bans removed
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
total => N total active bans,
|
||||
add => N new bans added,
|
||||
retire => N old bans deleted,
|
||||
objtest => N objects tested,
|
||||
retest => N regexps tested against,
|
||||
dups => N duplicate bans removed
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,263 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::cache;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
cache_hit => { thresholds => {
|
||||
warning_hit => { label => 'warning-hit', exit_value => 'warning' },
|
||||
critical_hit => { label => 'critical-hit', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Cache Hits: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
cache_hitpass => { thresholds => {
|
||||
warning_hitpass => { label => 'warning-hitpass', exit_value => 'warning' },
|
||||
critical_hitpass => { label => 'critical-hitpass', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Cache Hits for pass: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
cache_miss => { thresholds => {
|
||||
warning_miss => { label => 'warning-miss', exit_value => 'warning' },
|
||||
critical_miss => { label => 'critical-miss', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Cache misses: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
#my $stdout = '
|
||||
#cache_hit 69941 0.00 Cache hits
|
||||
#cache_hitpass 10 0.00 Cache hits for pass
|
||||
#cache_miss 16746 0.00 Cache misses
|
||||
#';
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
hit => Cache Hits,
|
||||
hitpass => Cache hits for Pass,
|
||||
miss => Cache Misses
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
hit => Cache Hits,
|
||||
hitpass => Cache hits for Pass,
|
||||
miss => Cache Misses
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,266 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::connections;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
client_conn => { thresholds => {
|
||||
warning_conn => { label => 'warning-conn', exit_value => 'warning' },
|
||||
critical_conn => { label => 'critical-conn', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Client connections accepted: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
client_drop => { thresholds => {
|
||||
warning_drop => { label => 'warning-drop', exit_value => 'warning' },
|
||||
critical_drop => { label => 'critical-drop', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Connection dropped, no sess/wrk: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
client_drop_late => { thresholds => {
|
||||
warning_droplate => { label => 'warning-droplate', exit_value => 'warning' },
|
||||
critical_droplate => { label => 'critical-droplate', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Connection dropped late: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
client_req => { thresholds => {
|
||||
warning_req => { label => 'warning-req', exit_value => 'warning' },
|
||||
critical_req => { label => 'critical-req', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Client requests received: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
conn => Client connections accepted,
|
||||
drop => Connection dropped, no sess/wrk,
|
||||
droplate => Connection dropped late,
|
||||
req => Client requests received
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
conn => Client connections accepted,
|
||||
drop => Connection dropped, no sess/wrk,
|
||||
droplate => Connection dropped late,
|
||||
req => Client requests received
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,266 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::dns;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
dir_dns_lookups => { thresholds => {
|
||||
warning_lookups => { label => 'warning-lookups', exit_value => 'warning' },
|
||||
critical_lookups => { label => 'critical-lookups', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'HCB Lookups without lock: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
dir_dns_failed => { thresholds => {
|
||||
warning_failed => { label => 'warning-failed', exit_value => 'warning' },
|
||||
critical_failed => { label => 'critical-failed', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'HCB Lookups with lock: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
dir_dns_hit => { thresholds => {
|
||||
warning_hit => { label => 'warning-hit', exit_value => 'warning' },
|
||||
critical_hit => { label => 'critical-hit', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'HCB Inserts: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
dir_dns_cache_full => { thresholds => {
|
||||
warning_full => { label => 'warning-full', exit_value => 'warning' },
|
||||
critical_full => { label => 'critical-full', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'HCB Inserts: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
lookups => DNS director lookups,
|
||||
failed => DNS director failed lookups,
|
||||
hit => DNS director cached lookups hit,
|
||||
full => DNS director full dnscache
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
lookups => DNS director lookups,
|
||||
failed => DNS director failed lookups,
|
||||
hit => DNS director cached lookups hit,
|
||||
full => DNS director full dnscache
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,248 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::esi;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
esi_errors => { thresholds => {
|
||||
warning_errors => { label => 'warning-errors', exit_value => 'warning' },
|
||||
critical_errors => { label => 'critical-errors', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'ESI parse errors (unlock): %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
esi_warnings => { thresholds => {
|
||||
warning_warnings => { label => 'warning-warnings', exit_value => 'warning' },
|
||||
critical_warnings => { label => 'critical-warnings', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'ESI parse warnings (unlock): %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
errors => ESI parse errors (unlock),
|
||||
warnings => ESI parse warnings (unlock)
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
errors => ESI parse errors (unlock),
|
||||
warnings => ESI parse warnings (unlock)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,338 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::fetch;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
fetch_head => { thresholds => {
|
||||
warning_head => { label => 'warning-head', exit_value => 'warning' },
|
||||
critical_head => { label => 'critical-head', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch head: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_length => { thresholds => {
|
||||
warning_length => { label => 'warning-length', exit_value => 'warning' },
|
||||
critical_length => { label => 'critical-length', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch with Length: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_chunked => { thresholds => {
|
||||
warning_chunked => { label => 'warning-chunked', exit_value => 'warning' },
|
||||
critical_chunked => { label => 'critical-chunked', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch chunked: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_eof => { thresholds => {
|
||||
warning_eof => { label => 'warning-eof', exit_value => 'warning' },
|
||||
critical_eof => { label => 'critical-eof', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch EOF: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_bad => { thresholds => {
|
||||
warning_bad => { label => 'warning-bad', exit_value => 'warning' },
|
||||
critical_bad => { label => 'critical-bad', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch had bad headers: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_close => { thresholds => {
|
||||
warning_close => { label => 'warning-close', exit_value => 'warning' },
|
||||
critical_close => { label => 'critical-close', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch wanted close: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_oldhttp => { thresholds => {
|
||||
warning_oldhttp => { label => 'warning-oldhttp', exit_value => 'warning' },
|
||||
critical_oldhttp => { label => 'critical-oldhttp', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch pre HTTP/1.1 closed: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_zero => { thresholds => {
|
||||
warning_zero => { label => 'warning-zero', exit_value => 'warning' },
|
||||
critical_zero => { label => 'critical-zero', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch zero len: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_failed => { thresholds => {
|
||||
warning_failed => { label => 'warning-failed', exit_value => 'warning' },
|
||||
critical_failed => { label => 'critical-failed', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch failed: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_1xx => { thresholds => {
|
||||
warning_1xx => { label => 'warning-1xx', exit_value => 'warning' },
|
||||
critical_1xx => { label => 'critical-1xx', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch no body (1xx): %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_204 => { thresholds => {
|
||||
warning_204 => { label => 'warning-204', exit_value => 'warning' },
|
||||
critical_204 => { label => 'critical-204', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch no body (204): %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
fetch_304 => { thresholds => {
|
||||
warning_304 => { label => 'warning-304', exit_value => 'warning' },
|
||||
critical_304 => { label => 'critical-304', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Fetch no body (304): %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
head => Fetch head,
|
||||
length => Fetch with Length,
|
||||
chunked => Fetch chunked,
|
||||
eof => Fetch EOF,
|
||||
bad => Fetch had bad headers,
|
||||
close => Fetch wanted close,
|
||||
oldhttp => Fetch pre HTTP/1.1 closed,
|
||||
zero => Fetch zero len,
|
||||
failed => Fetch failed,
|
||||
1xx => Fetch no body (1xx),
|
||||
204 => Fetch no body (204),
|
||||
304 => Fetch no body (304)
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
head => Fetch head,
|
||||
length => Fetch with Length,
|
||||
chunked => Fetch chunked,
|
||||
eof => Fetch EOF,
|
||||
bad => Fetch had bad headers,
|
||||
close => Fetch wanted close,
|
||||
oldhttp => Fetch pre HTTP/1.1 closed,
|
||||
zero => Fetch zero len,
|
||||
failed => Fetch failed,
|
||||
1xx => Fetch no body (1xx),
|
||||
204 => Fetch no body (204),
|
||||
304 => Fetch no body (304)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,257 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::hcb;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
hcb_nolock => { thresholds => {
|
||||
warning_nolock => { label => 'warning-nolock', exit_value => 'warning' },
|
||||
critical_nolock => { label => 'critical-nolock', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'HCB Lookups without lock: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
hcb_lock => { thresholds => {
|
||||
warning_lock => { label => 'warning-lock', exit_value => 'warning' },
|
||||
critical_lock => { label => 'critical-lock', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'HCB Lookups with lock: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
hcb_insert => { thresholds => {
|
||||
warning_insert => { label => 'warning-insert', exit_value => 'warning' },
|
||||
critical_insert => { label => 'critical-insert', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'HCB Inserts: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
nolock => HCB Lookups without lock,
|
||||
lock => HCB Lookups with lock,
|
||||
insert => HCB Inserts
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
nolock => HCB Lookups without lock,
|
||||
lock => HCB Lookups with lock,
|
||||
insert => HCB Inserts
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,338 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::n;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
n_sess_mem => { thresholds => {
|
||||
warning_mem => { label => 'warning-mem', exit_value => 'warning' },
|
||||
critical_mem => { label => 'critical-mem', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N struct sess_mem: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_sess => { thresholds => {
|
||||
warning_sess => { label => 'warning-sess', exit_value => 'warning' },
|
||||
critical_sess => { label => 'critical-sess', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N struct sess: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_object => { thresholds => {
|
||||
warning_object => { label => 'warning-object', exit_value => 'warning' },
|
||||
critical_object => { label => 'critical-object', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N struct object: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_vampireobject => { thresholds => {
|
||||
warning_vampireobject => { label => 'warning-vampireobject', exit_value => 'warning' },
|
||||
critical_vampireobject => { label => 'critical-vampireobject', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N unresurrected objects: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_objectcore => { thresholds => {
|
||||
warning_objectcore => { label => 'warning-objectcore', exit_value => 'warning' },
|
||||
critical_objectcore => { label => 'critical-objectcore', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N struct objectcore: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_objecthead => { thresholds => {
|
||||
warning_objecthead => { label => 'warning-objecthead', exit_value => 'warning' },
|
||||
critical_objecthead => { label => 'critical-objecthead', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N struct objecthead: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_waitinglist => { thresholds => {
|
||||
warning_waitinglist => { label => 'warning-waitinglist', exit_value => 'warning' },
|
||||
critical_waitinglist => { label => 'critical-waitinglist', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N struct waitinglist: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_vbc => { thresholds => {
|
||||
warning_vbc => { label => 'warning-vbc', exit_value => 'warning' },
|
||||
critical_vbc => { label => 'critical-vbc', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N struct vbc: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_backend => { thresholds => {
|
||||
warning_backend => { label => 'warning-backend', exit_value => 'warning' },
|
||||
critical_backend => { label => 'critical-backend', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N backends: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_expired => { thresholds => {
|
||||
warning_expired => { label => 'warning-expired', exit_value => 'warning' },
|
||||
critical_expired => { label => 'critical-expired', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N expired objects: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_lru_nuked => { thresholds => {
|
||||
warning_nuked => { label => 'warning-nuked', exit_value => 'warning' },
|
||||
critical_nuked => { label => 'critical-nuked', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N LRU nuked objects: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_lru_moved => { thresholds => {
|
||||
warning_moved => { label => 'warning-moved', exit_value => 'warning' },
|
||||
critical_moved => { label => 'critical-moved', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N LRU moved objects: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
n_sess_mem => N struct sess_mem,
|
||||
n_sess => N struct sess,
|
||||
n_object => N struct object,
|
||||
n_vampireobject => N unresurrected objects,
|
||||
n_objectcore => N struct objectcore,
|
||||
n_objecthead => N struct objecthead,
|
||||
n_waitinglist => N struct waitinglist,
|
||||
n_vbc => N struct vbc,
|
||||
n_backend => N backends,
|
||||
n_expired => N expired objects,
|
||||
n_lru_nuked => N LRU nuked objects,
|
||||
n_lru_moved => N LRU moved objects
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
n_sess_mem => N struct sess_mem,
|
||||
n_sess => N struct sess,
|
||||
n_object => N struct object,
|
||||
n_vampireobject => N unresurrected objects,
|
||||
n_objectcore => N struct objectcore,
|
||||
n_objecthead => N struct objecthead,
|
||||
n_waitinglist => N struct waitinglist,
|
||||
n_vbc => N struct vbc,
|
||||
n_backend => N backends,
|
||||
n_expired => N expired objects,
|
||||
n_lru_nuked => N LRU nuked objects,
|
||||
n_lru_moved => N LRU moved objects
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,257 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::objects;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
n_objsendfile => { thresholds => {
|
||||
warning_objsendfile => { label => 'warning-objsendfile', exit_value => 'warning' },
|
||||
critical_objsendfile => { label => 'critical-objsendfile', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Objects sent with sendfile: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_objwrite => { thresholds => {
|
||||
warning_objwrite => { label => 'warning-objwrite', exit_value => 'warning' },
|
||||
critical_objwrite => { label => 'critical-objwrite', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Objects sent with write: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_objoverflow => { thresholds => {
|
||||
warning_objoverflow => { label => 'warning-objoverflow', exit_value => 'warning' },
|
||||
critical_objoverflow => { label => 'critical-objoverflow', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Objects overflowing workspace: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
objsendfile => Objects sent with sendfile,
|
||||
objwrite => Objects sent with write,
|
||||
objoverflow => Objects overflowing workspace
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
objsendfile => Objects sent with sendfile,
|
||||
objwrite => Objects sent with write,
|
||||
objoverflow => Objects overflowing workspace
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,275 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::sessions;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
sess_closed => { thresholds => {
|
||||
warning_closed => { label => 'warning-closed', exit_value => 'warning' },
|
||||
critical_closed => { label => 'critical-closed', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Session Closed: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
sess_pipeline => { thresholds => {
|
||||
warning_pipeline => { label => 'warning-pipeline', exit_value => 'warning' },
|
||||
critical_pipeline => { label => 'critical-pipeline', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Session Pipeline: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
sess_readahead => { thresholds => {
|
||||
warning_readahead => { label => 'warning-readahead', exit_value => 'warning' },
|
||||
critical_readahead => { label => 'critical-readahead', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Session Read Ahead: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
sess_linger => { thresholds => {
|
||||
warning_linger => { label => 'warning-linger', exit_value => 'warning' },
|
||||
critical_linger => { label => 'critical-linger', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Session Linger: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
sess_herd => { thresholds => {
|
||||
warning_herd => { label => 'warning-herd', exit_value => 'warning' },
|
||||
critical_herd => { label => 'critical-herd', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Session herd: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
closed => Session Closed,
|
||||
pipeline => Session Pipeline,
|
||||
readahead => Session Read Ahead,
|
||||
linger => Session Linger,
|
||||
herd => Session herd
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
closed => Session Closed,
|
||||
pipeline => Session Pipeline,
|
||||
readahead => Session Read Ahead,
|
||||
linger => Session Linger,
|
||||
herd => Session herd
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,275 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::shm;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
shm_records => { thresholds => {
|
||||
warning_records => { label => 'warning-records', exit_value => 'warning' },
|
||||
critical_records => { label => 'critical-records', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'SHM records: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
shm_writes => { thresholds => {
|
||||
warning_writes => { label => 'warning-writes', exit_value => 'warning' },
|
||||
critical_writes => { label => 'critical-writes', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'SHM writes: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
shm_flushes => { thresholds => {
|
||||
warning_flushes => { label => 'warning-flushes', exit_value => 'warning' },
|
||||
critical_flushes => { label => 'critical-flushes', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'SHM flushes due to overflow: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
shm_cont => { thresholds => {
|
||||
warning_cont => { label => 'warning-cont', exit_value => 'warning' },
|
||||
critical_cont => { label => 'critical-cont', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'SHM MTX contention: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
shm_cycles => { thresholds => {
|
||||
warning_cycles => { label => 'warning-cycles', exit_value => 'warning' },
|
||||
critical_cycles => { label => 'critical-cycles', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'SHM cycles through buffer: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
records => SHM records,
|
||||
writes => SHM writes,
|
||||
flushes => SHM flushes due to overflow,
|
||||
cont => SHM MTX contention,
|
||||
cycles => SHM cycles through buffer
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
records => SHM records,
|
||||
writes => SHM writes,
|
||||
flushes => SHM flushes due to overflow,
|
||||
cont => SHM MTX contention,
|
||||
cycles => SHM cycles through buffer
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,275 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::sms;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
sms_nreq => { thresholds => {
|
||||
warning_nreq => { label => 'warning-nreq', exit_value => 'warning' },
|
||||
critical_nreq => { label => 'critical-nreq', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'SMS allocator requests: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
sms_nobj => { thresholds => {
|
||||
warning_nobj => { label => 'warning-nobj', exit_value => 'warning' },
|
||||
critical_nobj => { label => 'critical-nobj', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'SMS outstanding allocations: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
sms_nbytes => { thresholds => {
|
||||
warning_nbytes => { label => 'warning-nbytes', exit_value => 'warning' },
|
||||
critical_nbytes => { label => 'critical-nbytes', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'SMS outstanding bytes: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
sms_balloc => { thresholds => {
|
||||
warning_balloc => { label => 'warning-balloc', exit_value => 'warning' },
|
||||
critical_balloc => { label => 'critical-balloc', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'SMS bytes allocated: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
sms_bfree => { thresholds => {
|
||||
warning_bfree => { label => 'warning-bfree', exit_value => 'warning' },
|
||||
critical_bfree => { label => 'critical-bfree', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'SMS bytes freed: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
nreq => SMS allocator requests,
|
||||
nobj => SMS outstanding allocations,
|
||||
nbytes => SMS outstanding bytes,
|
||||
balloc => SMS bytes allocated,
|
||||
bfree => SMS bytes freed
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
nreq => SMS allocator requests,
|
||||
nobj => SMS outstanding allocations,
|
||||
nbytes => SMS outstanding bytes,
|
||||
balloc => SMS bytes allocated,
|
||||
bfree => SMS bytes freed
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,302 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::totals;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
s_sess => { thresholds => {
|
||||
warning_sess => { label => 'warning-sess', exit_value => 'warning' },
|
||||
critical_sess => { label => 'critical-sess', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Total Sessions: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
s_req => { thresholds => {
|
||||
warning_req => { label => 'warning-req', exit_value => 'warning' },
|
||||
critical_req => { label => 'critical-req', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Total Requests: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
s_pipe => { thresholds => {
|
||||
warning_pipe => { label => 'warning-pipe', exit_value => 'warning' },
|
||||
critical_pipe => { label => 'critical-pipe', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Total pipe: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
s_pass => { thresholds => {
|
||||
warning_pass => { label => 'warning-pass', exit_value => 'warning' },
|
||||
critical_pass => { label => 'critical-pass', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Total pass: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
s_fetch => { thresholds => {
|
||||
warning_fetch => { label => 'warning-fetch', exit_value => 'warning' },
|
||||
critical_fetch => { label => 'critical-fetch', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Total fetch: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
s_hdrbytes => { thresholds => {
|
||||
warning_hdrbytes => { label => 'warning-hdrbytes', exit_value => 'warning' },
|
||||
critical_hdrbytes => { label => 'critical-hdrbytes', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Total header bytes: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
s_bodybytes => { thresholds => {
|
||||
warning_bodybytes => { label => 'warning-bodybytes', exit_value => 'warning' },
|
||||
critical_bodybytes => { label => 'critical-bodybytes', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Total body bytes: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
accept_fail => { thresholds => {
|
||||
warning_fail => { label => 'warning-fail', exit_value => 'warning' },
|
||||
critical_fail => { label => 'critical-fail', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Accept failures: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
sess => Total Sessions,
|
||||
req => Total Requests,
|
||||
pipe => Total pipe,
|
||||
pass => Total pass,
|
||||
fetch => Total fetch,
|
||||
hdrbytes => Total header bytes,
|
||||
bodybytes => Total body bytes,
|
||||
fail => Accept failures
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
sess => Total Sessions,
|
||||
req => Total Requests,
|
||||
pipe => Total pipe,
|
||||
pass => Total pass,
|
||||
fetch => Total fetch,
|
||||
hdrbytes => Total header bytes,
|
||||
bodybytes => Total body bytes,
|
||||
fail => Accept failures
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,237 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::uptime;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
uptime => { thresholds => {
|
||||
warning => { label => 'warning', exit_value => 'warning' },
|
||||
critical => { label => 'critical', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Uptime in sec: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning Threshold for Uptime
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Critical Threshold for Uptime
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,258 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::vcl;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
#n_vcl_avail could be max from n_vcl
|
||||
my $maps_counters = {
|
||||
n_vcl => { thresholds => {
|
||||
warning_total => { label => 'warning-total', exit_value => 'warning' },
|
||||
critical_total => { label => 'critical-total', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N vcl total: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_vcl_avail => { thresholds => {
|
||||
warning_avail => { label => 'warning-avail', exit_value => 'warning' },
|
||||
critical_avail => { label => 'critical-avail', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N vcl available: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_vcl_discard => { thresholds => {
|
||||
warning_discard => { label => 'warning-discard', exit_value => 'warning' },
|
||||
critical_discard => { label => 'critical-discard', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'N vcl discarded: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
total => N vcl total,
|
||||
avail => N vcl available,
|
||||
discard => N vcl discarded
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
total => N vcl total,
|
||||
avail => N vcl available,
|
||||
discard => N vcl discarded
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,293 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::mode::workers;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
my $maps_counters = {
|
||||
n_wrk => { thresholds => {
|
||||
warning_workers => { label => 'warning-workers', exit_value => 'warning' },
|
||||
critical_workers => { label => 'critical-workers', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. success: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_wrk_create => { thresholds => {
|
||||
warning_create => { label => 'warning-create', exit_value => 'warning' },
|
||||
critical_create => { label => 'critical-create', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. not attempted: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_wrk_failed => { thresholds => {
|
||||
warning_failed => { label => 'warning-failed', exit_value => 'warning' },
|
||||
critical_failed => { label => 'critical-failed', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. too many: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_wrk_max => { thresholds => {
|
||||
warning_max => { label => 'warning-max', exit_value => 'warning' },
|
||||
critical_max => { label => 'critical-max', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. failures: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_wrk_lqueue => { thresholds => {
|
||||
warning_lqueue => { label => 'warning-lqueue', exit_value => 'warning' },
|
||||
critical_lqueue => { label => 'critical-lqueue', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. reuses: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_wrk_queued => { thresholds => {
|
||||
warning_queued => { label => 'warning-queued', exit_value => 'warning' },
|
||||
critical_queued => { label => 'critical-queued', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. was closed: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
n_wrk_drop => { thresholds => {
|
||||
warning_drop => { label => 'warning-drop', exit_value => 'warning' },
|
||||
critical_drop => { label => 'critical-drop', exit_value => 'critical' },
|
||||
},
|
||||
output_msg => 'Backend conn. recycles: %.2f',
|
||||
factor => 1, unit => '',
|
||||
},
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"remote" => { name => 'remote' },
|
||||
"ssh-option:s@" => { name => 'ssh_option' },
|
||||
"ssh-path:s" => { name => 'ssh_path' },
|
||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||
"timeout:s" => { name => 'timeout', default => 30 },
|
||||
"sudo" => { name => 'sudo' },
|
||||
"command:s" => { name => 'command', default => 'varnishstat' },
|
||||
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
|
||||
"command-options:s" => { name => 'command_options', default => ' -1 ' },
|
||||
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
|
||||
});
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$self->{instances_done} = {};
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
};
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
};
|
||||
};
|
||||
};
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
};
|
||||
|
||||
sub getdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
||||
options => $self->{option_results},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
|
||||
#print $stdout;
|
||||
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
#client_conn 7390867 1.00 Client connections
|
||||
# - Symbolic entry name
|
||||
# - Value
|
||||
# - Per-second average over process lifetime, or a period if the value can not be averaged
|
||||
# - Descriptive text
|
||||
|
||||
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
|
||||
#print "FOUND: " . $1 . "=" . $2 . "\n";
|
||||
$self->{result}->{$1} = $2;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->getdata();
|
||||
|
||||
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{result}->{last_timestamp} = time();
|
||||
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
# Calculate
|
||||
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
|
||||
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
|
||||
|
||||
|
||||
foreach (keys %{$maps_counters}) {
|
||||
#print $_ . "\n";
|
||||
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
|
||||
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
|
||||
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
|
||||
};
|
||||
|
||||
# Write Cache if not there
|
||||
$self->{statefile_value}->write(data => $self->{result});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
my @exits;
|
||||
foreach (keys %{$maps_counters}) {
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
|
||||
}
|
||||
}
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
|
||||
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . $instance_output if ($num > 1);
|
||||
|
||||
my $str_output = "";
|
||||
my $str_append = '';
|
||||
foreach (keys %{$maps_counters}) {
|
||||
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
|
||||
$str_append = ', ';
|
||||
my ($warning, $critical);
|
||||
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
|
||||
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
|
||||
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
|
||||
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
|
||||
warning => $warning,
|
||||
critical => $critical);
|
||||
}
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_output);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
};
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
||||
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Hostname to query (need --remote).
|
||||
|
||||
=item B<--ssh-option>
|
||||
|
||||
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
|
||||
|
||||
=item B<--command>
|
||||
|
||||
Varnishstat Binary Filename (Default: varnishstat)
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Directory Path to Varnishstat Binary File (Default: /usr/bin)
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Parameter for Binary File (Default: ' -1 ')
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Warning Threshold for:
|
||||
workers => N worker threads,
|
||||
create => N worker threads created,
|
||||
failed => N worker threads not created,
|
||||
max => N worker threads limited,
|
||||
lqueue => work request queue length,
|
||||
queued => N queued work requests,
|
||||
drop => N dropped work requests
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Critical Threshold for:
|
||||
workers => N worker threads,
|
||||
create => N worker threads created,
|
||||
failed => N worker threads not created,
|
||||
max => N worker threads limited,
|
||||
lqueue => work request queue length,
|
||||
queued => N queued work requests,
|
||||
drop => N dropped work requests
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,80 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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 : Florian Asche <info@florian-asche.de>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package apps::varnish::local::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_simple);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
# $options->{options} = options object
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'connections' => 'apps::varnish::local::mode::connections',
|
||||
'cache' => 'apps::varnish::local::mode::cache',
|
||||
'backend' => 'apps::varnish::local::mode::backend',
|
||||
'sessions' => 'apps::varnish::local::mode::sessions',
|
||||
'fetch' => 'apps::varnish::local::mode::fetch',
|
||||
'workers' => 'apps::varnish::local::mode::workers',
|
||||
'totals' => 'apps::varnish::local::mode::totals',
|
||||
'objects' => 'apps::varnish::local::mode::objects',
|
||||
'uptime' => 'apps::varnish::local::mode::uptime',
|
||||
'bans' => 'apps::varnish::local::mode::bans',
|
||||
'dns' => 'apps::varnish::local::mode::dns',
|
||||
'shm' => 'apps::varnish::local::mode::shm',
|
||||
'vcl' => 'apps::varnish::local::mode::vcl',
|
||||
'n' => 'apps::varnish::local::mode::n',
|
||||
'sms' => 'apps::varnish::local::mode::sms',
|
||||
'hcb' => 'apps::varnish::local::mode::hcb',
|
||||
'esi' => 'apps::varnish::local::mode::esi',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check Varnish Cache with varnishstat Command
|
||||
|
||||
=cut
|
|
@ -0,0 +1,149 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package centreon::common::powershell::exchange::2010::activesyncmailbox;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub get_powershell {
|
||||
my (%options) = @_;
|
||||
# options: no_ps
|
||||
my $no_ps = (defined($options{no_ps})) ? 1 : 0;
|
||||
my $no_trust_ssl = (defined($options{no_trust_ssl})) ? '' : '-TrustAnySSLCertificate';
|
||||
|
||||
return '' if ($no_ps == 1);
|
||||
|
||||
my $ps = '
|
||||
$culture = new-object "System.Globalization.CultureInfo" "en-us"
|
||||
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
|
||||
|
||||
If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
|
||||
If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
|
||||
Try {
|
||||
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
|
||||
} Catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
|
||||
# Check to make sure all databases are mounted
|
||||
try {
|
||||
$ErrorActionPreference = "Stop"
|
||||
$username = "' . $options{mailbox} . '"
|
||||
$password = "' . $options{password} . '"
|
||||
$secstr = New-Object -TypeName System.Security.SecureString
|
||||
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
|
||||
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
|
||||
|
||||
$results = Test-ActiveSyncConnectivity -MailboxCredential $cred ' . $no_trust_ssl . '
|
||||
} catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
|
||||
Foreach ($result in $results) {
|
||||
Write-Host "[scenario=" $result.Scenario "][result=" $result.Result "][latency=" $result.Latency.TotalMilliseconds "][[error=" $Result.Error "]]"
|
||||
}
|
||||
exit 0
|
||||
';
|
||||
|
||||
return centreon::plugins::misc::powershell_encoded($ps);
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[scenario= Options ][result= Failure ][latency= 52,00 ][[error=...]]
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "ActiveSync to '" . $options{mailbox} . "' is ok.");
|
||||
|
||||
my $checked = 0;
|
||||
$self->{output}->output_add(long_msg => $options{stdout});
|
||||
while ($options{stdout} =~ /\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) {
|
||||
my ($scenario, $result, $latency, $error) = ($self->{output}->to_utf8($1), centreon::plugins::misc::trim($2),
|
||||
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4));
|
||||
|
||||
$checked++;
|
||||
foreach my $th (('critical', 'warning')) {
|
||||
next if (!defined($self->{thresholds}->{$th}));
|
||||
|
||||
if ($self->{thresholds}->{$th}->{operator} eq '=' &&
|
||||
$result =~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("ActiveSync scenario '%s' to '%s' is '%s'",
|
||||
$scenario, $options{mailbox}, $result));
|
||||
} elsif ($self->{thresholds}->{$th}->{operator} eq '!=' &&
|
||||
$result !~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("ActiveSync scenario '%s' to '%s' is '%s'",
|
||||
$scenario, $options{mailbox}, $result));
|
||||
}
|
||||
}
|
||||
|
||||
if ($latency =~ /^(\d+)/) {
|
||||
$self->{output}->perfdata_add(label => $scenario, unit => 's',
|
||||
value => sprintf("%.3f", $1 / 1000),
|
||||
min => 0);
|
||||
}
|
||||
}
|
||||
|
||||
if ($checked == 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Method to check Exchange 2010 activesync on a specific mailbox.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,284 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package centreon::common::powershell::exchange::2010::databases;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub get_powershell {
|
||||
my (%options) = @_;
|
||||
# options: no_ps, no_mailflow, no_mapi
|
||||
my $no_mailflow = (defined($options{no_mailflow})) ? 1 : 0;
|
||||
my $no_ps = (defined($options{no_ps})) ? 1 : 0;
|
||||
my $no_mapi = (defined($options{no_mapi})) ? 1 : 0;
|
||||
|
||||
return '' if ($no_ps == 1);
|
||||
|
||||
my $ps = '
|
||||
$culture = new-object "System.Globalization.CultureInfo" "en-us"
|
||||
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
|
||||
|
||||
If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
|
||||
If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
|
||||
Try {
|
||||
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
|
||||
} Catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
|
||||
# Check to make sure all databases are mounted
|
||||
try {
|
||||
$ErrorActionPreference = "Stop"
|
||||
';
|
||||
|
||||
if (defined($options{filter_database})) {
|
||||
$ps .= '
|
||||
$MountedDB = Get-MailboxDatabase -Identity "' . $options{filter_database} . '" -Status
|
||||
';
|
||||
} else {
|
||||
$ps .= '
|
||||
$MountedDB = Get-MailboxDatabase -Status
|
||||
';
|
||||
}
|
||||
|
||||
$ps .= '
|
||||
} catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
Foreach ($DB in $MountedDB) {
|
||||
Write-Host "[name=" $DB.Name "][server=" $DB.Server "][mounted=" $DB.Mounted "][size=" $DB.DatabaseSize "][asize=" $DB.AvailableNewMailboxSpace "]" -NoNewline
|
||||
|
||||
';
|
||||
|
||||
if (defined($options{filter_database_test}) && $options{filter_database_test} ne '') {
|
||||
$ps .= '
|
||||
if (!($DB.Name -match "' . $options{filter_database_test} . '")) {
|
||||
Write-Host "[Skip extra test]"
|
||||
continue
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
$ps .= '
|
||||
If ($DB.Mounted -eq $true) {
|
||||
';
|
||||
|
||||
if ($no_mapi == 0) {
|
||||
$ps .= '
|
||||
# Test Mapi Connectivity
|
||||
$MapiResult = test-mapiconnectivity -Database $DB.Name
|
||||
Write-Host "[mapi=" $MapiResult.Result "]" -NoNewline
|
||||
';
|
||||
}
|
||||
|
||||
if ($no_mailflow == 0) {
|
||||
$ps .= '
|
||||
# Test Mailflow
|
||||
$MailflowResult = Test-mailflow -Targetdatabase $DB.Name
|
||||
Write-Host "[mailflow=" $MailflowResult.testmailflowresult "][latency=" $MailflowResult.MessageLatencyTime.TotalMilliseconds "]" -NoNewline
|
||||
';
|
||||
}
|
||||
|
||||
$ps .= '
|
||||
}
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
exit 0
|
||||
';
|
||||
|
||||
return centreon::plugins::misc::powershell_encoded($ps);
|
||||
}
|
||||
|
||||
sub check_mapi {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($self->{option_results}->{no_mapi})) {
|
||||
$self->{output}->output_add(long_msg => ' Skip MAPI test connectivity');
|
||||
return ;
|
||||
}
|
||||
|
||||
if ($options{line} !~ /\[mapi=(.*?)\]/) {
|
||||
$self->{output}->output_add(long_msg => ' Skip MAPI test connectivity (information not found)');
|
||||
return ;
|
||||
}
|
||||
|
||||
my $mapi_result = centreon::plugins::misc::trim($1);
|
||||
|
||||
$self->{output}->output_add(long_msg => " MAPI Test connectivity: " . $mapi_result);
|
||||
foreach my $th (('critical_mapi', 'warning_mapi')) {
|
||||
next if (!defined($self->{thresholds}->{$th}));
|
||||
|
||||
if ($self->{thresholds}->{$th}->{operator} eq '=' &&
|
||||
$mapi_result =~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("Server '%s' Database '%s' MAPI connectivity is %s",
|
||||
$options{server}, $options{database}, $mapi_result));
|
||||
} elsif ($self->{thresholds}->{$th}->{operator} eq '!=' &&
|
||||
$mapi_result !~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("Server '%s' Database '%s' MAPI connectivity is %s",
|
||||
$options{server}, $options{database}, $mapi_result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_mailflow {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($self->{option_results}->{no_mailflow})) {
|
||||
$self->{output}->output_add(long_msg => ' Skip Mailflow test');
|
||||
return ;
|
||||
}
|
||||
|
||||
if ($options{line} !~ /\[mailflow=(.*?)\]\[latency=(.*?)\]/) {
|
||||
$self->{output}->output_add(long_msg => ' Skip Mailflow test (information not found)');
|
||||
return ;
|
||||
}
|
||||
|
||||
my ($mailflow_result, $latency) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2));
|
||||
|
||||
$self->{output}->output_add(long_msg => " Mailflow Test: " . $mailflow_result);
|
||||
foreach my $th (('critical_mailflow', 'warning_mailflow')) {
|
||||
next if (!defined($self->{thresholds}->{$th}));
|
||||
|
||||
if ($self->{thresholds}->{$th}->{operator} eq '=' &&
|
||||
$mailflow_result =~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("Server '%s' Database '%s' Mailflow test is %s",
|
||||
$options{server}, $options{database}, $mailflow_result));
|
||||
} elsif ($self->{thresholds}->{$th}->{operator} eq '!=' &&
|
||||
$mailflow_result !~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("Server '%s' Database '%s' Mailflow test is %s",
|
||||
$options{server}, $options{database}, $mailflow_result));
|
||||
}
|
||||
}
|
||||
|
||||
if ($latency =~ /^(\d+)/) {
|
||||
$self->{output}->perfdata_add(label => 'latency_' . $options{database}, unit => 's',
|
||||
value => sprintf("%.3f", $1 / 1000),
|
||||
min => 0);
|
||||
}
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][mounted= True ][size= 136.1 MB (142,671,872 bytes) ][asize= 124.4 MB (130,482,176 bytes) ][mapi= Success ][mailflow= Success ][latency= 50,00 ]
|
||||
#...
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'Databases are mounted');
|
||||
if (!defined($self->{option_results}->{no_mapi})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'MAPI Connectivities are ok');
|
||||
}
|
||||
if (!defined($self->{option_results}->{no_mailflow})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'Mailflow test are ok');
|
||||
}
|
||||
|
||||
my $checked = 0;
|
||||
foreach my $line (split /\n/, $options{stdout}) {
|
||||
next if ($line !~ /^\[name=(.*?)\]\[server=(.*?)\]\[mounted=(.*?)\]\[size=(.*?)\]\[asize=(.*?)\]/);
|
||||
$checked++;
|
||||
my ($database, $server, $mounted, $size, $asize) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2),
|
||||
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4), centreon::plugins::misc::trim($5));
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Test database '%s' server '%s':", $database, $server));
|
||||
if ($size =~ /\((.*?)\s*bytes/) {
|
||||
my $total_bytes = $1;
|
||||
$total_bytes =~ s/[.,]//g;
|
||||
$self->{output}->perfdata_add(label => 'size_' . $database, unit => 'B',
|
||||
value => $total_bytes,
|
||||
min => 0);
|
||||
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_bytes);
|
||||
$self->{output}->output_add(long_msg => sprintf(" Size %s", $total_value . ' ' . $total_unit));
|
||||
}
|
||||
if ($asize =~ /\((.*?)\s*bytes/) {
|
||||
my $total_bytes = $1;
|
||||
$total_bytes =~ s/[.,]//g;
|
||||
$self->{output}->perfdata_add(label => 'asize_' . $database, unit => 'B',
|
||||
value => $total_bytes,
|
||||
min => 0);
|
||||
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_bytes);
|
||||
$self->{output}->output_add(long_msg => sprintf(" Available Size %s", $total_value . ' ' . $total_unit));
|
||||
}
|
||||
|
||||
|
||||
# Check mounted
|
||||
if ($mounted =~ /False/i) {
|
||||
$self->{output}->output_add(long_msg => sprintf(" not mounted\n Skip mapi/mailflow test"));
|
||||
$self->{output}->output_add(short_msg => 'CRITICAL',
|
||||
long_msg => sprintf("Database '%s' server '%s' is not mounted", $database, $server));
|
||||
next;
|
||||
}
|
||||
$self->{output}->output_add(long_msg => sprintf(" mounted"));
|
||||
|
||||
check_mapi($self, database => $database, server => $server, line => $line);
|
||||
check_mailflow($self, database => $database, server => $server, line => $line);
|
||||
}
|
||||
|
||||
if ($checked == 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Method to check Exchange 2010 databases.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,148 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package centreon::common::powershell::exchange::2010::imapmailbox;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub get_powershell {
|
||||
my (%options) = @_;
|
||||
# options: no_ps
|
||||
my $no_ps = (defined($options{no_ps})) ? 1 : 0;
|
||||
|
||||
return '' if ($no_ps == 1);
|
||||
|
||||
my $ps = '
|
||||
$culture = new-object "System.Globalization.CultureInfo" "en-us"
|
||||
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
|
||||
|
||||
If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
|
||||
If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
|
||||
Try {
|
||||
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
|
||||
} Catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
|
||||
# Check to make sure all databases are mounted
|
||||
try {
|
||||
$ErrorActionPreference = "Stop"
|
||||
$username = "' . $options{mailbox} . '"
|
||||
$password = "' . $options{password} . '"
|
||||
$secstr = New-Object -TypeName System.Security.SecureString
|
||||
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
|
||||
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
|
||||
|
||||
$results = Test-ImapConnectivity -MailboxCredential $cred
|
||||
} catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
|
||||
Foreach ($result in $results) {
|
||||
Write-Host "[scenario=" $result.Scenario "][result=" $result.Result "][latency=" $result.Latency.TotalMilliseconds "][[error=" $Result.Error "]]"
|
||||
}
|
||||
exit 0
|
||||
';
|
||||
|
||||
return centreon::plugins::misc::powershell_encoded($ps);
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[scenario= Options ][result= Failure ][latency= 52,00 ][[error=...]]
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Imap to '" . $options{mailbox} . "' is ok.");
|
||||
|
||||
my $checked = 0;
|
||||
$self->{output}->output_add(long_msg => $options{stdout});
|
||||
while ($options{stdout} =~ /\[scenario=(.*?)\]\[result=(.*?)\]\[latency=(.*?)\]\[\[error=(.*?)\]\]/msg) {
|
||||
my ($scenario, $result, $latency, $error) = ($self->{output}->to_utf8($1), centreon::plugins::misc::trim($2),
|
||||
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4));
|
||||
|
||||
$checked++;
|
||||
foreach my $th (('critical', 'warning')) {
|
||||
next if (!defined($self->{thresholds}->{$th}));
|
||||
|
||||
if ($self->{thresholds}->{$th}->{operator} eq '=' &&
|
||||
$result =~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("Imap scenario '%s' to '%s' is '%s'",
|
||||
$scenario, $options{mailbox}, $result));
|
||||
} elsif ($self->{thresholds}->{$th}->{operator} eq '!=' &&
|
||||
$result !~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("Imap scenario '%s' to '%s' is '%s'",
|
||||
$scenario, $options{mailbox}, $result));
|
||||
}
|
||||
}
|
||||
|
||||
if ($latency =~ /^(\d+)/) {
|
||||
$self->{output}->perfdata_add(label => $scenario, unit => 's',
|
||||
value => sprintf("%.3f", $1 / 1000),
|
||||
min => 0);
|
||||
}
|
||||
}
|
||||
|
||||
if ($checked == 0) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Method to check Exchange 2010 imap on a specific mailbox.
|
||||
|
||||
=cut
|
|
@ -0,0 +1,132 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2014 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package centreon::common::powershell::exchange::2010::mapimailbox;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub get_powershell {
|
||||
my (%options) = @_;
|
||||
# options: no_ps
|
||||
my $no_ps = (defined($options{no_ps})) ? 1 : 0;
|
||||
|
||||
return '' if ($no_ps == 1);
|
||||
|
||||
my $ps = '
|
||||
$culture = new-object "System.Globalization.CultureInfo" "en-us"
|
||||
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
|
||||
|
||||
If (@(Get-PSSnapin -Registered | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 1) {
|
||||
If (@(Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"} ).count -eq 0) {
|
||||
Try {
|
||||
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
|
||||
} Catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "Snap-In no present or not registered"
|
||||
exit 1
|
||||
}
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
|
||||
# Check to make sure all databases are mounted
|
||||
try {
|
||||
$ErrorActionPreference = "Stop"
|
||||
$mapi = test-mapiconnectivity -Identity "' . $options{mailbox} . '"
|
||||
} catch {
|
||||
Write-Host $Error[0].Exception
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "[name=" $mapi.Database "][server=" $mapi.Server "][result=" $mapi.Result "][error=" $mapi.Error "]"
|
||||
|
||||
exit 0
|
||||
';
|
||||
|
||||
return centreon::plugins::misc::powershell_encoded($ps);
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
# options: stdout
|
||||
|
||||
# Following output:
|
||||
#[name= Mailbox Database 0975194476 ][server= SRVI-WIN-TEST ][result= Success ][error=...]
|
||||
|
||||
if ($options{stdout} !~ /^\[name=(.*?)\]\[server=(.*?)\]\[result=(.*?)\]\[error=(.*)\]$/) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => 'Cannot find informations');
|
||||
return ;
|
||||
}
|
||||
my ($database, $server, $result, $error) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2),
|
||||
centreon::plugins::misc::trim($3), centreon::plugins::misc::trim($4));
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "MAPI connection to '" . $options{mailbox} . "' is '" . $result . "'.");
|
||||
$self->{output}->output_add(long_msg => sprintf("Database: %s, Server: %s\nError: %s",
|
||||
$database, $server, $error));
|
||||
foreach my $th (('critical_mapi', 'warning_mapi')) {
|
||||
next if (!defined($self->{thresholds}->{$th}));
|
||||
|
||||
if ($self->{thresholds}->{$th}->{operator} eq '=' &&
|
||||
$result =~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("MAPI connection to '%s' is '%s'",
|
||||
$options{mailbox}, $result));
|
||||
} elsif ($self->{thresholds}->{$th}->{operator} eq '!=' &&
|
||||
$result !~ /$self->{thresholds}->{$th}->{state}/) {
|
||||
$self->{output}->output_add(severity => $self->{thresholds}->{$th}->{out},
|
||||
short_msg => sprintf("MAPI connection to '%s' is '%s'",
|
||||
$options{mailbox}, $result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Method to check Exchange 2010 mapi connection on a specific mailbox.
|
||||
|
||||
=cut
|
|
@ -63,6 +63,7 @@ sub new {
|
|||
{ "datasource:s@" => { name => 'data_source' },
|
||||
"username:s@" => { name => 'username' },
|
||||
"password:s@" => { name => 'password' },
|
||||
"connect-options:s@" => { name => 'connect_options' },
|
||||
"sql-errors-exit:s" => { name => 'sql_errors_exit', default => 'unknown' },
|
||||
});
|
||||
}
|
||||
|
@ -77,6 +78,8 @@ sub new {
|
|||
$self->{data_source} = undef;
|
||||
$self->{username} = undef;
|
||||
$self->{password} = undef;
|
||||
$self->{connect_options} = undef;
|
||||
$self->{connect_options_hash} = {};
|
||||
|
||||
# Sometimes, we need to set ENV
|
||||
$self->{env} = undef;
|
||||
|
@ -119,6 +122,7 @@ sub check_options {
|
|||
$self->{data_source} = (defined($self->{option_results}->{data_source})) ? shift(@{$self->{option_results}->{data_source}}) : undef;
|
||||
$self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : undef;
|
||||
$self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : undef;
|
||||
$self->{connect_options} = (defined($self->{option_results}->{connect_options})) ? shift(@{$self->{option_results}->{connect_options}}) : undef;
|
||||
$self->{env} = (defined($self->{option_results}->{env})) ? shift(@{$self->{option_results}->{env}}) : undef;
|
||||
$self->{sql_errors_exit} = $self->{option_results}->{sql_errors_exit};
|
||||
|
||||
|
@ -126,6 +130,15 @@ sub check_options {
|
|||
$self->{output}->add_option_msg(short_msg => "Need to specify data_source arguments.");
|
||||
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||
}
|
||||
if (defined($self->{connect_options}) && $self->{connect_options} ne '') {
|
||||
foreach my $entry (split /,/, $self->{connect_options}) {
|
||||
if ($entry !~ /^\s*([^=]+)=([^=]+)\s*$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong format for --connect-options '" . $entry . "'.");
|
||||
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
|
||||
}
|
||||
$self->{connect_options_hash}->{$1} = $2;
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@{$self->{option_results}->{data_source}}) == 0) {
|
||||
return 0;
|
||||
|
@ -175,7 +188,7 @@ sub connect {
|
|||
"DBI:". $self->{data_source},
|
||||
$self->{username},
|
||||
$self->{password},
|
||||
{ "RaiseError" => 0, "PrintError" => 0, "AutoCommit" => 1 }
|
||||
{ "RaiseError" => 0, "PrintError" => 0, "AutoCommit" => 1, %{$self->{connect_options_hash}} }
|
||||
);
|
||||
|
||||
if (!defined($self->{instance})) {
|
||||
|
@ -264,6 +277,11 @@ Database username.
|
|||
|
||||
Database password.
|
||||
|
||||
=item B<--connect-options>
|
||||
|
||||
Add options in database connect.
|
||||
Format: name=value,name2=value2,...
|
||||
|
||||
=item B<--sql-errors-exit>
|
||||
|
||||
Exit code for DB Errors (default: unknown)
|
||||
|
|
|
@ -34,27 +34,48 @@
|
|||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package apps::apache::serverstatus::mode::libconnect;
|
||||
package centreon::plugins::httplib;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use LWP::UserAgent;
|
||||
|
||||
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};
|
||||
} else {
|
||||
$cache_port = 80 if ($self->{option_results}->{proto} eq 'http');
|
||||
$cache_port = 443 if ($self->{option_results}->{proto} eq 'https');
|
||||
}
|
||||
|
||||
return $cache_port;
|
||||
}
|
||||
|
||||
sub connect {
|
||||
my ($self, %options) = @_;
|
||||
my $ua = LWP::UserAgent->new( 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});
|
||||
my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown';
|
||||
|
||||
my ($response, $content);
|
||||
my $req;
|
||||
|
||||
my $req = HTTP::Request->new( GET => $self->{option_results}->{proto}."://" .$self->{option_results}->{hostname}.':'.$self->{option_results}->{port}.'/server-status');
|
||||
|
||||
if (defined($self->{option_results}->{credentials})) {
|
||||
if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} =~ /^[0-9]+$/) {
|
||||
$req = HTTP::Request->new( GET => $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname}.':'. $self->{option_results}->{port} . $self->{option_results}->{url_path});
|
||||
} else {
|
||||
$req = HTTP::Request->new( GET => $self->{option_results}->{proto}. "://" . $self->{option_results}->{hostname} . $self->{option_results}->{url_path});
|
||||
}
|
||||
|
||||
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});
|
||||
$ua->proxy(['http', 'https'], $self->{option_results}->{proxyurl});
|
||||
}
|
||||
|
||||
$response = $ua->request($req);
|
||||
|
@ -71,4 +92,3 @@ sub connect {
|
|||
}
|
||||
|
||||
1;
|
||||
|
|
@ -37,6 +37,7 @@ package centreon::plugins::misc;
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
# Function more simple for Windows platform
|
||||
sub windows_execute {
|
||||
|
@ -50,11 +51,11 @@ sub windows_execute {
|
|||
$cmd .= $options{command_options} if (defined($options{command_options}));
|
||||
|
||||
eval {
|
||||
local $SIG{ALRM} = sub { die "Timeout by signal ALARM\n"; };
|
||||
alarm( $options{timeout} );
|
||||
$stdout = `$cmd`;
|
||||
$exit_code = ($? >> 8);
|
||||
alarm(0);
|
||||
local $SIG{ALRM} = sub { die "Timeout by signal ALARM\n"; };
|
||||
alarm( $options{timeout} );
|
||||
$stdout = `$cmd`;
|
||||
$exit_code = ($? >> 8);
|
||||
alarm(0);
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
|
@ -183,6 +184,8 @@ sub backtick {
|
|||
$sig_do = 'DEFAULT';
|
||||
}
|
||||
local $SIG{CHLD} = $sig_do;
|
||||
$SIG{TTOU} = 'IGNORE';
|
||||
$| = 1;
|
||||
|
||||
if (!defined($pid = open( KID, "-|" ))) {
|
||||
return (-1001, "Cant fork: $!", -1);
|
||||
|
@ -220,6 +223,7 @@ sub backtick {
|
|||
# child
|
||||
# set the child process to be a group leader, so that
|
||||
# kill -9 will kill it and all its descendents
|
||||
# We have ignore SIGTTOU to let write background processes
|
||||
setpgrp( 0, 0 );
|
||||
|
||||
if ($arg{redirect_stderr} == 1) {
|
||||
|
@ -247,6 +251,41 @@ sub trim {
|
|||
return $value;
|
||||
}
|
||||
|
||||
sub powershell_encoded {
|
||||
my ($value) = $_[0];
|
||||
|
||||
require Encode;
|
||||
require MIME::Base64;
|
||||
my $bytes = Encode::encode("utf16LE", $value);
|
||||
my $script = MIME::Base64::encode_base64($bytes, "\n");
|
||||
$script =~ s/\n//g;
|
||||
return $script;
|
||||
}
|
||||
|
||||
sub minimal_version {
|
||||
my ($version_src, $version_dst) = @_;
|
||||
|
||||
# No Version. We skip
|
||||
|
||||
if (!defined($version_src) || !defined($version_dst) ||
|
||||
$version_src !~ /^[0-9]+(?:\.[0-9\.])*$/ || $version_dst !~ /^[0-9x]+(?:\.[0-9x\.])*$/) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
my @version_src = split /\./, $version_src;
|
||||
my @versions = split /\./, $version_dst;
|
||||
for (my $i = 0; $i < scalar(@versions); $i++) {
|
||||
return 1 if ($versions[$i] eq 'x');
|
||||
return 1 if (!defined($version_src[$i]));
|
||||
$version_src[$i] =~ /^([0-9]*)/;
|
||||
next if ($versions[$i] == int($1));
|
||||
return 0 if ($versions[$i] > int($1));
|
||||
return 1 if ($versions[$i] < int($1));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
|
|
@ -34,11 +34,14 @@
|
|||
####################################################################################
|
||||
|
||||
package centreon::plugins::options;
|
||||
|
||||
use Pod::Usage;
|
||||
use Pod::Find qw(pod_where);
|
||||
use Getopt::Long;
|
||||
Getopt::Long::Configure("pass_through");
|
||||
Getopt::Long::Configure('bundling');
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
|
@ -61,9 +64,9 @@ sub set_output {
|
|||
sub display_help {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $stdout;
|
||||
foreach (@{$self->{pod_package}}) {
|
||||
my $stdout;
|
||||
|
||||
|
||||
{
|
||||
local *STDOUT;
|
||||
open STDOUT, '>', \$stdout;
|
||||
|
@ -88,9 +91,9 @@ sub add_help {
|
|||
}
|
||||
|
||||
if (defined($options{help_first})) {
|
||||
shift @{$self->{pod_package}}, {package => $options{package}, sections => $options{sections}};
|
||||
unshift @{$self->{pod_package}}, {package => $options{package}, sections => $options{sections}};
|
||||
} else {
|
||||
push @{$self->{pod_package}}, {package => $options{package}, sections => $options{sections}};
|
||||
push @{$self->{pod_package}}, { package => $options{package}, sections => $options{sections} };
|
||||
}
|
||||
|
||||
$self->{pod_packages_once}->{$options{package}} = 1;
|
||||
|
|
|
@ -34,8 +34,10 @@
|
|||
####################################################################################
|
||||
|
||||
package centreon::plugins::output;
|
||||
use Encode;
|
||||
|
||||
use centreon::plugins::misc;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -49,6 +51,8 @@ sub new {
|
|||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"explode-perfdata-max:s@" => { name => 'explode_perfdata_max' },
|
||||
"range-perfdata:s" => { name => 'range_perfdata' },
|
||||
"filter-perfdata:s" => { name => 'filter_perfdata' },
|
||||
"verbose" => { name => 'verbose' },
|
||||
"opt-exit:s" => { name => 'opt_exit', default => 'unknown' },
|
||||
|
@ -70,7 +74,12 @@ sub new {
|
|||
$self->{global_short_outputs} = {OK => [], WARNING => [], CRITICAL => [], UNKNOWN => [], UNQUALIFIED_YET => []};
|
||||
$self->{global_long_output} = [];
|
||||
$self->{perfdatas} = [];
|
||||
$self->{explode_perfdatas} = {};
|
||||
$self->{explode_perfdata_total} = 0;
|
||||
$self->{range_perfdata} = 0;
|
||||
$self->{global_status} = 0;
|
||||
$self->{encode_utf8_import} = 0;
|
||||
$self->{perlqq} = 0;
|
||||
|
||||
$self->{disco_elements} = [];
|
||||
$self->{disco_entries} = [];
|
||||
|
@ -98,6 +107,31 @@ sub check_options {
|
|||
$self->{option_results}->{output_xml} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{range_perfdata})) {
|
||||
$self->{range_perfdata} = $self->{option_results}->{range_perfdata};
|
||||
$self->{range_perfdata} = 1 if ($self->{range_perfdata} eq '');
|
||||
if ($self->{range_perfdata} !~ /^[012]$/) {
|
||||
$self->add_option_msg(short_msg => "Wrong range-perfdata option '" . $self->{range_perfdata} . "'");
|
||||
$self->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{explode_perfdata_max})) {
|
||||
if (${$self->{option_results}->{explode_perfdata_max}}[0] eq '') {
|
||||
$self->{explode_perfdata_total} = 2;
|
||||
} else {
|
||||
$self->{explode_perfdata_total} = 1;
|
||||
foreach (@{$self->{option_results}->{explode_perfdata_max}}) {
|
||||
my ($perf_match, $perf_result) = split /,/;
|
||||
if (!defined($perf_result)) {
|
||||
$self->add_option_msg(short_msg => "Wrong explode-perfdata-max option '" . $_ . "' (syntax: match,value)");
|
||||
$self->option_exit();
|
||||
}
|
||||
$self->{explode_perfdatas}->{$perf_match} = $perf_result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub add_option_msg {
|
||||
|
@ -150,13 +184,52 @@ sub output_add {
|
|||
sub perfdata_add {
|
||||
my ($self, %options) = @_;
|
||||
my $perfdata = {'label' => '', 'value' => '', unit => '', warning => '', critical => '', min => '', max => ''};
|
||||
$perfdata = {%$perfdata, %options};
|
||||
foreach (keys %options) {
|
||||
next if (!defined($options{$_}));
|
||||
$perfdata->{$_} = $options{$_};
|
||||
}
|
||||
$perfdata->{label} =~ s/'/''/g;
|
||||
push @{$self->{perfdatas}}, $perfdata;
|
||||
}
|
||||
|
||||
sub explode_perfdatas {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if ($self->{explode_perfdata_total} == 0);
|
||||
foreach (@{$self->{perfdatas}}) {
|
||||
next if ($_->{max} eq '');
|
||||
if ($self->{explode_perfdata_total} == 2) {
|
||||
$self->perfdata_add(label => $_->{label} . '_max', value => $_->{max});
|
||||
next;
|
||||
}
|
||||
foreach my $regexp (keys %{$self->{explode_perfdatas}}) {
|
||||
if ($_->{label} =~ /$regexp/) {
|
||||
$self->perfdata_add(label => $self->{explode_perfdatas}->{$regexp}, value => $_->{max});
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub range_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if ($self->{range_perfdata} == 0);
|
||||
if ($self->{range_perfdata} == 1) {
|
||||
for (my $i = 0; $i < scalar(@{$options{ranges}}); $i++) {
|
||||
${${$options{ranges}}[$i]} =~ s/^(@?)-?[0\.]+:/$1/;
|
||||
}
|
||||
} else {
|
||||
for (my $i = 0; $i < scalar(@{$options{ranges}}); $i++) {
|
||||
${${$options{ranges}}[$i]} = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub output_json {
|
||||
my ($self, %options) = @_;
|
||||
my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
|
||||
my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0;
|
||||
my $json_content = {plugin => {
|
||||
name => $self->{plugin},
|
||||
mode => $self->{mode},
|
||||
|
@ -179,7 +252,7 @@ sub output_json {
|
|||
}
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{verbose}) || defined($options{force_long_output})) {
|
||||
if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) {
|
||||
foreach (@{$self->{global_long_output}}) {
|
||||
push @{$json_content->{plugin}->{outputs}}, {
|
||||
type => 2,
|
||||
|
@ -189,13 +262,15 @@ sub output_json {
|
|||
}
|
||||
|
||||
if ($options{force_ignore_perfdata} == 0) {
|
||||
foreach (@{$self->{perfdatas}}) {
|
||||
$self->explode_perfdatas();
|
||||
foreach my $perf (@{$self->{perfdatas}}) {
|
||||
next if (defined($self->{option_results}->{filter_perfdata}) &&
|
||||
$_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
|
||||
$perf->{label} !~ /$self->{option_results}->{filter_perfdata}/);
|
||||
$self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]);
|
||||
|
||||
my %values = ();
|
||||
foreach my $key (keys %$_) {
|
||||
$values{$key} = $_->{$key};
|
||||
foreach my $key (keys %$perf) {
|
||||
$values{$key} = $perf->{$key};
|
||||
}
|
||||
|
||||
push @{$json_content->{plugin}->{perfdatas}}, {
|
||||
|
@ -210,6 +285,7 @@ sub output_json {
|
|||
sub output_xml {
|
||||
my ($self, %options) = @_;
|
||||
my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
|
||||
my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0;
|
||||
my ($child_plugin_name, $child_plugin_mode, $child_plugin_exit, $child_plugin_output, $child_plugin_perfdata);
|
||||
|
||||
my $root = $self->{xml_output}->createElement('plugin');
|
||||
|
@ -255,7 +331,7 @@ sub output_xml {
|
|||
}
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{verbose}) || defined($options{force_long_output})) {
|
||||
if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) {
|
||||
foreach (@{$self->{global_long_output}}) {
|
||||
my ($child_output, $child_type, $child_msg);
|
||||
|
||||
|
@ -274,16 +350,18 @@ sub output_xml {
|
|||
}
|
||||
|
||||
if ($options{force_ignore_perfdata} == 0) {
|
||||
foreach (@{$self->{perfdatas}}) {
|
||||
$self->explode_perfdatas();
|
||||
foreach my $perf (@{$self->{perfdatas}}) {
|
||||
next if (defined($self->{option_results}->{filter_perfdata}) &&
|
||||
$_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
|
||||
$perf->{label} !~ /$self->{option_results}->{filter_perfdata}/);
|
||||
$self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]);
|
||||
|
||||
my ($child_perfdata);
|
||||
$child_perfdata = $self->{xml_output}->createElement("perfdata");
|
||||
$child_plugin_perfdata->addChild($child_perfdata);
|
||||
foreach my $key (keys %$_) {
|
||||
foreach my $key (keys %$perf) {
|
||||
my $child = $self->{xml_output}->createElement($key);
|
||||
$child->appendText($_->{$key});
|
||||
$child->appendText($perf->{$key});
|
||||
$child_perfdata->addChild($child);
|
||||
}
|
||||
}
|
||||
|
@ -295,6 +373,7 @@ sub output_xml {
|
|||
sub output_txt {
|
||||
my ($self, %options) = @_;
|
||||
my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
|
||||
my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0;
|
||||
|
||||
if (defined($self->{global_short_concat_outputs}->{UNQUALIFIED_YET})) {
|
||||
$self->output_add(severity => uc($options{exit_litteral}), short_msg => $self->{global_short_concat_outputs}->{UNQUALIFIED_YET});
|
||||
|
@ -310,22 +389,24 @@ sub output_txt {
|
|||
print (($options{nolabel} == 0 ? 'UNKNOWN: ' : '') . $self->{global_short_concat_outputs}->{UNKNOWN} . " ");
|
||||
}
|
||||
if (uc($options{exit_litteral}) eq 'OK') {
|
||||
print (($options{nolabel} == 0 ? 'OK: ' : '') . $self->{global_short_concat_outputs}->{OK} . " ");
|
||||
print (($options{nolabel} == 0 ? 'OK: ' : '') . (defined($self->{global_short_concat_outputs}->{OK}) ? $self->{global_short_concat_outputs}->{OK} : '') . " ");
|
||||
}
|
||||
|
||||
if ($force_ignore_perfdata == 1) {
|
||||
print "\n";
|
||||
} else {
|
||||
print "|";
|
||||
foreach (@{$self->{perfdatas}}) {
|
||||
$self->explode_perfdatas();
|
||||
foreach my $perf (@{$self->{perfdatas}}) {
|
||||
next if (defined($self->{option_results}->{filter_perfdata}) &&
|
||||
$_->{label} !~ /$self->{option_results}->{filter_perfdata}/);
|
||||
print " '" . $_->{label} . "'=" . $_->{value} . $_->{unit} . ";" . $_->{warning} . ";" . $_->{critical} . ";" . $_->{min} . ";" . $_->{max};
|
||||
$perf->{label} !~ /$self->{option_results}->{filter_perfdata}/);
|
||||
$self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]);
|
||||
print " '" . $perf->{label} . "'=" . $perf->{value} . $perf->{unit} . ";" . $perf->{warning} . ";" . $perf->{critical} . ";" . $perf->{min} . ";" . $perf->{max};
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{verbose}) || defined($options{force_long_output})) {
|
||||
if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) {
|
||||
if (scalar(@{$self->{global_long_output}})) {
|
||||
print join("\n", @{$self->{global_long_output}});
|
||||
print "\n";
|
||||
|
@ -337,25 +418,29 @@ sub display {
|
|||
my ($self, %options) = @_;
|
||||
my $nolabel = defined($options{nolabel}) ? 1 : 0;
|
||||
my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0;
|
||||
my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0;
|
||||
|
||||
if (defined($self->{option_results}->{output_xml})) {
|
||||
$self->create_xml_document();
|
||||
if ($self->{is_output_xml}) {
|
||||
$self->output_xml(exit_litteral => $self->get_litteral_status(),
|
||||
nolabel => $nolabel, force_ignore_perfdata => $force_ignore_perfdata);
|
||||
nolabel => $nolabel,
|
||||
force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output);
|
||||
return ;
|
||||
}
|
||||
} elsif (defined($self->{option_results}->{output_json})) {
|
||||
$self->create_json_document();
|
||||
if ($self->{is_output_json}) {
|
||||
$self->output_json(exit_litteral => $self->get_litteral_status(),
|
||||
nolabel => $nolabel, force_ignore_perfdata => $force_ignore_perfdata);
|
||||
nolabel => $nolabel,
|
||||
force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
$self->output_txt(exit_litteral => $self->get_litteral_status(),
|
||||
nolabel => $nolabel, force_ignore_perfdata => $force_ignore_perfdata);
|
||||
nolabel => $nolabel,
|
||||
force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output);
|
||||
}
|
||||
|
||||
sub die_exit {
|
||||
|
@ -484,7 +569,8 @@ sub is_litteral_status {
|
|||
sub create_json_document {
|
||||
my ($self) = @_;
|
||||
|
||||
require JSON;
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'JSON',
|
||||
error_msg => "Cannot load module 'JSON'.");
|
||||
$self->{is_output_json} = 1;
|
||||
$self->{json_output} = JSON->new->utf8();
|
||||
}
|
||||
|
@ -492,7 +578,8 @@ sub create_json_document {
|
|||
sub create_xml_document {
|
||||
my ($self) = @_;
|
||||
|
||||
require XML::LibXML;
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'XML::LibXML',
|
||||
error_msg => "Cannot load module 'XML::LibXML'.");
|
||||
$self->{is_output_xml} = 1;
|
||||
$self->{xml_output} = XML::LibXML::Document->new('1.0', 'utf-8');
|
||||
}
|
||||
|
@ -586,7 +673,18 @@ sub display_disco_show {
|
|||
sub to_utf8 {
|
||||
my ($self, $value) = @_;
|
||||
|
||||
return centreon::plugins::misc::trim(Encode::decode('UTF-8', $value, Encode::PERLQQ));
|
||||
if ($self->{encode_utf8_import} == 0) {
|
||||
|
||||
|
||||
# Some Perl version dont have the following module (like Perl 5.6.x)
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Encode',
|
||||
error_msg => "Cannot load module 'Encode'.");
|
||||
|
||||
$self->{encode_utf8_import} = 1;
|
||||
eval '$self->{perlqq} = Encode::PERLQQ';
|
||||
}
|
||||
|
||||
return centreon::plugins::misc::trim(Encode::decode('UTF-8', $value, $self->{perlqq}));
|
||||
}
|
||||
|
||||
sub add_disco_entry {
|
||||
|
@ -598,7 +696,7 @@ sub add_disco_entry {
|
|||
sub is_disco_format {
|
||||
my ($self) = @_;
|
||||
|
||||
if (defined($self->{option_results}->{disco_format}) ) {
|
||||
if (defined($self->{option_results}->{disco_format})) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -607,7 +705,7 @@ sub is_disco_format {
|
|||
sub is_disco_show {
|
||||
my ($self) = @_;
|
||||
|
||||
if ( defined($self->{option_results}->{disco_show}) ) {
|
||||
if (defined($self->{option_results}->{disco_show})) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -637,6 +735,16 @@ Display long output.
|
|||
|
||||
Filter perfdata that match the regexp.
|
||||
|
||||
=item B<--explode-perfdata-max>
|
||||
|
||||
Put max perfdata (if it exist) in a specific perfdata
|
||||
(without values: same with '_max' suffix)
|
||||
|
||||
=item B<--range-perfdata>
|
||||
|
||||
Change perfdata range thresholds display:
|
||||
1 = start value equals to '0' is removed, 2 = threshold range is not display.
|
||||
|
||||
=item B<--opt-exit>
|
||||
|
||||
Exit code for an option error, usage (default: unknown).
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
|
||||
package centreon::plugins::perfdata;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = {};
|
||||
|
@ -52,18 +55,34 @@ sub get_perfdata_for_output {
|
|||
# $options{label} : threshold label
|
||||
# $options{total} : percent threshold to transform in global
|
||||
# $options{cast_int} : cast absolute to int
|
||||
# $options{op} : operator to apply to start/end value (uses with 'value'})
|
||||
# $options{value} : value to apply with 'op' option
|
||||
|
||||
my $perf_output = $self->{threshold_label}->{$options{label}}->{value};
|
||||
if (defined($perf_output) && $perf_output ne '' && defined($options{total})) {
|
||||
$perf_output = ($self->{threshold_label}->{$options{label}}->{arobase} == 1 ? "@" : "") .
|
||||
(($self->{threshold_label}->{$options{label}}->{infinite_neg} == 0) ? (defined($options{cast_int}) ? sprintf("%d", ($self->{threshold_label}->{$options{label}}->{start} * $options{total} / 100)) : sprintf("%.2f", ($self->{threshold_label}->{$options{label}}->{start} * $options{total} / 100))) : "") .
|
||||
":" .
|
||||
(($self->{threshold_label}->{$options{label}}->{infinite_pos} == 0) ? (defined($options{cast_int}) ? sprintf("%d", ($self->{threshold_label}->{$options{label}}->{end} * $options{total} / 100)) : sprintf("%.2f", ($self->{threshold_label}->{$options{label}}->{end} * $options{total} / 100))) : "");
|
||||
if (!defined($self->{threshold_label}->{$options{label}}->{value}) || $self->{threshold_label}->{$options{label}}->{value} eq '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
my %perf_value = %{$self->{threshold_label}->{$options{label}}};
|
||||
|
||||
if (defined($options{op}) && defined($options{value})) {
|
||||
eval "\$perf_value{start} = \$perf_value{start} $options{op} \$options{value}" if ($perf_value{infinite_neg} == 0);
|
||||
eval "\$perf_value{end} = \$perf_value{end} $options{op} \$options{value}" if ($perf_value{infinite_pos} == 0);
|
||||
}
|
||||
if (defined($options{total})) {
|
||||
$perf_value{start} = $perf_value{start} * $options{total} / 100 if ($perf_value{infinite_neg} == 0);
|
||||
$perf_value{end} = $perf_value{end} * $options{total} / 100 if ($perf_value{infinite_pos} == 0);
|
||||
$perf_value{start} = sprintf("%.2f", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && !defined($options{cast_int}));
|
||||
$perf_value{end} = sprintf("%.2f", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && !defined($options{cast_int}));
|
||||
}
|
||||
|
||||
$perf_value{start} = sprintf("%d", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && defined($options{cast_int}));
|
||||
$perf_value{end} = sprintf("%d", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && defined($options{cast_int}));
|
||||
|
||||
my $perf_output = ($perf_value{arobase} == 1 ? "@" : "") .
|
||||
(($perf_value{infinite_neg} == 0) ? $perf_value{start} : "~") .
|
||||
":" .
|
||||
(($perf_value{infinite_pos} == 0) ? $perf_value{end} : "");
|
||||
|
||||
if (!defined($perf_output)) {
|
||||
$perf_output = '';
|
||||
}
|
||||
return $perf_output;
|
||||
}
|
||||
|
||||
|
@ -93,7 +112,7 @@ sub threshold_check {
|
|||
next if (!defined($self->{threshold_label}->{$_->{label}}->{value}) || $self->{threshold_label}->{$_->{label}}->{value} eq '');
|
||||
if ($self->{threshold_label}->{$_->{label}}->{arobase} == 0 && ($options{value} < $self->{threshold_label}->{$_->{label}}->{start} || $options{value} > $self->{threshold_label}->{$_->{label}}->{end})) {
|
||||
return $_->{exit_litteral};
|
||||
} elsif ($self->{threshold_label}->{$_->{label}}->{arobase} == 1 && ($options{value} >= $self->{threshold_label}->{$_->{label}}->{end} && $options{value} <= $self->{threshold_label}->{$_->{label}}->{end})) {
|
||||
} elsif ($self->{threshold_label}->{$_->{label}}->{arobase} == 1 && ($options{value} >= $self->{threshold_label}->{$_->{label}}->{start} && $options{value} <= $self->{threshold_label}->{$_->{label}}->{end})) {
|
||||
return $_->{exit_litteral};
|
||||
}
|
||||
}
|
||||
|
@ -109,42 +128,10 @@ sub trim {
|
|||
return $value;
|
||||
}
|
||||
|
||||
sub continue_to {
|
||||
my $self = shift;
|
||||
my ($forbidden, $stop1, $not_stop_after) = @_;
|
||||
my $value = "";
|
||||
|
||||
while ($self->{perfdata_pos} < $self->{perfdata_size}) {
|
||||
if (defined($forbidden) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] =~ /$forbidden/) {
|
||||
return undef;
|
||||
}
|
||||
if (${$self->{perfdata_chars}}[$self->{perfdata_pos}] =~ /$stop1/) {
|
||||
if (!defined($not_stop_after)) {
|
||||
return $value;
|
||||
}
|
||||
if (!($self->{perfdata_pos} + 1 < $self->{perfdata_size} && ${$self->{perfdata_chars}}[$self->{perfdata_pos} + 1] =~ /$not_stop_after/)) {
|
||||
$self->{perfdata_pos}++;
|
||||
return $value;
|
||||
}
|
||||
$self->{perfdata_pos}++;
|
||||
}
|
||||
|
||||
$value .= ${$self->{perfdata_chars}}[$self->{perfdata_pos}];
|
||||
$self->{perfdata_pos}++;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
sub parse_threshold {
|
||||
my $self = shift;
|
||||
|
||||
@{$self->{perfdata_chars}} = split //, $self->trim($_[0]);
|
||||
$self->{perfdata_pos} = 0;
|
||||
$self->{perfdata_size} = scalar(@{$self->{perfdata_chars}});
|
||||
|
||||
my $neg = 1;
|
||||
my $value_tmp = "";
|
||||
my $perf = $self->trim($_[0]);
|
||||
|
||||
my $arobase = 0;
|
||||
my $infinite_neg = 0;
|
||||
|
@ -153,85 +140,44 @@ sub parse_threshold {
|
|||
my $value_end = "";
|
||||
my $global_status = 1;
|
||||
|
||||
if (defined(${$self->{perfdata_chars}}[$self->{perfdata_pos}]) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] eq "@") {
|
||||
$arobase = 1;
|
||||
$self->{perfdata_pos}++;
|
||||
}
|
||||
|
||||
if (defined(${$self->{perfdata_chars}}[$self->{perfdata_pos}]) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] eq "~") {
|
||||
$infinite_neg = 1;
|
||||
$self->{perfdata_pos}++;
|
||||
} else {
|
||||
if (defined(${$self->{perfdata_chars}}[$self->{perfdata_pos}]) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] eq "-") {
|
||||
$neg = -1;
|
||||
$self->{perfdata_pos}++;
|
||||
}
|
||||
$value_tmp = $self->continue_to(undef, "[^0-9\.,]");
|
||||
if (defined($value_tmp) && $value_tmp ne "") {
|
||||
$value_tmp =~ s/,/./g;
|
||||
$value_tmp = $value_tmp * $neg;
|
||||
}
|
||||
$neg = 1;
|
||||
}
|
||||
|
||||
if (defined(${$self->{perfdata_chars}}[$self->{perfdata_pos}]) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] eq ":") {
|
||||
if ($value_tmp ne "") {
|
||||
$value_start = $value_tmp;
|
||||
} else {
|
||||
$value_start = 0;
|
||||
}
|
||||
$self->{perfdata_pos}++;
|
||||
|
||||
if (defined(${$self->{perfdata_chars}}[$self->{perfdata_pos}]) && ${$self->{perfdata_chars}}[$self->{perfdata_pos}] eq "-") {
|
||||
$neg = -1;
|
||||
$self->{perfdata_pos}++;
|
||||
}
|
||||
$value_end = $self->continue_to(undef, "[^0-9\.,]");
|
||||
if (defined($value_tmp) && $value_end ne "") {
|
||||
$value_end =~ s/,/./g;
|
||||
$value_end = $value_end * $neg;
|
||||
} else {
|
||||
if ($perf =~ /^(\@?)((?:~|(?:\+|-)?\d+(?:[\.,]\d+)?|):)?((?:\+|-)?\d+(?:[\.,]\d+)?)?$/) {
|
||||
$value_start = $2 if (defined($2));
|
||||
$value_end = $3 if (defined($3));
|
||||
$arobase = 1 if (defined($1) && $1 eq '@');
|
||||
$value_start =~ s/[\+:]//g;
|
||||
$value_end =~ s/\+//;
|
||||
if ($value_end eq '') {
|
||||
$value_end = 1e500;
|
||||
$infinite_pos = 1;
|
||||
}
|
||||
$value_start = 0 if ($value_start eq '');
|
||||
$value_start =~ s/,/\./;
|
||||
$value_end =~ s/,/\./;
|
||||
|
||||
if ($value_start eq '~') {
|
||||
$value_start = -1e500;
|
||||
$infinite_neg = 1;
|
||||
}
|
||||
} else {
|
||||
$value_start = 0;
|
||||
$value_end = $value_tmp;
|
||||
}
|
||||
|
||||
my $value = $self->continue_to(undef, "[ \t;]");
|
||||
if ($value ne '') {
|
||||
$global_status = 0;
|
||||
}
|
||||
|
||||
if ($infinite_neg == 1) {
|
||||
$value_start = '-1e500';
|
||||
}
|
||||
if ($infinite_pos == 1) {
|
||||
$value_end = '1e500';
|
||||
}
|
||||
|
||||
return ($global_status, $value_start, $value_end, $arobase, $infinite_neg, $infinite_pos);
|
||||
}
|
||||
|
||||
sub change_bytes {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $unit = defined($options{network}) ? 'b' : 'B';
|
||||
my $divide = defined($options{network}) ? 1000 : 1024;
|
||||
my @units = ('K', 'M', 'G', 'T');
|
||||
my $unit = '';
|
||||
|
||||
if (($options{value} / $divide) >= 1) {
|
||||
for (my $i = 0; $i < scalar(@units); $i++) {
|
||||
last if (($options{value} / $divide) < 1);
|
||||
$unit = $units[$i];
|
||||
$options{value} = $options{value} / $divide;
|
||||
$unit = defined($options{network}) ? 'Kb' : 'KB';
|
||||
}
|
||||
if (($options{value} / $divide) >= 1) {
|
||||
$options{value} = $options{value} / $divide;
|
||||
$unit = defined($options{network}) ? 'Mb' : 'MB';
|
||||
}
|
||||
if (($options{value} / $divide) >= 1) {
|
||||
$options{value} = $options{value} / $divide;
|
||||
$unit = defined($options{network}) ? 'Gb' : 'GB';
|
||||
}
|
||||
return (sprintf("%.2f", $options{value}), $unit);
|
||||
|
||||
return (sprintf("%.2f", $options{value}), $unit . (defined($options{network}) ? 'b' : 'B'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -77,8 +77,7 @@ sub class_handle_DIE {
|
|||
sub handle_DIE {
|
||||
my ($self, $msg) = @_;
|
||||
|
||||
# For 'mod_perl'
|
||||
die $msg if $^S;
|
||||
return unless defined $^S and $^S == 0; # Ignore errors in eval
|
||||
$self->{output}->add_option_msg(short_msg => $msg);
|
||||
$self->{output}->die_exit();
|
||||
}
|
||||
|
@ -94,16 +93,18 @@ sub get_plugin {
|
|||
$self->{options}->set_output(output => $self->{output});
|
||||
|
||||
$self->{options}->add_options(arguments => {
|
||||
'plugin:s' => { name => 'plugin' },
|
||||
'help' => { name => 'help' },
|
||||
'version' => { name => 'version' },
|
||||
'runas:s' => { name => 'runas' },
|
||||
'plugin:s' => { name => 'plugin' },
|
||||
'list-plugin' => { name => 'list_plugin' },
|
||||
'help' => { name => 'help' },
|
||||
'version' => { name => 'version' },
|
||||
'runas:s' => { name => 'runas' },
|
||||
'environment:s%' => { name => 'environment' },
|
||||
} );
|
||||
|
||||
$self->{options}->parse_options();
|
||||
|
||||
$self->{plugin} = $self->{options}->get_option(argument => 'plugin' );
|
||||
$self->{list_plugin} = $self->{options}->get_option(argument => 'list_plugin' );
|
||||
$self->{help} = $self->{options}->get_option(argument => 'help' );
|
||||
$self->{version} = $self->{options}->get_option(argument => 'version' );
|
||||
$self->{runas} = $self->{options}->get_option(argument => 'runas' );
|
||||
|
@ -129,6 +130,46 @@ sub display_local_help {
|
|||
$self->{output}->add_option_msg(long_msg => $stdout) if (defined($stdout));
|
||||
}
|
||||
|
||||
sub check_directory {
|
||||
my ($self, $directory) = @_;
|
||||
|
||||
opendir(my $dh, $directory) || return ;
|
||||
while (my $filename = readdir $dh) {
|
||||
$self->check_directory($directory . "/" . $filename) if ($filename !~ /^\./ && -d $directory . "/" . $filename);
|
||||
if ($filename eq 'plugin.pm') {
|
||||
my $stdout = '';
|
||||
|
||||
{
|
||||
local *STDOUT;
|
||||
open STDOUT, '>', \$stdout;
|
||||
pod2usage(-exitval => 'NOEXIT', -input => $directory . "/" . $filename,
|
||||
-verbose => 99,
|
||||
-sections => "PLUGIN DESCRIPTION");
|
||||
}
|
||||
$self->{plugins_result}->{$directory . "/" . $filename} = $stdout;
|
||||
}
|
||||
}
|
||||
closedir $dh;
|
||||
}
|
||||
|
||||
sub display_list_plugin {
|
||||
my $self = shift;
|
||||
$self->{plugins_result} = {};
|
||||
|
||||
# Search file 'plugin.pm'
|
||||
$self->check_directory($FindBin::Bin);
|
||||
foreach my $key (keys %{$self->{plugins_result}}) {
|
||||
my $name = $key;
|
||||
$name =~ s/^$FindBin::Bin\/(.*)\.pm/$1/;
|
||||
$name =~ s/\//::/g;
|
||||
$self->{plugins_result}->{$key} =~ s/^Plugin Description/DESCRIPTION/i;
|
||||
|
||||
$self->{output}->add_option_msg(long_msg => '-----------------');
|
||||
$self->{output}->add_option_msg(long_msg => 'PLUGIN: ' . $name);
|
||||
$self->{output}->add_option_msg(long_msg => $self->{plugins_result}->{$key});
|
||||
}
|
||||
}
|
||||
|
||||
sub check_relaunch {
|
||||
my $self = shift;
|
||||
my $need_restart = 0;
|
||||
|
@ -200,6 +241,10 @@ sub run {
|
|||
$self->display_local_help();
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (defined($self->{list_plugin})) {
|
||||
$self->display_list_plugin();
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{plugin}) || $self->{plugin} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify '--plugin' option.");
|
||||
$self->{output}->option_exit();
|
||||
|
@ -235,6 +280,10 @@ centreon_plugins.pl [options]
|
|||
|
||||
Specify the path to the plugin.
|
||||
|
||||
=item B<--list-plugin>
|
||||
|
||||
Print available plugins.
|
||||
|
||||
=item B<--version>
|
||||
|
||||
Print plugin version.
|
||||
|
|
|
@ -50,9 +50,10 @@ sub new {
|
|||
|
||||
$self->{options}->add_options(
|
||||
arguments => {
|
||||
'mode:s' => { name => 'mode' },
|
||||
'dyn-mode:s' => { name => 'dynmode_name' },
|
||||
'list-mode' => { name => 'list_mode' },
|
||||
'mode:s' => { name => 'mode' },
|
||||
'dyn-mode:s' => { name => 'dynmode_name' },
|
||||
'list-mode' => { name => 'list_mode' },
|
||||
'mode-version:s' => { name => 'mode_version' },
|
||||
}
|
||||
);
|
||||
$self->{version} = '1.0';
|
||||
|
@ -60,8 +61,9 @@ sub new {
|
|||
$self->{default} = undef;
|
||||
|
||||
$self->{options}->parse_options();
|
||||
$self->{mode_name} = $self->{options}->get_option(argument => 'mode' );
|
||||
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode' );
|
||||
$self->{mode_name} = $self->{options}->get_option(argument => 'mode');
|
||||
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode');
|
||||
$self->{mode_version} = $self->{options}->get_option(argument => 'mode_version');
|
||||
$self->{options}->clean();
|
||||
|
||||
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
|
||||
|
@ -113,6 +115,10 @@ sub init {
|
|||
$self->{mode}->version();
|
||||
$self->{output}->option_exit(nolabel => 1);
|
||||
}
|
||||
if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ". $self->{mode}->{version});
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{options}->parse_options();
|
||||
$self->{option_results} = $self->{options}->get_options();
|
||||
|
@ -192,6 +198,10 @@ Specify a mode with the path (separated by '::').
|
|||
|
||||
List available modes.
|
||||
|
||||
=item B<--mode-version>
|
||||
|
||||
Check minimal version of mode. If not, unknown error.
|
||||
|
||||
=item B<--version>
|
||||
|
||||
Display plugin version.
|
||||
|
|
|
@ -52,9 +52,10 @@ sub new {
|
|||
|
||||
$self->{options}->add_options(
|
||||
arguments => {
|
||||
'mode:s' => { name => 'mode' },
|
||||
'dyn-mode:s' => { name => 'dynmode_name' },
|
||||
'list-mode' => { name => 'list_mode' },
|
||||
'mode:s' => { name => 'mode' },
|
||||
'dyn-mode:s' => { name => 'dynmode_name' },
|
||||
'list-mode' => { name => 'list_mode' },
|
||||
'mode-version:s' => { name => 'mode_version' },
|
||||
}
|
||||
);
|
||||
$self->{version} = '1.0';
|
||||
|
@ -62,8 +63,9 @@ sub new {
|
|||
$self->{default} = undef;
|
||||
|
||||
$self->{options}->parse_options();
|
||||
$self->{mode_name} = $self->{options}->get_option(argument => 'mode' );
|
||||
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode' );
|
||||
$self->{mode_name} = $self->{options}->get_option(argument => 'mode');
|
||||
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode');
|
||||
$self->{mode_version} = $self->{options}->get_option(argument => 'mode_version');
|
||||
$self->{options}->clean();
|
||||
|
||||
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
|
||||
|
@ -118,10 +120,14 @@ sub init {
|
|||
$self->{mode}->version();
|
||||
$self->{output}->option_exit(nolabel => 1);
|
||||
}
|
||||
if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ". $self->{mode}->{version});
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{options}->parse_options();
|
||||
$self->{option_results} = $self->{options}->get_options();
|
||||
|
||||
|
||||
$self->{snmp}->check_options(option_results => $self->{option_results});
|
||||
$self->{mode}->check_options(option_results => $self->{option_results}, default => $self->{default});
|
||||
}
|
||||
|
@ -200,6 +206,10 @@ Specify a mode with the path (separated by '::').
|
|||
|
||||
List available modes.
|
||||
|
||||
=item B<--mode-version>
|
||||
|
||||
Check minimal version of mode. If not, unknown error.
|
||||
|
||||
=item B<--version>
|
||||
|
||||
Display plugin version.
|
||||
|
|
|
@ -51,12 +51,13 @@ sub new {
|
|||
|
||||
$self->{options}->add_options(
|
||||
arguments => {
|
||||
'mode:s' => { name => 'mode_name' },
|
||||
'dyn-mode:s' => { name => 'dynmode_name' },
|
||||
'list-mode' => { name => 'list_mode' },
|
||||
'sqlmode:s' => { name => 'sqlmode_name', default => 'dbi' },
|
||||
'list-sqlmode' => { name => 'list_sqlmode' },
|
||||
'multiple' => { name => 'multiple' },
|
||||
'mode:s' => { name => 'mode_name' },
|
||||
'dyn-mode:s' => { name => 'dynmode_name' },
|
||||
'list-mode' => { name => 'list_mode' },
|
||||
'mode-version:s' => { name => 'mode_version' },
|
||||
'sqlmode:s' => { name => 'sqlmode_name', default => 'dbi' },
|
||||
'list-sqlmode' => { name => 'list_sqlmode' },
|
||||
'multiple' => { name => 'multiple' },
|
||||
}
|
||||
);
|
||||
$self->{version} = '1.0';
|
||||
|
@ -136,6 +137,10 @@ sub init {
|
|||
$self->{mode}->version();
|
||||
$self->{output}->option_exit(nolabel => 1);
|
||||
}
|
||||
if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ". $self->{mode}->{version});
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{options}->parse_options();
|
||||
$self->{option_results} = $self->{options}->get_options();
|
||||
|
@ -255,6 +260,10 @@ List available modes.
|
|||
|
||||
Display plugin version.
|
||||
|
||||
=item B<--mode-version>
|
||||
|
||||
Check minimal version of mode. If not, unknown error.
|
||||
|
||||
=item B<--dyn-mode>
|
||||
|
||||
Specify a mode with the path (separated by '::').
|
||||
|
|
|
@ -52,9 +52,10 @@ sub new {
|
|||
|
||||
$self->{options}->add_options(
|
||||
arguments => {
|
||||
'mode:s' => { name => 'mode' },
|
||||
'dyn-mode:s' => { name => 'dynmode_name' },
|
||||
'list-mode' => { name => 'list_mode' },
|
||||
'mode:s' => { name => 'mode' },
|
||||
'dyn-mode:s' => { name => 'dynmode_name' },
|
||||
'list-mode' => { name => 'list_mode' },
|
||||
'mode-version:s' => { name => 'mode_version' },
|
||||
}
|
||||
);
|
||||
$self->{version} = '1.0';
|
||||
|
@ -62,8 +63,9 @@ sub new {
|
|||
$self->{default} = undef;
|
||||
|
||||
$self->{options}->parse_options();
|
||||
$self->{mode_name} = $self->{options}->get_option(argument => 'mode' );
|
||||
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode' );
|
||||
$self->{mode_name} = $self->{options}->get_option(argument => 'mode');
|
||||
$self->{list_mode} = $self->{options}->get_option(argument => 'list_mode');
|
||||
$self->{mode_version} = $self->{options}->get_option(argument => 'mode_version');
|
||||
$self->{options}->clean();
|
||||
|
||||
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
|
||||
|
@ -118,6 +120,10 @@ sub init {
|
|||
$self->{mode}->version();
|
||||
$self->{output}->option_exit(nolabel => 1);
|
||||
}
|
||||
if (centreon::plugins::misc::minimal_version($self->{mode}->{version}, $self->{mode_version}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Not good version for plugin mode. Excepted at least: " . $self->{mode_version} . ". Get: ". $self->{mode}->{version});
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{options}->parse_options();
|
||||
$self->{option_results} = $self->{options}->get_options();
|
||||
|
@ -204,6 +210,10 @@ List available modes.
|
|||
|
||||
Display plugin version.
|
||||
|
||||
=item B<--mode-version>
|
||||
|
||||
Check minimal version of mode. If not, unknown error.
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
|
|
@ -34,8 +34,12 @@
|
|||
####################################################################################
|
||||
|
||||
package centreon::plugins::statefile;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Data::Dumper;
|
||||
use vars qw($datas);
|
||||
use centreon::plugins::misc;
|
||||
|
||||
my $default_dir = '/var/lib/centreon/centplugins';
|
||||
|
||||
|
@ -47,15 +51,18 @@ sub new {
|
|||
if (defined($options{options})) {
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"memcached:s" => { name => 'memcached' },
|
||||
"memcached:s" => { name => 'memcached' },
|
||||
"statefile-dir:s" => { name => 'statefile_dir', default => $default_dir },
|
||||
"statefile-concat-cwd" => { name => 'statefile_concat_cwd' },
|
||||
"statefile-storable" => { name => 'statefile_storable' },
|
||||
});
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'RETENTION OPTIONS', once => 1);
|
||||
}
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{datas} = {};
|
||||
$self->{storable} = 0;
|
||||
$self->{memcached_ok} = 0;
|
||||
$self->{memcached} = undef;
|
||||
|
||||
$self->{statefile_dir} = undef;
|
||||
|
@ -67,15 +74,22 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($options{option_results}) && defined($options{option_results}->{memcached})) {
|
||||
require Memcached::libmemcached;
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Memcached::libmemcached',
|
||||
error_msg => "Cannot load module 'Memcached::libmemcached'.");
|
||||
$self->{memcached} = Memcached::libmemcached->new();
|
||||
Memcached::libmemcached::memcached_server_add($self->{memcached}, $options{option_results}->{memcached});
|
||||
}
|
||||
$self->{statefile_dir} = $options{option_results}->{statefile_dir};
|
||||
if ($self->{statefile_dir} ne $default_dir && defined($options{option_results}->{statefile_concat_cwd})) {
|
||||
require Cwd;
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Cwd',
|
||||
error_msg => "Cannot load module 'Cwd'.");
|
||||
$self->{statefile_dir} = Cwd::cwd() . '/' . $self->{statefile_dir};
|
||||
}
|
||||
if (defined($options{option_results}->{statefile_storable})) {
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Storable',
|
||||
error_msg => "Cannot load module 'Storable'.");
|
||||
$self->{storable} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub read {
|
||||
|
@ -87,6 +101,7 @@ sub read {
|
|||
# if "SUCCESS" or "NOT FOUND" is ok. Other with use the file
|
||||
my $val = Memcached::libmemcached::memcached_get($self->{memcached}, $self->{statefile_dir} . "/" . $self->{statefile});
|
||||
if (defined($self->{memcached}->errstr) && $self->{memcached}->errstr =~ /^SUCCESS|NOT FOUND$/i) {
|
||||
$self->{memcached_ok} = 1;
|
||||
if (defined($val)) {
|
||||
eval( $val );
|
||||
$self->{datas} = $datas;
|
||||
|
@ -95,7 +110,6 @@ sub read {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
$self->{memcached_ok} = 0;
|
||||
}
|
||||
|
||||
if (! -e $self->{statefile_dir} . "/" . $self->{statefile}) {
|
||||
|
@ -112,22 +126,36 @@ sub read {
|
|||
return 0;
|
||||
}
|
||||
|
||||
unless (my $return = do $self->{statefile_dir} . "/" . $self->{statefile}) {
|
||||
if ($self->{storable} == 1) {
|
||||
open FILE, $self->{statefile_dir} . "/" . $self->{statefile};
|
||||
eval {
|
||||
$self->{datas} = Storable::fd_retrieve(*FILE);
|
||||
};
|
||||
# File is corrupted surely. We'll reset it
|
||||
if ($@) {
|
||||
$self->{output}->add_option_msg(short_msg => "Couldn't parse '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $@");
|
||||
$self->{output}->option_exit();
|
||||
close FILE;
|
||||
return 0;
|
||||
}
|
||||
unless (defined($return)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Couldn't do '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $!");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
unless ($return) {
|
||||
$self->{output}->add_option_msg(short_msg => "Couldn't run '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $!");
|
||||
$self->{output}->option_exit();
|
||||
close FILE;
|
||||
} else {
|
||||
unless (my $return = do $self->{statefile_dir} . "/" . $self->{statefile}) {
|
||||
# File is corrupted surely. We'll reset it
|
||||
return 0;
|
||||
#if ($@) {
|
||||
# $self->{output}->add_option_msg(short_msg => "Couldn't parse '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $@");
|
||||
# $self->{output}->option_exit();
|
||||
#}
|
||||
#unless (defined($return)) {
|
||||
# $self->{output}->add_option_msg(short_msg => "Couldn't do '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $!");
|
||||
# $self->{output}->option_exit();
|
||||
#}
|
||||
#unless ($return) {
|
||||
# $self->{output}->add_option_msg(short_msg => "Couldn't run '" . $self->{statefile_dir} . "/" . $self->{statefile} . "': $!");
|
||||
# $self->{output}->option_exit();
|
||||
}
|
||||
$self->{datas} = $datas;
|
||||
$datas = {};
|
||||
}
|
||||
$self->{datas} = $datas;
|
||||
$datas = {};
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -150,7 +178,7 @@ sub get {
|
|||
sub write {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($self->{memcached})) {
|
||||
if ($self->{memcached_ok} == 1) {
|
||||
Memcached::libmemcached::memcached_set($self->{memcached}, $self->{statefile_dir} . "/" . $self->{statefile},
|
||||
Data::Dumper->Dump([$options{data}], ["datas"]));
|
||||
if (defined($self->{memcached}->errstr) && $self->{memcached}->errstr =~ /^SUCCESS$/i) {
|
||||
|
@ -158,7 +186,11 @@ sub write {
|
|||
}
|
||||
}
|
||||
open FILE, ">", $self->{statefile_dir} . "/" . $self->{statefile};
|
||||
print FILE Data::Dumper->Dump([$options{data}], ["datas"]);
|
||||
if ($self->{storable} == 1) {
|
||||
Storable::store_fd($options{data}, *FILE);
|
||||
} else {
|
||||
print FILE Data::Dumper->Dump([$options{data}], ["datas"]);
|
||||
}
|
||||
close FILE;
|
||||
}
|
||||
|
||||
|
@ -191,6 +223,10 @@ Directory for statefile (Default: '/var/lib/centreon/centplugins').
|
|||
Concat current working directory with option '--statefile-dir'.
|
||||
Useful on Windows when plugin is compiled.
|
||||
|
||||
=item B<--statefile-storable>
|
||||
|
||||
Use Perl Module 'Storable' (instead Data::Dumper) to store datas.
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
|
|
@ -71,6 +71,7 @@ SELECT name FROM sysdatabases ORDER BY name
|
|||
$self->{list_databases} = [];
|
||||
while ((my $row = $self->{sql}->fetchrow_hashref())) {
|
||||
if (defined($self->{option_results}->{exclude}) && $row->{name} !~ /$self->{option_results}->{exclude}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping database '" . centreon::plugins::misc::trim($row->{name}) . "': no matching filter name");
|
||||
next;
|
||||
}
|
||||
push @{$self->{list_databases}}, centreon::plugins::misc::trim($row->{name});
|
||||
|
@ -84,10 +85,13 @@ sub run {
|
|||
|
||||
$self->manage_selection();
|
||||
|
||||
foreach my $name (sort @{$self->{list_databases}}) {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "'");
|
||||
}
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "List of dbspaces: " . join(', ', @{$self->{list_databases}}));
|
||||
short_msg => "List of databases:");
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ SELECT name FROM sysdbspaces ORDER BY name
|
|||
$self->{list_dbspaces} = [];
|
||||
while ((my $row = $self->{sql}->fetchrow_hashref())) {
|
||||
if (defined($self->{option_results}->{exclude}) && $row->{name} !~ /$self->{option_results}->{exclude}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping dbspace '" . centreon::plugins::misc::trim($row->{name}) . "': no matching filter name");
|
||||
next;
|
||||
}
|
||||
push @{$self->{list_dbspaces}}, centreon::plugins::misc::trim($row->{name});
|
||||
|
@ -84,10 +85,13 @@ sub run {
|
|||
|
||||
$self->manage_selection();
|
||||
|
||||
foreach my $name (sort @{$self->{list_dbspaces}}) {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "'");
|
||||
}
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "List of dbspaces: " . join(', ', @{$self->{list_dbspaces}}));
|
||||
short_msg => "List of dbspaces:");
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Stephane Duret <sduret@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package database::mssql::mode::blockedprocesses;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes;
|
||||
use POSIX;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->{sql}->connect();
|
||||
$self->{sql}->query(query => q{SELECT count(*) FROM master.dbo.sysprocesses WHERE blocked <> '0'});
|
||||
my $blocked = $self->{sql}->fetchrow_array();
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $blocked, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("%i Blocked process(es).", $blocked));
|
||||
$self->{output}->perfdata_add(label => 'blocked_processes',
|
||||
value => $blocked,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check MSSQL blocked processes.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,131 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Stephane Duret <sduret@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package database::mssql::mode::cachehitratio;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes;
|
||||
use POSIX;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->{sql}->connect();
|
||||
$self->{sql}->query(query => q{
|
||||
SELECT CAST(
|
||||
(
|
||||
SELECT CAST (cntr_value AS BIGINT)
|
||||
FROM sys.dm_os_performance_counters
|
||||
WHERE counter_name = 'Buffer cache hit ratio'
|
||||
)* 100.00
|
||||
/
|
||||
(
|
||||
SELECT CAST (cntr_value AS BIGINT)
|
||||
FROM sys.dm_os_performance_counters
|
||||
WHERE counter_name = 'Buffer cache hit ratio base'
|
||||
) AS NUMERIC(6,3)
|
||||
)
|
||||
});
|
||||
my $hitratio = $self->{sql}->fetchrow_array();
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $hitratio, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("Buffer cache hit ratio is %.2f%%", $hitratio));
|
||||
$self->{output}->perfdata_add(label => 'cache_hitratio',
|
||||
value => $hitratio,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0,
|
||||
max => 100);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check MSSQL buffer cache hit ratio.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,116 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Stephane Duret <sduret@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package database::mssql::mode::connectedusers;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes;
|
||||
use POSIX;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->{sql}->connect();
|
||||
$self->{sql}->query(query => q{SELECT count(*) FROM master..sysprocesses WHERE spid >= '51'});
|
||||
my $users = $self->{sql}->fetchrow_array();
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $users, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("%i Connected user(s).", $users));
|
||||
$self->{output}->perfdata_add(label => 'connected_users',
|
||||
value => $users,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check MSSQL connected users.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,123 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Kevin Duret <kduret@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package database::mssql::mode::connectiontime;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes;
|
||||
use POSIX;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
my $now = Time::HiRes::time();
|
||||
my ($exit, $msg_error) = $self->{sql}->connect(dontquit => 1);
|
||||
my $now2 = Time::HiRes::time();
|
||||
|
||||
if ($exit == -1) {
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => $msg_error);
|
||||
} else {
|
||||
my $milliseconds = $now2 - $now;
|
||||
$milliseconds = floor($milliseconds * 1000);
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $milliseconds, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("Connection established in %.3fs.", $milliseconds / 1000));
|
||||
$self->{output}->perfdata_add(label => 'connection_time', unit => 'ms',
|
||||
value => $milliseconds,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check MSSQL connection time.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in milliseconds.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in milliseconds.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,142 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Kevin Duret <kduret@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package database::mssql::mode::lockswaits;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
"filter:s" => { name => 'filter', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->{sql}->connect();
|
||||
my $query = "SELECT
|
||||
cntr_value
|
||||
FROM
|
||||
sys.dm_os_performance_counters
|
||||
WHERE
|
||||
object_name = 'SQLServer:Locks'
|
||||
AND
|
||||
counter_name = 'Lock Waits/sec%'
|
||||
";
|
||||
|
||||
$self->{sql}->query(query => $query);
|
||||
my $result = $self->{sql}->fetchall_arrayref();
|
||||
|
||||
my $locks = 0;
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "0 Locks Waits/sec.");
|
||||
foreach my $row (@$result) {
|
||||
print $$row[0];
|
||||
next if (defined($self->{option_results}->{filter}) &&
|
||||
$$row[0] !~ /$self->{option_results}->{filter}/);
|
||||
$locks++;
|
||||
}
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $locks, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(long_msg => sprintf( "%i Locks Waits/sec.", $locks));
|
||||
if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("%i Locks Waits/sec.", $locks));
|
||||
}
|
||||
$self->{output}->perfdata_add(label => 'locks_waits_per_sec',
|
||||
value => $locks,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check MySQL databases size.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in bytes.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in bytes.
|
||||
|
||||
=item B<--filter>
|
||||
|
||||
Filter database to checks.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,123 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Stephane Duret <sduret@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package database::mssql::mode::transactions;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Time::HiRes;
|
||||
use POSIX;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->{sql}->connect();
|
||||
$self->{sql}->query(query => q{SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name = 'transactions/sec' AND instance_name = '_Total'});
|
||||
my $transaction1 = $self->{sql}->fetchrow_array();
|
||||
|
||||
sleep 1;
|
||||
|
||||
$self->{sql}->query(query => q{SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name = 'transactions/sec' AND instance_name = '_Total'});
|
||||
my $transaction2 = $self->{sql}->fetchrow_array();
|
||||
|
||||
my $transactions = $transaction2 - $transaction1 ;
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $transactions, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("%i transaction(s) per second.", $transactions));
|
||||
$self->{output}->perfdata_add(label => 'transactions_per_second',
|
||||
value => $transactions,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check MSSQL transactions per second.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,113 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package database::mssql::plugin;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(centreon::plugins::script_sql);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
# $options->{options} = options object
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'availability-group-states' => 'database::mssql::mode::availabilitygroupstates',
|
||||
'blocked-processes' => 'database::mssql::mode::blockedprocesses',
|
||||
'cache-hitratio' => 'database::mssql::mode::cachehitratio',
|
||||
'connected-users' => 'database::mssql::mode::connectedusers',
|
||||
'connection-time' => 'database::mssql::mode::connectiontime',
|
||||
'database-size' => 'database::mssql::mode::databasesize',
|
||||
'locks-waits' => 'database::mssql::mode::lockswaits',
|
||||
'transactions' => 'database::mssql::mode::transactions',
|
||||
);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub init {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{options}->add_options(
|
||||
arguments => {
|
||||
'host:s@' => { name => 'db_host' },
|
||||
'port:s@' => { name => 'db_port' },
|
||||
'database:s' => { name => 'database' },
|
||||
}
|
||||
);
|
||||
$self->{options}->parse_options();
|
||||
my $options_result = $self->{options}->get_options();
|
||||
$self->{options}->clean();
|
||||
|
||||
if (defined($options_result->{db_host})) {
|
||||
@{$self->{sqldefault}->{dbi}} = ();
|
||||
for (my $i = 0; $i < scalar(@{$options_result->{db_host}}); $i++) {
|
||||
$self->{sqldefault}->{dbi}[$i] = { data_source => 'Sybase:host=' . $options_result->{db_host}[$i] };
|
||||
if (defined($options_result->{db_port}[$i])) {
|
||||
$self->{sqldefault}->{dbi}[$i]->{data_source} .= ';port=' . $options_result->{db_port}[$i];
|
||||
}
|
||||
if ((defined($options_result->{database})) && ($options_result->{database} ne '')) {
|
||||
$self->{sqldefault}->{dbi}[$i]->{data_source} .= ';database=' . $options_result->{database};
|
||||
}
|
||||
}
|
||||
}
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 PLUGIN DESCRIPTION
|
||||
|
||||
Check MSSQL Server.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--host>
|
||||
|
||||
Hostname to query.
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Database Server Port.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -108,8 +108,7 @@ sub run {
|
|||
if (defined($old_read_request) && defined($old_read) &&
|
||||
$new_datas->{Innodb_buffer_pool_read_requests} >= $old_read_request &&
|
||||
$new_datas->{Innodb_buffer_pool_reads} >= $old_read) {
|
||||
|
||||
|
||||
|
||||
my %prcts = ();
|
||||
my $total_read_requests = $new_datas->{Innodb_buffer_pool_read_requests} - $old_read_request;
|
||||
my $total_read_disk = $new_datas->{Innodb_buffer_pool_reads} - $old_read;
|
||||
|
|
|
@ -85,7 +85,7 @@ sub run {
|
|||
$self->{sql}->query(query => q{SHOW VARIABLES LIKE 'open_files_limit'});
|
||||
my ($dummy, $open_files_limit) = $self->{sql}->fetchrow_array();
|
||||
if (!defined($open_files_limit)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get ope files limit.");
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get open files limit.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Open_files'});
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package database::mysql::mode::qcachehitrate;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
"lookback" => { name => 'lookback', },
|
||||
});
|
||||
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{statefile_cache}->check_options(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
$self->{sql} = $options{sql};
|
||||
|
||||
$self->{sql}->connect();
|
||||
|
||||
if (!($self->{sql}->is_version_minimum(version => '5'))) {
|
||||
$self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x').");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{sql}->query(query => q{SHOW /*!50000 global */ STATUS WHERE Variable_name IN ('Com_select', 'Qcache_hits')});
|
||||
my $new_datas = {Com_select => undef, Qcache_hits => undef};
|
||||
my $result = $self->{sql}->fetchall_arrayref();
|
||||
foreach my $row (@{$result}) {
|
||||
$new_datas->{$$row[0]} = $$row[1];
|
||||
}
|
||||
foreach (keys %$new_datas) {
|
||||
if (!defined($new_datas->{$_})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get '$_' variable.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
$self->{sql}->query(query => q{SHOW VARIABLES WHERE Variable_name IN ('have_query_cache', 'query_cache_size')});
|
||||
my ($dummy, $have_query_cache) = $self->{sql}->fetchrow_array();
|
||||
if (!defined($have_query_cache)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get have_query_cache variable.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
($dummy, my $query_cache_size) = $self->{sql}->fetchrow_array();
|
||||
if (!defined($query_cache_size)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cannot get query_cache_size variable.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ($have_query_cache !~ /^yes$/i || $query_cache_size == 0) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Query cache is turned off.");
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
$self->{statefile_cache}->read(statefile => 'mysql_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save());
|
||||
my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp');
|
||||
$new_datas->{last_timestamp} = time();
|
||||
|
||||
my $old_com_select = $self->{statefile_cache}->get(name => 'Com_select');
|
||||
my $old_qcache_hits = $self->{statefile_cache}->get(name => 'Qcache_hits');
|
||||
if (defined($old_com_select) && defined($old_qcache_hits) &&
|
||||
$new_datas->{Com_select} >= $old_com_select &&
|
||||
$new_datas->{Qcache_hits} >= $old_qcache_hits) {
|
||||
|
||||
my %prcts = ();
|
||||
my $total_select_requests = ($new_datas->{Com_select} - $old_com_select) + ($new_datas->{Qcache_hits} - $old_qcache_hits);
|
||||
my $total_hits = $new_datas->{Qcache_hits} - $old_qcache_hits;
|
||||
$prcts{qcache_hitrate_now} = ($total_select_requests == 0) ? 100 : ($total_hits) * 100 / $total_select_requests;
|
||||
$prcts{qcache_hitrate} = (($new_datas->{Qcache_hits} + $new_datas->{Com_select}) == 0) ? 100 : ($new_datas->{Qcache_hits}) * 100 / ($new_datas->{Qcache_hits} + $new_datas->{Com_select});
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now' )}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("query cache hitrate at %.2f%%", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')})
|
||||
);
|
||||
$self->{output}->perfdata_add(label => 'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now'), unit => '%',
|
||||
value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '' : '_now')}),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => 'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : ''), unit => '%',
|
||||
value => sprintf("%.2f", $prcts{'qcache_hitrate' . ((defined($self->{option_results}->{lookback})) ? '_now' : '')}),
|
||||
min => 0);
|
||||
}
|
||||
|
||||
$self->{statefile_cache}->write(data => $new_datas);
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check hitrate in the Query Cache.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning.
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical.
|
||||
|
||||
=item B<--lookback>
|
||||
|
||||
Threshold isn't on the percent calculated from the difference ('qcache_hitrate_now').
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,286 @@
|
|||
################################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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 executable,
|
||||
# regardless of the license terms of these independent modules, and to copy and
|
||||
# distribute the resulting executable 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
|
||||
# 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
|
||||
# Authors : Quentin Garnier <qgarnier@merethis.com>
|
||||
#
|
||||
####################################################################################
|
||||
|
||||
package database::mysql::mode::replicationmastermaster;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub check_replication {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my ($master, $slave) = ($options{master}, $options{slave});
|
||||
|
||||
my ($slave_status, $slave_status_error) = (0, "");
|
||||
my ($position_status, $position_status_error) = (0, "");
|
||||
|
||||
my ($total_srv, $last_error);
|
||||
|
||||
my ($io_thread_status_srv, $sql_thread_status_srv);
|
||||
if ($self->{$slave->get_id()}->{exit} != -1) {
|
||||
$slave->query(query => q{
|
||||
SHOW SLAVE STATUS
|
||||
});
|
||||
my $result = $slave->fetchrow_hashref();
|
||||
my $slave_io_running = $result->{Slave_IO_Running};
|
||||
my $slave_sql_running = $result->{Slave_SQL_Running};
|
||||
$last_error = $result->{Last_Error};
|
||||
|
||||
if (defined($slave_io_running) && $slave_io_running =~ /^yes$/i) {
|
||||
$io_thread_status_srv = 0;
|
||||
} else {
|
||||
$io_thread_status_srv = 1;
|
||||
}
|
||||
if (defined($slave_sql_running) && $slave_sql_running =~ /^yes$/i) {
|
||||
$sql_thread_status_srv = 0;
|
||||
} else {
|
||||
$sql_thread_status_srv = 1;
|
||||
}
|
||||
} else {
|
||||
$io_thread_status_srv = 100;
|
||||
$sql_thread_status_srv = 100;
|
||||
}
|
||||
|
||||
$total_srv = $io_thread_status_srv + $sql_thread_status_srv;
|
||||
|
||||
# Check if a thread is down
|
||||
if ($total_srv == 1) {
|
||||
$slave_status = -1;
|
||||
$slave_status_error = "A Replication thread is down on '" . $slave->get_id() . "'.";
|
||||
if ($sql_thread_status_srv != 0) {
|
||||
if (defined($last_error) && $last_error ne "") {
|
||||
$slave_status = 1;
|
||||
$slave_status_error .= " SQL Thread is stopped because of an error (error='" . $last_error . "').";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Check if we need to SKIP
|
||||
if ($io_thread_status_srv == 100) {
|
||||
$slave_status = -1;
|
||||
$slave_status_error .= " Skip check on '" . $slave->get_id() . "'.";
|
||||
}
|
||||
|
||||
if ($total_srv > 1) {
|
||||
$slave_status = 1;
|
||||
$slave_status_error .= " not a slave '" . $slave->get_id() . "' (maybe because we cannot check the server).";
|
||||
}
|
||||
|
||||
####
|
||||
# Check Slave position
|
||||
####
|
||||
if ($self->{$master->get_id()}->{exit} == -1) {
|
||||
$position_status = -1;
|
||||
$position_status_error = "Can't get master position on '" . $master->get_id() . "'.";
|
||||
} else {
|
||||
# Get Master Position
|
||||
$master->query(query => q{
|
||||
SHOW MASTER STATUS
|
||||
});
|
||||
my $result = $master->fetchrow_hashref();
|
||||
my $master_file = $result->{File};
|
||||
my $master_position = $result->{Position};
|
||||
|
||||
$slave->query(query => q{
|
||||
SHOW SLAVE STATUS
|
||||
});
|
||||
my $result2 = $slave->fetchrow_hashref();
|
||||
my $slave_file = $result2->{Master_Log_File}; # 'Master_Log_File'
|
||||
my $slave_position = $result2->{Read_Master_Log_Pos}; # 'Read_Master_Log_Pos'
|
||||
my $num_sec_lates = $result2->{Seconds_Behind_Master};
|
||||
|
||||
my $exit_code_sec = $self->{perfdata}->threshold_check(value => $num_sec_lates, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
if (!$self->{output}->is_status(value => $exit_code_sec, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit_code_sec,
|
||||
short_msg => sprintf("Slave '%s' has %d seconds latency behind master", $slave->get_id(), $num_sec_lates));
|
||||
}
|
||||
$self->{output}->perfdata_add(label => 'slave_latency_' . $slave->get_id(), unit => 's',
|
||||
value => $num_sec_lates,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
|
||||
my $slave_sql_thread_ko = 1;
|
||||
my $slave_sql_thread_warning = 1;
|
||||
my $slave_sql_thread_ok = 1;
|
||||
|
||||
$slave->query(query => q{
|
||||
SHOW FULL PROCESSLIST
|
||||
});
|
||||
while ((my $row = $slave->fetchrow_hashref())) {
|
||||
my $state = $row->{State};
|
||||
$slave_sql_thread_ko = 0 if (defined($state) && $state =~ /^(Waiting to reconnect after a failed binlog dump request|Connecting to master|Reconnecting after a failed binlog dump request|Waiting to reconnect after a failed master event read|Waiting for the slave SQL thread to free enough relay log space)$/i);
|
||||
$slave_sql_thread_warning = 0 if (defined($state) && $state =~ /^Waiting for the next event in relay log|Reading event from the relay log$/i);
|
||||
$slave_sql_thread_ok = 0 if (defined($state) && $state =~ /^Has read all relay log; waiting for the slave I\/O thread to update it$/i);
|
||||
}
|
||||
|
||||
if ($slave_sql_thread_ko == 0) {
|
||||
$position_status = 1;
|
||||
$position_status_error .= " Slave replication has connection issue with the master.";
|
||||
} elsif (($master_file ne $slave_file || $master_position != $slave_position) && $slave_sql_thread_warning == 0) {
|
||||
$position_status = -1;
|
||||
$position_status_error .= " Slave replication is late but it's progressing..";
|
||||
} elsif (($master_file ne $slave_file || $master_position != $slave_position) && $slave_sql_thread_ok == 0) {
|
||||
$position_status = -1;
|
||||
$position_status_error .= " Slave replication is late but it's progressing..";
|
||||
}
|
||||
}
|
||||
|
||||
$self->replication_add($slave_status, "Slave Thread Status '" . $slave->get_id() . "'", $slave_status_error);
|
||||
$self->replication_add($position_status, "Position Status '" . $slave->get_id() . "'", $position_status_error);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{sql} = sqlmode object
|
||||
|
||||
if (ref($options{sql}) ne 'ARRAY') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to use --multiple options.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (scalar(@{$options{sql}}) < 2) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify two MySQL Server.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my ($msg_error1, $msg_error2);
|
||||
my ($sql_one, $sql_two) = @{$options{sql}};
|
||||
|
||||
($self->{$sql_one->get_id()}->{exit}, $msg_error1) = $sql_one->connect(dontquit => 1);
|
||||
($self->{$sql_two->get_id()}->{exit}, $msg_error2) = $sql_two->connect(dontquit => 1);
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "No problems. Replication is ok.");
|
||||
if ($self->{$sql_one->get_id()}->{exit} == -1) {
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => "Connection Status '" . $sql_one->get_id() . "': " . $msg_error1);
|
||||
} else {
|
||||
$self->{output}->output_add(long_msg => "Connection Status '" . $sql_one->get_id() . "' [OK]");
|
||||
}
|
||||
if ($self->{$sql_two->get_id()}->{exit} == -1) {
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => "Connection Status '" . $sql_two->get_id() . "': " . $msg_error2);
|
||||
} else {
|
||||
$self->{output}->output_add(long_msg => "Connection Status '" . $sql_two->get_id() . "' [OK]");
|
||||
}
|
||||
|
||||
$self->check_replication(master => $sql_one, slave => $sql_two);
|
||||
$self->check_replication(master => $sql_two, slave => $sql_one);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub replication_add {
|
||||
my ($self, $lstate, $str_display, $lerr) = @_;
|
||||
my $status;
|
||||
my $status_msg;
|
||||
|
||||
if ($lstate == 0) {
|
||||
$status = 'OK';
|
||||
} elsif ($lstate == -1) {
|
||||
$status = 'WARNING';
|
||||
} elsif ($lstate == -2) {
|
||||
$status = 'CRITICAL';
|
||||
$status_msg = 'SKIP';
|
||||
} else {
|
||||
$status = 'CRITICAL';
|
||||
}
|
||||
|
||||
my $output;
|
||||
if (defined($lerr) && $lerr ne "") {
|
||||
$output = $str_display . " [" . (defined($status_msg) ? $status_msg : $status) . "] [" . $lerr . "]";
|
||||
} else {
|
||||
$output = $str_display . " [" . (defined($status_msg) ? $status_msg : $status) . "]";
|
||||
}
|
||||
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $status,
|
||||
short_msg => $output);
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => $output);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check MySQL replication master/master (need to use --multiple).
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in seconds (slave latency).
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in seconds (slave latency).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -48,16 +48,18 @@ sub new {
|
|||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'connection-time' => 'database::mysql::mode::connectiontime',
|
||||
'databases-size' => 'database::mysql::mode::databasessize',
|
||||
'queries' => 'database::mysql::mode::queries',
|
||||
'slow-queries' => 'database::mysql::mode::slowqueries',
|
||||
'threads-connected' => 'database::mysql::mode::threadsconnected',
|
||||
'uptime' => 'database::mysql::mode::uptime',
|
||||
'open-files' => 'database::mysql::mode::openfiles',
|
||||
'innodb-bufferpool-hitrate' => 'database::mysql::mode::innodbbufferpoolhitrate',
|
||||
'myisam-keycache-hitrate' => 'database::mysql::mode::myisamkeycachehitrate',
|
||||
'replication-master-slave' => 'database::mysql::mode::replicationmasterslave',
|
||||
'connection-time' => 'database::mysql::mode::connectiontime',
|
||||
'databases-size' => 'database::mysql::mode::databasessize',
|
||||
'queries' => 'database::mysql::mode::queries',
|
||||
'slow-queries' => 'database::mysql::mode::slowqueries',
|
||||
'threads-connected' => 'database::mysql::mode::threadsconnected',
|
||||
'uptime' => 'database::mysql::mode::uptime',
|
||||
'open-files' => 'database::mysql::mode::openfiles',
|
||||
'innodb-bufferpool-hitrate' => 'database::mysql::mode::innodbbufferpoolhitrate',
|
||||
'myisam-keycache-hitrate' => 'database::mysql::mode::myisamkeycachehitrate',
|
||||
'qcache-hitrate' => 'database::mysql::mode::qcachehitrate',
|
||||
'replication-master-slave' => 'database::mysql::mode::replicationmasterslave',
|
||||
'replication-master-master' => 'database::mysql::mode::replicationmastermaster',
|
||||
);
|
||||
$self->{sql_modes}{mysqlcmd} = 'database::mysql::mysqlcmd';
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ SELECT datname FROM pg_database
|
|||
$self->{list_db} = [];
|
||||
while ((my $row = $self->{sql}->fetchrow_hashref())) {
|
||||
if (defined($self->{option_results}->{exclude}) && $row->{datname} !~ /$self->{option_results}->{exclude}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping database '" . $row->{datname} . "': no matching filter name");
|
||||
next;
|
||||
}
|
||||
push @{$self->{list_db}}, $row->{datname};
|
||||
|
@ -83,10 +84,13 @@ sub run {
|
|||
|
||||
$self->manage_selection();
|
||||
|
||||
foreach my $name (sort @{$self->{list_db}}) {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "'");
|
||||
}
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "List of databases: " . join(', ', @{$self->{list_db}}));
|
||||
short_msg => "List of databases:");
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
|
|
|
@ -53,8 +53,9 @@ sub new {
|
|||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"filter-tray:s" => { name => 'filter_tray' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -106,6 +107,12 @@ sub run {
|
|||
$descr = $hrDeviceIndex . '#' . $prtInputIndex;
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{filter_tray}) && $self->{option_results}->{filter_tray} ne '' &&
|
||||
$descr !~ /$self->{option_results}->{filter_tray}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping tray '$descr': not matching filter.");
|
||||
next;
|
||||
}
|
||||
|
||||
if (!defined($unit_managed{$unit})) {
|
||||
$self->{output}->output_add(long_msg => "Skipping input '$descr': unit not managed.");
|
||||
next;
|
||||
|
@ -114,7 +121,7 @@ sub run {
|
|||
$self->{output}->output_add(long_msg => "Skipping tray '$descr': no level.");
|
||||
next;
|
||||
} elsif ($current_value == -2) {
|
||||
$self->{output}->output_add(long_msg => "Skippinp tray'$descr': level unknown.");
|
||||
$self->{output}->output_add(long_msg => "Skippinp tray '$descr': level unknown.");
|
||||
next;
|
||||
} elsif ($current_value == -3) {
|
||||
$self->{output}->output_add(long_msg => "Tray '$descr': no level but some space remaining.");
|
||||
|
@ -161,6 +168,10 @@ Threshold warning in percent.
|
|||
|
||||
Threshold critical in percent.
|
||||
|
||||
=item B<--filter-tray>
|
||||
|
||||
Filter tray to check (can use a regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -0,0 +1,177 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package hardware::sensors::sequoia::em01::web::mode::contact;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/index.htm?eL" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"warning" => { name => 'warning' },
|
||||
"critical" => { name => 'critical' },
|
||||
"closed" => { name => 'closed' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
$self->{status} = { closed => 'ok', opened => 'ok' };
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
my $label = 'opened';
|
||||
$label = 'closed' if (defined($self->{option_results}->{closed}));
|
||||
if (defined($self->{option_results}->{critical})) {
|
||||
$self->{status}->{$label} = 'critical';
|
||||
} elsif (defined($self->{option_results}->{warning})) {
|
||||
$self->{status}->{$label} = 'warning';
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my $contact;
|
||||
|
||||
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /([NW]).*?:/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Could not find door contact information.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$contact = $1;
|
||||
|
||||
if ($contact eq 'N') {
|
||||
$self->{output}->output_add(severity => $self->{status}->{opened},
|
||||
short_msg => sprintf("Door is opened."));
|
||||
} else {
|
||||
$self->{output}->output_add(severity => $self->{status}->{closed},
|
||||
short_msg => sprintf("Door is closed."));
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check sensor voltage.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/index.htm?eL')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning if door is opened (can set --close for closed door)
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Critical if door is opened (can set --close for closed door)
|
||||
|
||||
=item B<--closed>
|
||||
|
||||
Threshold is on closed door (default: opened)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,177 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package hardware::sensors::sequoia::em01::web::mode::flood;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"warning" => { name => 'warning' },
|
||||
"critical" => { name => 'critical' },
|
||||
"dry" => { name => 'dry' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
$self->{status} = { dry => 'ok', wet => 'ok' };
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
my $label = 'wet';
|
||||
$label = 'dry' if (defined($self->{option_results}->{dry}));
|
||||
if (defined($self->{option_results}->{critical})) {
|
||||
$self->{status}->{$label} = 'critical';
|
||||
} elsif (defined($self->{option_results}->{warning})) {
|
||||
$self->{status}->{$label} = 'warning';
|
||||
}
|
||||
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my $flood;
|
||||
|
||||
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /(dry|wet)/i) {
|
||||
$self->{output}->add_option_msg(short_msg => "Could not find flood information (need to set good --urlpath option).");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$flood = lc($1);
|
||||
|
||||
if ($flood eq 'dry') {
|
||||
$self->{output}->output_add(severity => $self->{status}->{dry},
|
||||
short_msg => sprintf("Flood sensor is dry."));
|
||||
} else {
|
||||
$self->{output}->output_add(severity => $self->{status}->{wet},
|
||||
short_msg => sprintf("Flood sensor is wet."));
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check sensor flood.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning if flood sensor is wet (can set --dry for dry sensor)
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Critical if flood sensor is wet (can set --dry for dry sensor)
|
||||
|
||||
=item B<--closed>
|
||||
|
||||
Threshold is on dry sensor (default: wet)
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,174 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package hardware::sensors::sequoia::em01::web::mode::humidity;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/index.htm?em" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my $humidity;
|
||||
|
||||
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /HU:\s*([0-9\.]+)/i) {
|
||||
$self->{output}->add_option_msg(short_msg => "Could not find humidity information.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$humidity = $1;
|
||||
$humidity = '0' . $humidity if ($humidity =~ /^\./);
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $humidity, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Humidity: %.2f %%", $humidity));
|
||||
$self->{output}->perfdata_add(label => "humidity", unit => '%',
|
||||
value => sprintf("%.2f", $humidity),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check sensor Humidity.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/index.htm?em')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning Threshold for Humidity
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Critical Threshold for Humidity
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,174 @@
|
|||
###############################################################################
|
||||
# Copyright 2005-2013 MERETHIS
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# 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>
|
||||
#
|
||||
# Based on De Bodt Lieven plugin
|
||||
####################################################################################
|
||||
|
||||
package hardware::sensors::sequoia::em01::web::mode::illumination;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::httplib;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"hostname:s" => { name => 'hostname' },
|
||||
"port:s" => { name => 'port', },
|
||||
"proto:s" => { name => 'proto', default => "http" },
|
||||
"urlpath:s" => { name => 'url_path', default => "/index.htm?em" },
|
||||
"credentials" => { name => 'credentials' },
|
||||
"username:s" => { name => 'username' },
|
||||
"password:s" => { name => 'password' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"timeout:s" => { name => 'timeout', default => '3' },
|
||||
});
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{hostname})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ((defined($self->{option_results}->{credentials})) && (!defined($self->{option_results}->{username}) || !defined($self->{option_results}->{password}))) {
|
||||
$self->{output}->add_option_msg(short_msg => "You need to set --username= and --password= options when --credentials is used");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $webcontent = centreon::plugins::httplib::connect($self);
|
||||
my $illumination;
|
||||
|
||||
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /IL\s*([0-9\.]+)/i) {
|
||||
$self->{output}->add_option_msg(short_msg => "Could not find illumination information.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$illumination = $1;
|
||||
$illumination = '0' . $illumination if ($illumination =~ /^\./);
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $illumination, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Illumination: %.1f", $illumination));
|
||||
$self->{output}->perfdata_add(label => "illumination",
|
||||
value => sprintf("%.1f", $illumination),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check sensor Illumination.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
IP Addr/FQDN of the webserver host
|
||||
|
||||
=item B<--port>
|
||||
|
||||
Port used by Apache
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=item B<--proto>
|
||||
|
||||
Specify https if needed
|
||||
|
||||
=item B<--urlpath>
|
||||
|
||||
Set path to get server-status page in auto mode (Default: '/index.htm?em')
|
||||
|
||||
=item B<--credentials>
|
||||
|
||||
Specify this option if you access server-status page over basic authentification
|
||||
|
||||
=item B<--username>
|
||||
|
||||
Specify username for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--password>
|
||||
|
||||
Specify password for basic authentification (Mandatory if --credentials is specidied)
|
||||
|
||||
=item B<--timeout>
|
||||
|
||||
Threshold for HTTP timeout
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Warning Threshold for Illumination
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Critical Threshold for Illumination
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue