Server check_nrpe returning unexpected value for plugin

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
ski2tee
Posts: 2
Joined: Thu Jun 16, 2016 12:45 pm

Server check_nrpe returning unexpected value for plugin

Post 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
}
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Server check_nrpe returning unexpected value for plugin

Post 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).
Former Nagios Employee
ski2tee
Posts: 2
Joined: Thu Jun 16, 2016 12:45 pm

Re: Server check_nrpe returning unexpected value for plugin

Post 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!
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Server check_nrpe returning unexpected value for plugin

Post 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).
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked