Script returns different result when ran locally versus nrpe
Posted: Tue Oct 28, 2014 1:04 pm
I have a script that I can run locally and get the proper return. When I try to run it using check_nrpe, either on the system itself or from the Nagios server, I get an improper response.
This is the response running locally:
./check_redis.sh
REDIS Sentinel 16379 on dencita1 is active and PONG was the response
REDIS Nuxeo 6379 on dencita1 is active and PONG was the response
This is the response when running with nrpe:
./check_nrpe -H localhost -c check_redis
REDIS Sentinel 16379 on dencita1 not active and did not PONG
The scripts is here:
Any ideas?
Thanks
This is the response running locally:
./check_redis.sh
REDIS Sentinel 16379 on dencita1 is active and PONG was the response
REDIS Nuxeo 6379 on dencita1 is active and PONG was the response
This is the response when running with nrpe:
./check_nrpe -H localhost -c check_redis
REDIS Sentinel 16379 on dencita1 not active and did not PONG
The scripts is here:
Code: Select all
#!/usr/bin/env bash
################# Check SENTINEL Port #################
HOSTNAME_REDIS=`hostname -s`
# Gather ports (default sentinel port is 26379)
# SEN_PORT=`grep -P '^port \d+' /etc/redis/rsentinel.conf || echo "port 26379" | cut -f2 -d' '`
# SEN_PORT=`grep -P '^port \d+' /etc/redis/rsentinel.conf | cut -f2 -d' '`
# SEN_PORT=`grep -P '^port ' /etc/redis/rsentinel.conf | cut -f2 -d' '`
SEN_PORT=`grep -w port /etc/redis/rsentinel.conf | cut -f2 -d' '`
# if [[ `redis-cli -p $SEN_PORT PING | grep 'PONG' 2>&1 >/dev/null` ]];then
if [[ `redis-cli -p $SEN_PORT PING | grep 'PONG'` ]];then
# Success
echo "REDIS Sentinel $SEN_PORT on $HOSTNAME_REDIS is active and PONG was the response"
else
# Failure
echo "REDIS Sentinel $SEN_PORT on $HOSTNAME_REDIS $port not active and did not PONG"
exit 1
fi
################# Check MOBILE Port #################
if [[ `find /apps/opt -maxdepth 1 -type d | grep /apps/opt/Tomcat_JDM` \
|| `find /apps/opt -maxdepth 1 -type d | grep /apps/opt/Tomcat_PWM` \
|| `find /apps/opt -maxdepth 1 -type d | grep /apps/opt/Tomcat_FDS` \
|| `find /apps/opt -maxdepth 1 -type d | grep /apps/opt/Tomcat_SYNC` \
|| `find /apps/opt -maxdepth 1 -type d | grep /apps/opt/Tomcat_REGISTRAR` ]];then
MOBIL_PORT=`grep -w MobileServices_Redis_Master /etc/redis/rsentinel.conf | cut -f5 -d' '`
if [ -z $MOBIL_PORT ];then
echo "MOBILE REDIS NOT DEFINED IN SENTINEL. WARNING MR. ROBINSON"
exit 178
fi
# if [[ `redis-cli -p $MOBIL_PORT PING | grep 'PONG' 2>&1 >/dev/null` ]];then
if [[ `redis-cli -p $MOBIL_PORT PING | grep 'PONG'` ]];then
# Success
echo "REDIS Mobile $MOBIL_PORT on $HOSTNAME_REDIS is active and PONG was the response"
else
# Failure
echo "REDIS Mobile $MOBIL_PORT on $HOSTNAME_REDIS $port not active and did not PONG"
exit 1
fi
fi
################### Check NUXEO Port #################
if [[ `find /apps/opt -maxdepth 1 -type d | grep /apps/opt/nuxeo-jdm-server` ]];then
# NUXEO_PORT=`ls -1 /etc/redis/*.conf | cut -f1 -d' ' | grep -v $MOBIL_PORT`
# NUXEO_PORT=`grep -P '^#sentinel monitor Nuxeo_Redis_Master ' /etc/redis/rsentinel.conf | cut -f5 -d' '`
NUXEO_PORT=`grep -w Nuxeo_Redis_Master /etc/redis/rsentinel.conf | cut -f5 -d' '`
if [ -z $NUXEO_PORT ];then
echo "NUXEO REDIS NOT DEFINED IN SENTINEL. WARNING MR. ROBINSON"
exit 178
fi
# if [[ `redis-cli -p $NUXEO_PORT PING | grep 'PONG' 2>&1 >/dev/null` ]];then
if [[ `redis-cli -p $NUXEO_PORT PING | grep 'PONG'` ]];then
# Success
echo "REDIS Nuxeo $NUXEO_PORT on $HOSTNAME_REDIS is active and PONG was the response"
else
# Failure
echo "REDIS Nuxeo $NUXEO_PORT on $HOSTNAME_REDIS $port not active and did not PONG"
exit 1
fi
fiThanks