Plugin does not work with nrpe


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($$);

GetOptions("V"   => \$opt_V, "version"    => \$opt_V,
           "h"   => \$opt_h, "help"       => \$opt_h);

if ($opt_V) {
    print " version 0.001 by michas\n";

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

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):


results on a “new” machine:

root# /usr/local/nagios/libexec/
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 -c check_uptime
NRPE: Unable to read output

any idea?



try that: … .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…



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/

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


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.