NRPE: Unable to read output

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
Pratapa
Posts: 144
Joined: Tue Oct 01, 2019 1:33 am

NRPE: Unable to read output

Post by Pratapa »

Hi,

We are getting following error when we execute from Nagios server.

[root@nagios libexec]# ./check_nrpe -H host1 -c check_event
NRPE: Unable to read output

Following is the entry in nrpe.cfg on client machine.

command[check_event]=/usr/lib64/nagios/plugins/ce/check_monitor.sh


When we execute as nagios user it is getting executed.

[root@host1 nagios]# su - nagios
-bash-4.2$ /usr/lib64/nagios/plugins/ce/check_monitor.sh
No Event noticed from Azure Backend
-bash-4.2$


"No Event noticed from Azure Backend" is the output of the script /usr/lib64/nagios/plugins/ce/check_monitor.sh

What should be the problem?
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: NRPE: Unable to read output

Post by gormank »

I think one possibility is that whatever is producing the output in the script is writing on STDERR, and Nagios is expecting output on STDOUT.
Maybe try to see if the output disappears in the test:
/usr/lib64/nagios/plugins/ce/check_monitor.sh 2>/dev/null

If so, updating the script to redirect whatever produces the output to redirect to 2>&1 should help.
Pratapa
Posts: 144
Joined: Tue Oct 01, 2019 1:33 am

Re: NRPE: Unable to read output

Post by Pratapa »

[root@host1 nrpe.d]# /usr/lib64/nagios/plugins/ce/check_monitor.sh 2> /dev/null
No Event noticed from Azure Backend

I did some troubleshooting.

I deleted the contents of the file check_monitor.sh and just placed the following code

echo "Hello"

and when I executed it from Nagios server, following is the output.

[root@nagios libexec]# ./check_nrpe -H host1 -c check_event
Hello

It means something wrong with the script.

Then I started debugging line by line in chech_monitor.sh script.

I placed following code in the script check_monitor.sh

--------------------------------------------------------------------------------------
ls -l /var/log/event.txt > /dev/null 2>&1

if [ $? -ne 0 ]
then
echo "event.txt file does not exist"
exit 1
fi


n1=`cat /var/log/event.txt | grep "NO Event noticed from Azure Backend"|wc -l`

echo "Value of n1 is $n1"

------------------------------------------------------------------

When I execute the script on client machine, we are getting correct results

[root@host1 ]# sh check_monitor.sh
Value of n1 is 1

When I invoke the script from Nagios server we are getting different results.

[root@nagios libexec]# ./check_nrpe -H host1 -c check_event
Value of n1 is 0



[root@host1 ]#cat /var/log/event.txt
08.Sep_12:26 NO Event noticed from Azure Backend

/var/log/event.txt contains only one line and the output should be "Value of n1 is 1". We are getting the output "Value of n1 is 0" when
we invoke from Nagios server. Not sure of this weird behaviour.

[root@nagios libexec]# ./check_nrpe -H host1 -c check_event
Value of n1 is 0
Locked