Page 1 of 1

Nagios server is giving wrong output

Posted: Thu Jul 06, 2017 9:03 am
by grayloglearn
HI team,

I want to monitor the tomcat heap memory for this i have created small script, while i am executing the script i am able to get the right output from remote server. The same script i am calling the check_nrpe i am not able to get the wrong out put for ex: if remote server out put is Critical , the nagios server output OK like this i am getting the wrong output.

The below is my script

#!/bin/bash
process=`ps -ef | grep java | grep -v grep | cut -f6 -d ' '| head -n 1`
max=`jmap -heap $process | grep MaxHeapSize | awk '{printf $4}' | tr -s "." " " | awk '{print $1}' | tr -s "(" " " | awk '{print $1}'`
if [ $max -gt 2000 ] ; then

echo "CRITICAL: $max"
exit 2
else
echo "OK: $max"
exit 0
fi
---------------------------------------------------------------------

I have given the in sudo file as
Defaults:nagios !requiretty
Defaults:nrpe !requiretty
nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/check_heap (I saved the script in check_heap)

Re: Nagios server is giving wrong output

Posted: Thu Jul 06, 2017 9:08 am
by tmcdonald
Can you show us your actual service definition? It sounds like you might not be running it through check_nrpe.

Re: Nagios server is giving wrong output

Posted: Fri Jul 07, 2017 2:50 am
by grayloglearn
Hi ,

Thanks for the reply

i have followed below steps in remote server nrpe.cfg as
command[check_heap]=/usr/local/nagios/libexec/check_heap

i have followed below steps in Nagios server as


define service{
use local-service ; Name of service template to use
host_name Testing
service_description Heap-Memory
check_command check_nrpe!check_heap
register 1
}


I followed below command to execute .
/usr/local/nagios/libexec/check_nrpe -H 192.168.0.5 -c check_heap
OK:

Instead of OK i should get CRITICAL the same script working at remote server perfectly.

Re: Nagios server is giving wrong output

Posted: Fri Jul 07, 2017 11:46 am
by scottwilkerson
you may need to add the following to your nrpe config

Code: Select all

command[check_heap]=sudo /usr/local/nagios/libexec/check_heap
Additionally, nrpe runs the script under a restricted environment so you may need to alter your script to put the full path to jmap in this line

Code: Select all

max=`jmap -heap $process | grep MaxHeapSize | awk '{printf $4}' | tr -s "." " " | awk '{print $1}' | tr -s "(" " " | awk '{print $1}'`
Finally depending on how you installed NRPE, the nagios user may not be running the check, the nrpe user may be (if there is one).

Re: Nagios server is giving wrong output

Posted: Mon Jul 10, 2017 4:49 am
by grayloglearn
Hi ,

Issue got resolved by adding the two below steps.

command[check_heap]= sudo /usr/local/nagios/libexec/check_heap

max=`/opt/jdk1.7.0_79/bin/jmap -heap $process | grep MaxHeapSize | awk '{printf $4}' | tr -s "." " " | awk '{print $1}' | tr -s "(" " " | awk '{print $1}'`

Thanks scottwilkerson

Re: Nagios server is giving wrong output

Posted: Mon Jul 10, 2017 9:34 am
by tmcdonald
Did you have any further (related) questions or are we okay to close this thread?

Re: Nagios server is giving wrong output

Posted: Tue Jul 11, 2017 6:36 am
by grayloglearn
yes please