Page 1 of 2

NRPE: Unable to read output - Custom Plugin Script

Posted: Fri Oct 06, 2017 3:35 pm
by pmoradiya
Hi

I have been trying to get my custom plugin (simple script) to return appropriate return code based on warning and critical threshold.

Running this plugin manually (as shell script) returns expected results.

Code: Select all

root@server-1:/# /usr/local/nagios/libexec/check_heap_custom.sh -w 13839455574 -c 6919727787
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.6) (7u79-2.5.6-0ubuntu1.14.04.1)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
OK
However, running with NRPE returns "Unable to read output" both on the client host and on the monitoring host.

Code: Select all

root@server-1:/# grep heap /usr/local/nagios/etc nrpe.cfg
command[check_tomcat_heap]=sh /usr/local/nagios/libexec/check_jvm_custom.sh -w 1466538393 -c 1780796620

root@server-1:/# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_tomcat_heap
NRPE: Unable to read output

Any suggestions?


Thanks in advance for your inputs.

Re: NRPE: Unable to read output - Custom Plugin Script

Posted: Fri Oct 06, 2017 4:11 pm
by scottwilkerson
Can you run the following?

Code: Select all

sudo su nagios -c "/usr/local/nagios/libexec/check_heap_custom.sh -w 13839455574 -c 6919727787"
Also, it is worth noting that any environment variables this script depends on may not be available and should be specified in the script

Re: NRPE: Unable to read output - Custom Plugin Script

Posted: Fri Oct 06, 2017 6:46 pm
by pmoradiya
scottwilkerson wrote:Can you run the following?

Code: Select all

sudo su nagios -c "/usr/local/nagios/libexec/check_heap_custom.sh -w 13839455574 -c 6919727787"
Also, it is worth noting that any environment variables this script depends on may not be available and should be specified in the script
The script doesn't have environment variables and its main content is processing the output of the following command:

Code: Select all

java -XX:+PrintFlagsFinal -version | grep -i 'MaxHeapSize' | awk '{print $4}'
I have also tried running the command with "sudo su nagios" but returns the same result.

Re: NRPE: Unable to read output - Custom Plugin Script

Posted: Mon Oct 09, 2017 11:33 am
by scottwilkerson
pmoradiya wrote: I have also tried running the command with "sudo su nagios" but returns the same result.
What results?

also this command assumes the environment knows where java is located, which is usually added to an environment PATH

Code: Select all

java -XX:+PrintFlagsFinal -version | grep -i 'MaxHeapSize' | awk '{print $4}'

Re: NRPE: Unable to read output - Custom Plugin Script

Posted: Tue Oct 10, 2017 8:25 am
by pmoradiya
scottwilkerson wrote:
pmoradiya wrote: I have also tried running the command with "sudo su nagios" but returns the same result.
What results?

also this command assumes the environment knows where java is located, which is usually added to an environment PATH

Code: Select all

java -XX:+PrintFlagsFinal -version | grep -i 'MaxHeapSize' | awk '{print $4}'
Line from nrpe.cfg:
command[check_tomcat_heap]=sudo su nagios -c /usr/local/nagios/libexec/check_jvm_custom.sh -w 1466538393 -c 1780796620

root@prod-server-1:/usr/local/nagios/etc# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_tomcat_heap
NRPE: Unable to read output

Running with or without "sudo" returns the expected results (also shows Java is in the environment PATH)
root@prod-server-1:/usr/local/nagios/etc# sudo su nagios -c "/usr/local/nagios/libexec/check_heap_custom.sh -w 13839455574 -c 6919727787"
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.6) (7u79-2.5.6-0ubuntu1.14.04.1)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
OK

root@prod-server-1:~# /usr/local/nagios/libexec/check_heap_custom.sh -w 13839455574 -c 6919727787
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.6) (7u79-2.5.6-0ubuntu1.14.04.1)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
OK

root@prod-server-1:/usr/local/nagios/etc# which java
/usr/bin/java

Re: NRPE: Unable to read output - Custom Plugin Script

Posted: Tue Oct 10, 2017 9:18 am
by scottwilkerson
I would just set the nrpe config to this

Code: Select all

command[check_tomcat_heap]=/usr/local/nagios/libexec/check_jvm_custom.sh -w 1466538393 -c 1780796620
then restart nrpe

Is NRPE running under xinetd or stand alone?

Is localhost added to the allowed_hosts( or only_from in /etc/xinetd.d/nrpe config)

would it be possible to share check_heap_custom.sh ?

Re: NRPE: Unable to read output - Custom Plugin Script

Posted: Tue Oct 10, 2017 11:11 am
by pmoradiya
scottwilkerson wrote:I would just set the nrpe config to this

Code: Select all

command[check_tomcat_heap]=/usr/local/nagios/libexec/check_jvm_custom.sh -w 1466538393 -c 1780796620
then restart nrpe

Is NRPE running under xinetd or stand alone?

Is localhost added to the allowed_hosts( or only_from in /etc/xinetd.d/nrpe config)

would it be possible to share check_heap_custom.sh ?
I had tried the following..

Code: Select all

command[check_tomcat_heap]=/usr/local/nagios/libexec/check_jvm_custom.sh -w 1466538393 -c 1780796620
And getting the following results:

Code: Select all

root@prod-server-1:/usr/local/nagios/libexec# ./check_heap_custom.sh -w 1466538393 -c 1780796620
OK
root@prod-server-1:/usr/local/nagios/libexec# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_tomcat_heap
UNKNOWN heap usage
Regarding NRPE, I'm running with xinetd and localhost is in the allowed hosts. IP with 208 is monitoring server IP.
allowed_hosts=127.0.0.1,10.0.0.208

check_heap_custom script is in the attachment.

Re: NRPE: Unable to read output - Custom Plugin Script

Posted: Tue Oct 10, 2017 11:30 am
by bolson
The hosts in your /etc/xinetd.d/nrpe file should be separated by a space rather than by a comma:

This:

Code: Select all

allowed_hosts=127.0.0.1 10.0.0.208
not this:

Code: Select all

allowed_hosts=127.0.0.1,10.0.0.208
Be sure and restart xinetd.

Re: NRPE: Unable to read output - Custom Plugin Script

Posted: Tue Oct 10, 2017 11:38 am
by pmoradiya
bolson wrote:The hosts in your /etc/xinetd.d/nrpe file should be separated by a space rather than by a comma:

This:

Code: Select all

allowed_hosts=127.0.0.1 10.0.0.208
not this:

Code: Select all

allowed_hosts=127.0.0.1,10.0.0.208
Be sure and restart xinetd.
Thanks for your prompt responses. The nrpe.cfg says "# ALLOWED HOST ADDRESSES # This is an optional comma-delimited list of IP address or hostnames".

However, I updated it with space-delimited allowed hosts and restarted nrpe service. It returned the same result.

Re: NRPE: Unable to read output - Custom Plugin Script

Posted: Tue Oct 10, 2017 11:43 am
by bolson
The correct syntax differs between nrpe.cfg (comma delimited) and /etc/xinetd.d/nrpe (space delimited)

Are the hosts delimited by a space in /etc/xinetd.d/nrpe?