This commit is contained in:
Quentin Garnier 2015-02-13 16:38:06 +01:00
commit 1d5778ab0c

View File

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