Page 2 of 4
Re: Script returns different result when ran locally versus
Posted: Fri Oct 31, 2014 9:23 am
by rickwilson7425
Well, I've tried what combinations of switches for the echo command and escape sequences I could figure out.
My lack of in depth knowledge in scripting is probably keeping me from seeing the obvious.
Any help on this would be appreciated.
Re: Script returns different result when ran locally versus
Posted: Fri Oct 31, 2014 12:53 pm
by cmerchant
If you use \n in the echo command, you need to use -e to interpret the \n as a newline.
Code: Select all
echo -e "this is a comment\n and a second line"
Code: Select all
this is a comment
and a second line
Re: Script returns different result when ran locally versus
Posted: Fri Oct 31, 2014 1:25 pm
by rickwilson7425
I tried doing the echo -e and placing a \n inside the quotes and outside and neither arrangement would make more than one line display in the Nagios GUI.
Re: Script returns different result when ran locally versus
Posted: Fri Oct 31, 2014 1:30 pm
by cmerchant
I miss understood. You need to leave off the -e on the echo so that the \n does not get expanded until it gets to the GUI. Could you please post your updated script to see what you currently have? Thanks
Re: Script returns different result when ran locally versus
Posted: Fri Oct 31, 2014 1:42 pm
by rickwilson7425
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 [[ `/usr/local/bin/redis-cli -p $SEN_PORT PING | grep 'PONG'` ]];then
# Success
# echo "REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is active and PONG was the response"
echo "REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is OK \n"
else
# Failure
echo "REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is 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 -P '^sentinel monitor 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 [[ `/usr/local/bin/redis-cli -p $MOBIL_PORT PING | grep 'PONG'` ]];then
# Success
# echo "REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is active and PONG was the response"
echo "REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is OK \n"
else
# Failure
echo "REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is 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 [[ `/usr/local/bin/redis-cli -p $NUXEO_PORT PING | grep 'PONG'` ]];then
# Success
# echo "REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is active and PONG was the response"
echo "REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is OK \n"
else
# Failure
echo "REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is not active and did not PONG"
exit 1
fi
fi
Re: Script returns different result when ran locally versus
Posted: Fri Oct 31, 2014 2:04 pm
by cmerchant
We'll look into it further. I think the suggestion sreinhardt originally had would be a better solution.
Re: Script returns different result when ran locally versus
Post by sreinhardt ยป Wed Oct 29, 2014 4:36 pm
You need to use a \n in your output to nagios, not an actual newline or second echo. Using \n will be replaced internally with a newline for pretty output but will not cause Core to think the second line is intended as long output. You will probably want to store your results in a variable and do a single echo at the end instead of multiple echos.
Re: Script returns different result when ran locally versus
Posted: Fri Oct 31, 2014 2:11 pm
by rickwilson7425
Thank you for your help.
I am researching and studying on how to dump the individual echos into variable(s) and then string them together (concatenate?).
Scripting is not one of my strong suits.
Re: Script returns different result when ran locally versus
Posted: Fri Oct 31, 2014 2:17 pm
by cmerchant
concatenating the echo's is probably the wrong way to go. We will look at your script and suggest changes to make this work. Thanks.
Re: Script returns different result when ran locally versus
Posted: Fri Oct 31, 2014 2:34 pm
by rickwilson7425
This is what I have come up with so far but it isn't displaying in the GUI properly either.
It does give me the proper return messages however:
Code: Select all
#!/bin/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 | cut -f2 -d' '`
# SEN_PORT=`grep -w port /etc/redis/rsentinel.conf | cut -f2 -d' '`
SEN_PORT=`grep -P '^port ' /etc/redis/rsentinel.conf | cut -f2 -d' '`
# if [[ `redis-cli -p $SEN_PORT PING | grep 'PONG' 2>&1 >/dev/null` ]];then
if [[ `/usr/local/bin/redis-cli -p $SEN_PORT PING | grep 'PONG'` ]];then
# Success
# echo "REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is OK"
sen_return="REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is OK"
else
# Failure
# echo "REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
sen_return="REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
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 -P '^sentinel monitor 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 [[ `/usr/local/bin/redis-cli -p $MOBIL_PORT PING | grep 'PONG'` ]];then
# Success
# echo "REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is OK"
mobil_return="REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is OK"
else
# Failure
# echo "REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
mobil_return="REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
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 [[ `/usr/local/bin/redis-cli -p $NUXEO_PORT PING | grep 'PONG'` ]];then
# Success
# echo "REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is OK"
nuxeo_return="REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is OK"
else
# Failure
# echo "REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
nuxeo_return="REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
exit 1
fi
echo "$SEN_RETURN \
>>$MOBIL_RETURN \
>>$NUXEO_RETURN"
fi
Re: Script returns different result when ran locally versus
Posted: Mon Nov 03, 2014 11:10 am
by rickwilson7425
One of my coworkers got the display working more or less properly. Here is how he modified the script:
Code: Select all
#!/bin/bash
################# Check SENTINEL Port #################
# Clint adds to make a single return option
sen_return=''
mobil_return=''
nuxeo_return=''
error_return=''
final_response_string=''
HOSTNAME_REDIS=`hostname -s`
# Gather ports (default sentinel port is 26379)
# SEN_PORT=`grep -P '^port \d+' /etc/redis/rsentinel.conf | cut -f2 -d' '`
# SEN_PORT=`grep -w port /etc/redis/rsentinel.conf | cut -f2 -d' '`
SEN_PORT=`grep -P '^port ' /etc/redis/rsentinel.conf | cut -f2 -d' '`
# if [[ `redis-cli -p $SEN_PORT PING | grep 'PONG' 2>&1 >/dev/null` ]];then
if [[ `/usr/local/bin/redis-cli -p $SEN_PORT PING | grep 'PONG'` ]];then
# Success
# echo "REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is OK"
sen_return="REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is OK"
else
# Failure
# echo "REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
sen_return="REDIS Sentinel port $SEN_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
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 -P '^sentinel monitor 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"
error_return="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 [[ `/usr/local/bin/redis-cli -p $MOBIL_PORT PING | grep 'PONG'` ]];then
# Success
# echo "REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is OK"
mobil_return="REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is OK"
else
# Failure
# echo "REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
mobil_return="REDIS Mobile port $MOBIL_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
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"
error_return="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 [[ `/usr/local/bin/redis-cli -p $NUXEO_PORT PING | grep 'PONG'` ]];then
# Success
# echo "REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is OK"
nuxeo_return="REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is OK"
else
# Failure
# echo "REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
nuxeo_return="REDIS Nuxeo port $NUXEO_PORT on $HOSTNAME_REDIS is not active and FAILED!!"
exit 1
fi
# echo -e "$SEN_RETURN>>\n$MOBIL_RETURN>>\n$NUXEO_RETURN"
# printf '%b\n%b\n%b\n' "$SEN_RETURN" "\n$MOBIL_RETURN" "\n$NUXEO_RETURN"
final_response_string="$sen_return $mobil_return $nuxeo_return $error_return"
printf '%s' "$final_response_string"
fi
There is only a slight formatting problem in the output - the 3rd line actually starts at the end of the second line and then continues on the 3rd line.
[img]dencita1
Perform Extra Host Actions View Extra Host Notes Linux
Check Redis
Perform Extra Service Actions View Extra Service Notes
OK 08:56:11 5d 20h 28m 36s 1/3 REDIS Sentinel port 16379 on dencita1 is OK
REDIS Mobile port 6380 on dencita1 is OK REDIS
Nuxeo port 6379 on dencita1 is OK [/img]