So first here is the first plugin I try to use : zmqstat.pl
Code: Select all
#!/usr/bin/perl
#Author:
# [email protected])
use strict;
use Getopt::Long;
use POSIX;
use File::Basename;
use Data::Dumper;
# Global variables
our $name = basename($0, ".pl");
our ($oHelp, $oVerbose, $oWarn, $oCrit, $oQueue);
#--------------------------------------------------------------------------------------
sub main {
getoption();
my @output = `sudo /opt/zimbra/libexec/zmqstat 2>&1`;
chomp @output;
#print Dumper @output;
#print Dumper $?;
if($? != 0 ){
quit("ERROR: ".@output[0], 3);
}
my $value;
foreach my $line (@output){
#print "$line\n";
my @words = split /=/, $line;
#print Dumper @words[1];
if(@words[0] eq $oQueue){
$value = @words[1];
}
}
#print Dumper $value;
my $msg ="Queue $oQueue: $value";
my $exit_code = 3;
if($oWarn && $oWarn){
$exit_code = metric($value);
}else{
$exit_code = 0;
}
my $perf = " | '".$oQueue."'=".$value.";".$oWarn.";".$oCrit.";0;";
quit( $msg.$perf, $exit_code);
}
#--------------------------------------------------------------------------------------
sub metric {
my $value = shift;
if ($value >= $oCrit) { return 2
}elsif ($value >= $oWarn) { return 1
}elsif ($value < $oWarn) { return 0
}else{ quit("Unable to check.",3) }
}
#--------------------------------------------------------------------------------------
sub quit {
my $mgs = shift;
my $code = shift;
print $mgs,"\n";
exit($code);
}
#--------------------------------------------------------------------------------------
sub getoption {
Getopt::Long::Configure('bundling');
GetOptions(
'c|critical=i' => \$oCrit,
'h|help' => \$oHelp,
'v|verbose=i' => \$oVerbose,
'w|warning=i' => \$oWarn,
'q|queue=s' => \$oQueue,
);
if($oHelp){
printUsage();
exit(3);
}
if (!$oQueue){
printUsage();
exit(3);
}
my @array = qw/hold corrupt deferred active incoming/;
if(!grep $_ eq $oQueue, @array)
{
printUsage();
exit(3);
}
}
#--------------------------------------------------------------------------------------
sub printUsage {
print <<EOB
Usage: $name.pl [OPTION]...
-c, --critical
-h, --help
-w, --warning
-v, --verbose
-q, --queue [hold|corrupt|deferred|active|incoming]
Grant permission to the nagios user:
\t nagios ALL=(zimbra) NOPASSWD:/opt/zimbra/bin/zmcontrol
EOB
}
#--------------------------------------------------------------------------------------
&main;And here is the second one: check_zimbra.pl
Code: Select all
#!/usr/bin/perl
use Getopt::Std;
use vars qw/ %opt /;
# Just change this command line to be compatible with your setup
$zimbra_status_command='/opt/zimbra/bin/zmcontrol status';
# You should'n change anything behind this line.
$DEBUG=0;
$output="";
$faulty_service=0;
$faulty_daemon=0;
getopts('sSChde:', \%opt);
if (exists $opt{h}) {
usage();
exit(0);
}
if (exists $opt{d}) {
$DEBUG=1;
}
if (exists $opt{e}) {
$exclude_list=$opt{e};
print "Excluded list : $exclude_list\n" if $DEBUG;
}
# Getting zimbra status :
open (ZMSTATUS, "$zimbra_status_command |");
while (<ZMSTATUS>){
print $_ if $DEBUG;
if (/^Host/){
my ($tmp, $hostname)=split();
$output="HOST : $hostname"
} else {
($service, $state)=split();
}
if ($exclude_list =~ /$service/){
print "Service $service is excluded from monitoring\n" if $DEBUG;
next;
}
if ( $state eq "Running" ){
$output=$output . ", $service : OK";
} elsif ( $state eq "Stopped" ){
$output=$output . ", $service : STOPPED";
$faulty_service++;
} elsif ( $state eq "is" ){
$output=$output . " and $service down";
$faulty_daemon++;
}
}
print $output . "\n";
close (ZMSTATUS);
print "Faulty Services : $faulty_service, Faulty Daemons : $faulty_daemon\n" if $DEBUG;
# Choosing right exit code :
# 0 OK, 1 Warning, 2 Critical, 3 Unknow
if (exists $opt{s}) {
#stopped service are ignored until some daemon is faulty
if ( $faulty_service > 0 && $faulty_daemon > 0){
exit(2);
} elsif ( $faulty_service > 0 && $faulty_daemon == 0){
exit(0);
} elsif ( $faulty_service == 0 && $faulty_daemon == 0){
exit(0);
} else {
exit(3);
}
}
if (exists $opt{S}) {
#stopped service give warning state
if ( $faulty_service > 0 && $faulty_daemon > 0){
exit(2);
} elsif ( $faulty_service > 0 && $faulty_daemon == 0){
exit(1);
} elsif ( $faulty_service == 0 && $faulty_daemon == 0){
exit(0);
} else {
exit(3);
}
}
if (exists $opt{C}) {
#stopped service give critical state in all cases
if ( $faulty_service > 0 && $faulty_daemon > 0){
exit(2);
} elsif ( $faulty_service > 0 && $faulty_daemon == 0){
exit(2);
} elsif ( $faulty_service == 0 && $faulty_daemon == 0){
exit(0);
} else {
exit(3);
}
}
sub usage {
if (@_ == 1) {
print "$0: $_[0].\n";
}
print << "EOF";
Usage: $0 [options]
-s
stopped service are ignored until some daemon is faulty
-S
stopped service give warning state if a service is faulty
-C
stopped service give critical if a service is faulty
-e service1,service2,..
list of excluded services from monitoring
-d
enable debug mode
-h
display usage information
EOF
}So basically I am trying to get those two plugins works throught NRPE between nagios server and the mailing server.
ON THE MAILING SERVER
So here are my commands in NRPE.cfg
Code: Select all
command[check_zimbraqueue]=/usr/bin/sudo /usr/local/nagios/libexec/zmqstat.pl -q deferred -w 20 -c 25
command[check_zimbraqueue_active]=/usr/bin/sudo /usr/local/nagios/libexec/zmqstat.pl -q active -w 20 -c 25
command[check_zimbraqueue_hold]=/usr/bin/sudo /usr/local/nagios/libexec/zmqstat.pl -q hold -w 20 -c 25
command[check_zimbraqueue_corrupt]=/usr/bin/sudo /usr/local/nagios/libexec/zmqstat.pl -q corrupt -w 20 -c 25
command[check_zimbraqueue_incoming]=/usr/bin/sudo /usr/local/nagios/libexec/zmqstat.pl -q incoming -w 20 -c 25
command[check_zimbra]=/usr/bin/sudo /usr/local/nagios/libexec/check_zimbra.pl -H localhost
Code: Select all
sudo visudoCode: Select all
#
# Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
# You have to run "ssh -t hostname sudo <cmd>".
#
#Defaults !requiretty
#Defaults:nagios !requiretty
#
# Refuse to run if unable to disable echo on the tty. This setting should also be
# changed in order to be able to use sudo without a tty. See requiretty above.
#
Defaults !visiblepw
.
..
.
# ASTERISK-SPECIFIC CHECKS
# NOTE: You can uncomment the following line if you are monitoring Asterisk locally
#nagios ALL=NOPASSWD: /usr/local/nagios/libexec/check_asterisk_sip_peers.sh, /usr/local/nagios/libexec/nagisk.pl, /usr/sbin/asterisk
nagios ALL=(zimbra) NOPASSWD:/opt/zimbra/bin/zmcontrol
nagios ALL=(root) NOPASSWD:/usr/local/nagios/libexec/check_zmqstat.pl
But here are some results :
Code: Select all
[root@avenger etc]# /usr/local/nagios/libexec/zmqstat.pl -q deferred -w 20 -c 35
Queue deferred: 30 | 'deferred'=30;20;35;0;
Code: Select all
[root@avenger etc]# sudo /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_zimbraqueue
NRPE: Unable to read output
Code: Select all
[root@avenger etc]# sudo /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_cpu
CPU STATISTICS OK: user=26.18% system=1.01% iowait=0.00% idle=59.85% | user=26.18% system=1.01% iowait=0.00%;90,40,30;90,50,40 idle=59.85%
Code: Select all
[root@avenger etc]# sudo /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.15
ON THE NAGIOS SERVER:
Here are the results of some commands:
Code: Select all
[root@wasp objects]# /usr/local/nagios/libexec/check_nrpe -H avenger -c check_zimbraqueue
NRPE: Unable to read output
Code: Select all
[root@wasp objects]# /usr/local/nagios/libexec/check_nrpe -H avenger -c check_cpu
CPU STATISTICS OK: user=26.09% system=0.45% iowait=0.00% idle=71.06% | user=26.09% system=0.45% iowait=0.00%;90,40,30;90,50,40 idle=71.06%
Code: Select all
[root@wasp objects]# /usr/local/nagios/libexec/check_nrpe -H avenger
NRPE v2.15
I have checked the iptables and it's OK.
By the way I have tried all restart and so on :/
So I have any idea of what's going on let me know