I have a small problem with a custom script i am trying to implement inside nagios
Below is my script. it’s to run against a database. I put a few switches and safety nets. However on the Nagios interface it seems to get out the first if and not continuing. I have put number by each ok to see where it gets stuck. Here are 2 screenshot explaining the issue.
If I run this in command line from the Nagios machine it execute flawlessly. Warning,critical,static all work well
However inside Nagios first if and out not mather if I force it to go critical or warning.
Any idea?
=====================script=============
Code: Select all
#/bin/bash
#coded by psteam
# version 3.2
script=""
instance=""
warn=-1
crit=-1
stactic=-1
dis=0
user=""
pass=""
# Get options
while getopts :i:s:w:c:d:b:u: OPTION
do
case $OPTION
in
i)
instance=${OPTARG}
;;
s)
script=${OPTARG}
;;
w)
warn=${OPTARG}
;;
c)
crit=${OPTARG}
;;
b)
stactic=${OPTARG}
;;
d)
dis=${OPTARG}
;;
u)
user=${OPTARG}
;;
esac
done
# grab password from User
pass=$(awk -F "$user"= '{print $2}' .mdfpassword )
# extract output from query
#. Oracle.env;sqlplus -s "$user"/"$pass"@$instance @$script > ./tmp/"$script".tmp
tmp_out_nospace="$(. Oracle.env;sqlplus -s "$user"/"$pass"@$instance @$script | tr -d '[[:space:]]')"
# show all variables for debugging
#echo $script
#echo $instance
#echo $warn
#echo $crit
#echo $stactic
#echo $dis
#echo $tmp_out
echo $tmp_out_nospace
#echo $errcnt
#echo $user
#echo $pass
#validates no errors in query
errcnt=$(echo $tmp_out_nospace | grep -i "ERROR" | wc -l)
if [ $errcnt -ne 0 ]
then
echo " error on query or server please validate"
echo $script
echo $instance
exit 4
fi
#Disable nagios alerts if warning and critical limits are both set to 0 (zero)
if [ $dis -eq 1 ]
then
ALERT=false
fi
#Display output without alert
if [ "$ALERT" == "false" ]
then
echo no alert
echo "$tmp_out_nospace"
exit 0
else
ALERT=true
fi
#Display static output
if [ "$stactic" -ne -1 ]
then
if [ "$tmp_out_nospace" -ne "$stactic" ]
then
echo "WARNING: static Should be $stactic currently : $tmp_out_nospace"
exit 1
else
echo "static OK143: $tmp_out_nospace"
exit 0
fi
fi
#Display output with alert
if [ "$crit" -ne -1 ]
then
if (("$tmp_out_nospace" >= "$crit"))
then
echo "CRITICAL: $tmp_out_nospace"
exit 1
else
if [ "$warn" -ne -1 ]
then
if (("$tmp_out_nospace" >= "$warn"))
then
echo "Warning: $tmp_out_nospace"
exit 2
else
echo "OK155: $tmp_out_nospace"
exit 0
fi
fi
fi
fi
if [ "$warn" -ne -1 ]
then
if (("$tmp_out_nospace" >= "$warn"))
then
echo "Warning: $tmp_out_nospace"
exit 2
else
echo "OK255: $tmp_out_nospace"
exit 0
fi
fi