External monitor not working properly
Hello.
i have configured an external monitor that uses a bash script. the script connects to the pool members via telnet and sends a command, it then searches for a string in the output of the telnet command. when i test this monitor the results are always "UP" even when i change the matching string to something not in the output of the command. It is like it is not even checking for the matching string and just marks the pool members as online. Even pool members that are switched off are showing as online. What am i missing, see below the monitor configuration and the script used.
#!/bin/bash
IP=`echo $1 | sed 's/::ffff://'`
# Check if there is a prior instance of the monitor running
bn=`basename $0`
pidfile="/var/run/${bn%_*}.$IP.pid"
if [ -f $pidfile ]
then
kill -9 `cat $pidfile` > /dev/null 2>&1
fi
echo "$$" > $pidfile
#start the test
output=$({
echo open $IP "10013"
sleep 1
echo "ENQUIRY.SELECT,,KONDWANIMA/Kondwani@1234,%DATES,"
sleep 2
} | telnet 2>/dev/null)
n=1
while read -r line; do
echo "line #$((n++)): $line | grep TODAY/VERSION" # maybe add a grep here
done <<< "$output"
if [[ ${output} == *"TODAY/VERSION"* ]]; then
echo "UP"
fi
rm -f "${pidfile}"