NRPE: Unable to read output - Custom Plugin Script

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.
pmoradiya
Posts: 26
Joined: Fri Oct 06, 2017 9:48 am

NRPE: Unable to read output - Custom Plugin Script

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

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

Post 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
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
pmoradiya
Posts: 26
Joined: Fri Oct 06, 2017 9:48 am

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

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

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

Post 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}'
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
pmoradiya
Posts: 26
Joined: Fri Oct 06, 2017 9:48 am

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

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

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

Post 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 ?
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
pmoradiya
Posts: 26
Joined: Fri Oct 06, 2017 9:48 am

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

Post 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.
Attachments
check_heap_custom.sh.txt
script to check jvm heap size
(1.81 KiB) Downloaded 241 times
bolson

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

Post 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.
pmoradiya
Posts: 26
Joined: Fri Oct 06, 2017 9:48 am

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

Post 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.
bolson

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

Post 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?
Locked