Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hcoyote
Created February 22, 2012 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hcoyote/1886219 to your computer and use it in GitHub Desktop.
Save hcoyote/1886219 to your computer and use it in GitHub Desktop.
Get a healthcheck on zookeeper. must be a version that responds to ruok.
#!/bin/sh
HOST=$1
PORT=$2
TIMEOUT=5
if [ ! -x /usr/bin/nc ] ; then
echo "/usr/bin/nc is missing; required for $0 to run"
exit 3
fi
if [ -z "$HOST" ] ; then
echo "Specify a host to check"
exit 3
fi
if [ -z "$PORT" ] ; then
echo "Specify a zookeeper port to check"
exit 3
fi
RUOK=`echo ruok | /usr/bin/nc -w $TIMEOUT $HOST $PORT`
if [ $? == 1 ] ; then
echo "CRITICAL: Zookeeper on $HOST:$PORT is down"
exit 2
fi
if [ "$RUOK" != "imok" ] ; then
echo "CRITICAL: Zookeeper on $HOST:$PORT is not ok"
exit 2
else
echo "OK: Zookeeper on $HOST:$PORT is responding"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment