Page 1 of 1
Server check_nrpe returning unexpected value for plugin
Posted: Thu Jun 16, 2016 1:44 pm
by ski2tee
I have a server and host both running CentOS 6. I wrote a plugin to monitor a directory and notify if any files appear. When I run the plugin directly on the host I get the correct response. When I run it from the server I get something different. See below for code.
Host returns the correct response of CRITICAL: 2 files
Code: Select all
/usr/lib64/nagios/plugins/check_file_count
Server returns the incorrect response of OK: 0 files
Code: Select all
/usr/lib64/nagios/plugins/check_nrpe -H host.ipaddress -c check_file_count
Plugin check_file_count:
Code: Select all
OK_STATE=0
CRITICAL_STATE=2
file_count=0
file_count=`ls /home/user1/ | wc -l`
if [ $file_count -gt 0 ]
then
echo "CRITICAL:" $file_count "files"
exit $CRITICAL_STATE
fi
echo "OK:" $file_count "files"
exit $OK_STATE
command.cfg
Code: Select all
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS -c $ARG1$
}
server.cfg
Code: Select all
define command{
command_name check_file_count
command_line $USER1$/check_nrpe $HOSTADDRESS -c check_file_count
}
define service{
use local-service
host_name host
service_description check_file_count
check_command check_nrpe!check_file_count
notifications_enabled 1
contact_groups test
}
Re: Server check_nrpe returning unexpected value for plugin
Posted: Thu Jun 16, 2016 2:00 pm
by rkennedy
When you test running the plugin locally, what user are you using? I suspect that the NRPE user doesn't have the correct permissions to be able to execute ls -l /home/user1/ directory.
You'll want to adjust the permissions on the folder, and test running as the nagios user (or whatever user NRPE is set to run as).
Re: Server check_nrpe returning unexpected value for plugin
Posted: Mon Jun 20, 2016 7:13 am
by ski2tee
rkennedy, that was indeed the issue. I had been banging my head against the wall and never thought to check permissions and the fact that the command would be running as the nrpe user when issued remotely. What is the norm when giving permissions to the nrpe user on the agent? Is it common practice to add a secondary group to the nrpe user to allow access to system files? Thanks for the help!
Re: Server check_nrpe returning unexpected value for plugin
Posted: Mon Jun 20, 2016 12:30 pm
by lmiltchev
It is not unusual to add a command to the sudoers that needs to be executed by the nagios (or nrpe) user, and to prepend the command in the nrpe.cfg with "sudo" (if needed).