This commit is contained in:
Quentin Garnier 2015-02-13 16:38:06 +01:00
commit 1d5778ab0c
1 changed files with 16 additions and 26 deletions

View File

@ -40,6 +40,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use IO::Socket;
use Data::Dumper;
sub new {
my ($class, %options) = @_;
@ -56,8 +57,7 @@ sub new {
"critical-update:s" => { name => 'critical_update', default => '5000' },
"warning-queue:s" => { name => 'warning_queue', default => '70' },
"critical-queue:s" => { name => 'critical_queue', default => '100' },
"tcp" => { name => 'tcp' },
"unix" => { name => 'unix' },
"socket-type:s" => { name => 'socket_type', default => 'unix' },
});
return $self;
}
@ -82,14 +82,6 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical-queue threshold '" . $self->{critical} . "'.");
$self->{output}->option_exit();
}
if ((defined($self->{option_results}->{tcp})) && (!defined($self->{option_results}->{host}) || !defined($self->{option_results}->{port}))) {
$self->{output}->add_option_msg(short_msg => "Please define host and port options when __tcp option is used");
$self->{output}->option_exit();
}
if ((defined($self->{option_results}->{unix})) && (!defined($self->{option_results}->{unix_socket_path}))) {
$self->{output}->add_option_msg(short_msg => "Please define host and port option when --unix option is used");
$self->{output}->option_exit();
}
}
sub run {
@ -100,7 +92,7 @@ sub run {
my $queueLenght;
my $socket;
if (defined($self->{option_results}->{tcp})) {
if ($self->{option_results}->{socket_type} eq 'tcp') {
$socket = IO::Socket::INET->new(
PeerHost => $self->{option_results}->{host},
PeerPort => $self->{option_results}->{port},
@ -120,9 +112,7 @@ sub run {
$self->{output}->display();
$self->{output}->exit();
} else {
$socket->send("STATS\n");
while ($data = <$socket>) {
if ($data =~ /(\d+) Statistics follow/) {
my $stats_number = $1;
@ -136,6 +126,7 @@ sub run {
next if $data !~ m/(^UpdatesR|Data|Queue)/;
push @tab,$data;
$socket->send("QUIT\n");
}
close($socket);
@ -148,7 +139,6 @@ sub run {
chomp($stat[0]);
my $updatesNotWritten = $stat[1] - $stat[2];
my $exit1 = $self->{perfdata}->threshold_check(value => $updatesNotWritten, threshold => [ { label => 'critical-update', 'exit_litteral' => 'critical' }, { label => 'warning-update', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $stat[0], threshold => [ { label => 'critical-queue', 'exit_litteral' => 'critical' }, { label => 'warning-queue', exit_litteral => 'warning' } ]);