Last active
August 29, 2015 14:13
-
-
Save danielhauck/d0053e113d2d73568807 to your computer and use it in GitHub Desktop.
Check your failover from time to time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ -z ${1} ] || [ -z ${2} ]; then | |
echo "USAGE: ${0} <IP-TO-MONITOR> <PIVOT-DAYS>" | |
exit 1 | |
fi | |
PIVOTDAYS=35 # how often should the failover be checked?(in days) | |
IP_TO_MONITOR=${1} | |
FAILOVER_IP=$(ip addr sh | grep -v "127.0.0.1" | grep "inet " | cut -d/ -f1 | awk '{print $2}' | grep -Fx ${IP_TO_MONITOR}) | |
if [ -z "${FAILOVER_IP}" ];then | |
echo "[OK] Host is in Backup mode" | |
exit 0 | |
fi | |
HASHFILE="/tmp/$(echo "${IP_TO_MONITOR}" | md5sum | cut -f1 -d' ')" | |
touch ${HASHFILE} | |
if test $(find ${HASHFILE} -ctime +${PIVOTDAYS}) | |
then | |
echo "[CRIT] it is time to check the failover!" | |
exit 2 | |
else | |
echo "[OK] still got some time" | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment