NRPE: Unable to read output only fails on custom script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: NRPE: Unable to read output only fails on custom script

Post by gormank »

Is the nagios user not able to run df? Can you try removing the sudo in the df commands?
You might try putting an echo something and exit 0 at the top of the script to see what happens. If nothing changes, the trouble isn't in the script...

#!/bin/bash
echo testing
exit 0
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: NRPE: Unable to read output only fails on custom script

Post by hsmith »

@lee.krause, let us know how @gormank's instructions worked for you. Thanks!
Former Nagios Employee.
me.
lee.krause
Posts: 86
Joined: Wed Jan 20, 2016 8:38 am

Re: NRPE: Unable to read output only fails on custom script

Post by lee.krause »

Sorry I've been away from the office.
I added the following to the sudoers file:
Cmnd_Alias NAG = /usr/bin/grep, \
/usr/bin/df
nagios ALL=(root) NOPASSWD:NAG

I also tried removing the sudo from the script but have the same result.

When the check_nrpe script is initiated, does it run "su nagios"?
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: NRPE: Unable to read output only fails on custom script

Post by lmiltchev »

When the check_nrpe script is initiated, does it run "su nagios"?
The check_nrpe runs as whatever user nagios is running as, which is usually 'nagios'. NRPE will use the 'nrpe_user' in nrpe.cfg unless it's running under inetd, in which case it will run as 'root' or whatever user is specified in the inetd config.
# NRPE USER
# This determines the effective user that the NRPE daemon should run as.
# You can either supply a username or a UID.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd

nrpe_user=nagios



# NRPE GROUP
# This determines the effective group that the NRPE daemon should run as.
# You can either supply a group name or a GID.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd

nrpe_group=nagios
Let's try the following:

On the remote box

1. Create a test script, for example named "check_test.sh", and set permissions.

Code: Select all

#!/bin/bash
echo $1
exit 0
chmod 775

2. Add the command to the nrpe.cfg file:

Code: Select all

command[check_test]=/etc/nagios/nrpe/check_test.sh $ARG1
3. Restart nrpe (if it's running as a standalone daemon) or inetd/xinetd.

Test the check on the Nagios box (example):

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H <client ip> -c check_test -a 'testing'
testing
echo $?
0
If this works, the issue must be in your script.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked