Page 1 of 2

NRPE: unable to read output.

Posted: Wed Jun 06, 2018 6:08 am
by Ravikimt
Node service is running on remote Linux host and I have to monitor the node service from Nagios server. I have crated my script [check_node]

But I am getting this error NRPE: unable to read output.

Added this command in my nre.cfg file.

Code: Select all

command[check_node]=/usr/local/nagios/libexec/node_check $ARG1$
added command in command.cfg file.

#'check_node' command definition

Code: Select all

define command{
       command_name    check_node
       command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
       }

Added service in linux_servers.cfg.

Code: Select all

define service{
        use                        local-service         ; Name of service template to use
        host_name                  Sales-Demo
        service_description        Node Service
        check_command          check_nrpe!check_node
        contact_groups             Nagios
        notification_options       w,u,c,r
        notification_interval      10
        notification_period        24x7
        }
I checked the permission of my script as well both the sides on Nagios server and remote host also.

Code: Select all

-rwxr-xr-x 1 root root 340 Jun  5 21:07 check_node
I have gone through the remote host nrpe.log also i am getting below mentioned error in the log file.

Code: Select all

[1528212140] Host address is in allowed_hosts
[1528212141] Host 10.10.100.35 is asking for command 'check_node' to be run...
[1528212141] Running command: /usr/local/nagios/libexec/check_node
[1528212141] WARNING: my_system() seteuid(0): Operation not permitted
Can someone suggest me on this.? Thanks in advance.

Re: NRPE: unable to read output.

Posted: Wed Jun 06, 2018 6:42 am
by danjoh
Does your script "/usr/local/nagios/libexec/node_check" run correctly when you run it as the nrpe/nagios user?

i.e.

Code: Select all

su nagios /usr/local/nagios/libexec/node_check
or

Code: Select all

su nrpe /usr/local/nagios/libexec/node_check
dependent on if your nrpe-daemon runs as nagios or nrpe.

Do you have se-linux enabled? If yes try to disable it and test again.
I do not know how you script looks like, but it looks like it is calling some command/script that has the suid-bit set and the user nagios/nrpe is not allowed to execute this command/script.

Re: NRPE: unable to read output.

Posted: Wed Jun 06, 2018 10:47 am
by Ravikimt
My check_node script

Code: Select all

#!/bin/bash

#Mentioned valid service name
service=node

#Checking for service pid value
pid=`ps -ef | grep -v grep | grep -i $service | wc -l`

case $pid in
[2]*)

echo "OK -$service is running" 
exit 0
;;

[0]*)

echo "CRITICAL -$service is not running"
exit 2
;;

[1]*)

echo "WARNING -$service Please check the service"
exit 1
;;

esac
I tried with this option because nrpe is running as nagios user but still I am getting same problem.

Code: Select all

su nagios /usr/local/nagios/libexec/node_check
I am using Ubuntu 16.04 LTS and by default se-linux wouldn't be enable on this. Same process I have followed to monitor python service and it's working fine. I don't know why It's not working for this.? I just changed service name in my script instead of node before that it was python .

But that works fine. Please help I have to finish this task today itself at any coast.

Re: NRPE: unable to read output.

Posted: Wed Jun 06, 2018 2:23 pm
by scottwilkerson
So what is the output of this command

Code: Select all

su nagios -c /usr/local/nagios/libexec/node_check
how about as root

Code: Select all

/usr/local/nagios/libexec/node_check

Re: NRPE: unable to read output.

Posted: Wed Jun 06, 2018 11:03 pm
by Ravikimt
scottwilkerson I tried both the commands as you suggested but it didn't workout for me.

Code: Select all

su nagios -c /usr/local/nagios/libexec/node_check
Output of this command is NRPE:Unable to read output

Code: Select all

/usr/local/nagios/libexec/node_check
Output of this command is NRPE:Unable to read output

I am getting same error with both the commands no changes in output. @scottwilkerson If you remembered I have followed same steps to monitor my python service that time it worked fine. I am following same steps here to monitor node but getting error.

Please suggest something here I will wait for your reply @scottwilkerson.

Re: NRPE: unable to read output.

Posted: Thu Jun 07, 2018 9:03 am
by scottwilkerson
I meant run them on the machine by themselves, NOT through NRPE

Re: NRPE: unable to read output.

Posted: Thu Jun 07, 2018 9:39 am
by Ravikimt
I ran this command on remote Linux host as well as Nagios server also it gives me same output.

Code: Select all

su nagios -c /usr/local/nagios/libexec/node_check
Password: 
su: Authentication failure
Then I ran this command on Nagios sever it gives me correct output.

Code: Select all

bash /usr/local/nagios/libexec/check_node 
OK -node is running
Same when I am running on remote host it doesn't give any output.

Re: NRPE: unable to read output.

Posted: Thu Jun 07, 2018 9:50 am
by scottwilkerson
how about

Code: Select all

sudo su nagios -c /usr/local/nagios/libexec/node_check

Re: NRPE: unable to read output.

Posted: Thu Jun 07, 2018 9:54 am
by Ravikimt
It doesn't gives any output when I run on remote Linux machine.

Getting error when I run on Nagios server.

Code: Select all

 sudo su nagios -c /usr/local/nagios/libexec/node_check
bash: /usr/local/nagios/libexec/node_check: No such file or directory

Re: NRPE: unable to read output.

Posted: Thu Jun 07, 2018 10:04 am
by scottwilkerson
Ravikimt wrote:It doesn't gives any output when I run on remote Linux machine.
This means there is something in the plugin that the nagios user can't run.

If the output of the plugin is blank, then you would get the error you see from NRPE.

For debugging purposes, I would add the following above your case statement to see what the value of PID is as your case doesn't have a default echo:

Code: Select all

echo $pid
Then run again as the nagios user

Code: Select all

sudo su nagios -c /usr/local/nagios/libexec/node_check