Plugin does not work with nrpe

hi,
recently I tried to write my own plugin in perl. it works fine, but I can’t make it run with NRPE. I’m new in this, can’t find solution. I’m not using embedded perl. I want my script to simply check uptime on an unix machine. here’s the code:

#! /usr/bin/perl -w
#simple perl script for checking uptime on the unix machine
#

use strict;
use Getopt::Long;
use Pod::Usage;
use lib '/usr/local/nagios/libexec/';
use utils qw(%ERRORS);

use vars qw($opt_V $opt_h);

sub nagexit($$);

#Getopt::Long::Configure('bundling');
GetOptions("V"   => \$opt_V, "version"    => \$opt_V,
           "h"   => \$opt_h, "help"       => \$opt_h);


if ($opt_V) {
    print "check_uptime.pl version 0.001 by michas\n";
    exit();
}

if ($opt_h) {
    print "call with no parameters for normal use;\n";
    print "-V for version\n";
    print "-h for this help\n";
    exit();
}

my $uptime=`uptime`;
#print "$uptime\n";
nagexit('OK', "$uptime");

sub nagexit($$) {
    my $errlevel = shift;
    my $string = shift;

    print "$errlevel: $string";
    exit $ERRORS{$errlevel};

}

master server service definition:

define service{
        host_name                       new
        service_description             uptime
        check_command                   check_nrpe!check_uptime
        }

and command on a “new” host (virtualized ubuntu-jeos):

command[check_uptime]=/usr/lib/nagios/libexec/check_uptime.pl

results on a “new” machine:

root# /usr/local/nagios/libexec/check_uptime.pl
OK:  12:46:16 up 2 days,  4:43,  2 users,  load average: 0.00, 0.00, 0.00

and on a master server:

root# /usr/local/nagios/libexec/check_nrpe -H 192.168.4.119 -c check_uptime
NRPE: Unable to read output

any idea?
greetings.

yup

try that:
meulie.net/portal_plugins/fo … .php?11783

ok, but still… the above does not resolve my problem. the script gives expected results when run from command line, without nrpe… paths are the same on both machines, both are virtualized ubuntu-jeos’es…

Hi,

Your nrpe is very likely running stuff as the user ‘nagios’ (look in your nrpe.cfg, or your xinetd definition if you’re using xinetd). Does your nagios user have access to all the stuff that perl script is calling?

Try adding the following to your sudoers file:
nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/libexec/check_uptime.pl

and then throwing a ‘sudo’ in front of your check_uptime command definition ie:
check_command sudo /usr/lib/nagios/libexec/check_uptime.pl

ok, I found error myself… as always, some small thing… first line in my script:

should be:

theres space between #! and path to perl… thanks anyway.