NAgios plugin works from command line but not via NRPE

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
b0br0ff
Posts: 2
Joined: Tue Jan 12, 2016 2:54 pm

NAgios plugin works from command line but not via NRPE

Post by b0br0ff »

Hi Everybody, thank you in advance if somebody can help with following issue.

My Nagios plugin needs to connect o MySQL server and grep some info from there. In case of unsuccessful connection attempt it needs to count connection failures and show status as WARNING in case of connection failures less then 3 and if more then 3 => CRITICAL. So, I store connection failures in the text file in /tmp/fails.count

My problem is that when I execute script from command line on a client machine it works as expected, however when I executed from Nagios server it always returns 1 as fails count.

Output at client:
[root@cent1 ~]# /usr/lib/nagios/plugins/check_DP_status.sh
DP verification failed 5 times (TCP port 3307): ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)


Output at server:
[root@cent2 20160111]# /usr/lib/nagios/plugins/check_nrpe -H 192.168.178.30 -c check_dp_status
File /tmp/fails.count exist and is accessible!
Fails count=
DP verification failed 1 times (TCP port 3307): ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)


Environment:
OS: Centos 6.5
Language: bash

Code: Select all

COUNTER_FILE="/tmp/fails.count"
#MySQL settings
MYSQL_USER=xxx
MYSQL_PASSWD=xxx
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3307
MYSQL_QUERY="SELECT count(*) FROM ...."
MYSQL_OPT="--host=${MYSQL_HOST} --port=${MYSQL_PORT} --user=${MYSQL_USER} --password=${MYSQL_PASSWD}"
#End MySQL settings


mysql ${MYSQL_OPT} --execute="${MYSQL_QUERY}" > ${LOG_DP_STATUS} 2> ${LOG_ACCESS}

if [ -s "${LOG_ACCESS}" ]; then
	#Could not connect to MySQL
	MSG=`tail -n 1 ${LOG_ACCESS}`
	COUNT=
	
	#Create a new counter file if one doesn't exist already
	if [ -r $COUNTER_FILE ] ; then
		echo "File $COUNTER_FILE exist and is accessible!"
	    #COUNT=$(<$COUNTER_FILE)
	   COUNT=$(cat $COUNTER_FILE)
	   echo "Fails count=$COUNT"
	else
		echo "File $COUNTER_FILE does not exist!"
		COUNT=0
	fi

	#Increment counter and save to file 
	COUNT=$(( COUNT += 1 ))
	echo $COUNT > $COUNTER_FILE
	#echo "Fails count=$COUNT"
	echo "DP verification failed $COUNT times (TCP port ${MYSQL_PORT}): ${MSG}"
	
	#check if fails count is 3
	if [[ $(($COUNT)) -gt 3 ]] ; then
	   #We have reached 3
	   exit 2
	fi
	
	exit 1
else
	COUNT=0
	echo $COUNT > $COUNTER_FILE
fi

Regards
Evghenii
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: NAgios plugin works from command line but not via NRPE

Post by hsmith »

Can you try to run the script on the client as the nagios user account?
Former Nagios Employee.
me.
b0br0ff
Posts: 2
Joined: Tue Jan 12, 2016 2:54 pm

Re: NAgios plugin works from command line but not via NRPE

Post by b0br0ff »

Hi actually nagios account has "nologin" option in /etc/passwd. Might be this a reason?
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: NAgios plugin works from command line but not via NRPE

Post by hsmith »

That could be an issue. The /etc/passwd entry for the nagios account on my VPS is this:

Code: Select all

grep nagios /etc/passwd
nagios:x:1002:1002::/home/nagios:/bin/sh
Former Nagios Employee.
me.
Locked