Search code examples
bashpluginsmonitoringnagiosnrpe

Custom nagios plugin can't read output


I've created a simple plugin using nagios to be run with NRPE and it runs fine in the command line but when I run it via nrpe, it says "NRPE: can't read the output"

It has to do with not being able to read the file because if I just echo a fixed string, it works fine. I made sure the permissions were 644.

Anyone know what is happening?

Here is the invocations I use:

/usr/lib64/nagios/plugins/check_nrpe -H 192.168.1.10 -p 5666 -c local_check

Here is the config command in nrpe.conf

command[local_check]=/usrl/lib64/nagios/plugins/local_check

Here is code for the plugin (simplified I obviously have more checks to create the status file) :

#!/usr/bin/bash

HOST="127.0.0.1"
CACHE_FILE="/tmp/local_check"

echo "0">$CACHE_FILE
echo "This is the status code I want">>$CACHE_FILE

ret_code=$(/usr/bin/cat $CACHE_FILE|/usr/bin/sed -n 1p)
status=$(/usr/bin/cat $CACHE_FILE|/usr/bin/sed -n 2p )
/usr/bin/cat $CACHE_FILE|/usr/bin/sed -n 2p
exit $ret_code

Solution

  • I disabled SELinux and rebooted the system. After that, it work, so it is an SELinux problem. Other issues that may come up are opening tcp port 5666 in the firewall, missing library (run plugin from the command line first) and if it is a root only operation that cannot be run by the nagios plugin, you need to account for it too