Page 1 of 1

NRPE - Unable to read output (Zimbra plugin) SOLVED

Posted: Thu Aug 04, 2016 1:01 pm
by Gouteya
Hi all , I have been searching for an answer on google but I keep being stuck with that error . Here are all the information about my config and the plugins (two of them) that are failing.

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
Here is the config of the

Code: Select all

sudo visudo

Code: 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
By the way other plugins using NRPE are working well (like check_cpu)

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
As I said other plugins works well :

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%
And NRPE is good too

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
Check_cpu plugin is working well:

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%
NRPE is working well too:

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 :) and thanks for those who read this and try to help me with that problem :)

Re: NRPE - Unable to read output (Zimbra plugin

Posted: Thu Aug 04, 2016 1:23 pm
by tgriep
Check the permissions of the /usr/local/nagios/libexec/zmqstat.pl file and see if the nagios user account can execute the script.
Alos, it could be the permissions of the folders where the perl modules that the plugin uses may have to be adjusted for the nagios user to run it.
Also, login to the remote server as the nagios user account and run the plugin and see if it works for you.

Code: Select all

su - nagios
/usr/local/nagios/libexec/zmqstat.pl -q deferred -w 20 -c 25

Re: NRPE - Unable to read output (Zimbra plugin

Posted: Thu Aug 04, 2016 1:49 pm
by Gouteya
Sorry I forgot about hte permissions but here it is:

Code: Select all

[root@avenger libexec]# ls -l | grep zmqstat
-rwxrwxrwx 1 nagios nagios   2940 Aug  3 16:51 zmqstat.pl
For the perl folder here is what I get :

Code: Select all

[root@avenger bin]# ls -l | grep perl
-rwxr-xr-x  1 root root     23614 Nov 10  2015 find2perl
-rwxr-xr-x  2 root root      7184 Nov 10  2015 perl
-rwxr-xr-x  2 root root      7184 Nov 10  2015 perl5.10.1
-rwxr-xr-x  2 root root     44726 Nov 10  2015 perlbug
-rwxr-xr-x  1 root root       224 Nov 10  2015 perldoc
-rwxr-xr-x  2 root root     44726 Nov 10  2015 perlthanks
And for hte final one :

Code: Select all

ERROR: Sorry, user nagios is not allowed to execute '/opt/zimbra/libexec/zmqstat' as root on avenger.solutions4ebiz.com.
So maybe it is coming from there nah ?

Re: NRPE - Unable to read output (Zimbra plugin

Posted: Thu Aug 04, 2016 2:12 pm
by tgriep
Yes, you will have to update the sudoers file for that perl script and that should fix it for you.

Re: NRPE - Unable to read output (Zimbra plugin

Posted: Thu Aug 04, 2016 2:19 pm
by Gouteya
Updated the sudoers file , it works for your command but none for the rest :

Code: Select all

[nagios@avenger ~]$ /usr/local/nagios/libexec/zmqstat.pl -q deferred -w 20 -c 25
Queue deferred: 29 | 'deferred'=29;20;25;0;
Meanwhile :( :

Code: Select all

[root@avenger ~]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_zimbraqueue
NRPE: Unable to read output

Re: NRPE - Unable to read output (Zimbra plugin

Posted: Thu Aug 04, 2016 3:05 pm
by tgriep
Now that the nagios user can run the plugin, try removing the following from the command and see if it works.

Code: Select all

/usr/bin/sudo 

Re: NRPE - Unable to read output (Zimbra plugin

Posted: Thu Aug 04, 2016 3:22 pm
by Gouteya
Wow you're the boss man , thanks a lot for your help , it was fast and really precise :). Hope I will help some users like you

Re: NRPE - Unable to read output (Zimbra plugin

Posted: Thu Aug 04, 2016 3:58 pm
by hsmith
Did you need any other assistance, or are we good to consider this thread resolved?