Created
January 8, 2021 09:17
-
-
Save jplitza/0348316bc19e5a0e98300e780cfe8aeb to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
set -eu | |
declare -a STATES=(OK WARNING CRITICAL UNKNOWN) | |
declare -i STATE_OK=0 | |
declare -i STATE_WARNING=1 | |
declare -i STATE_CRITICAL=2 | |
declare -i STATE_UNKNOWN=3 | |
declare -i RET=$STATE_OK | |
MSG="" | |
MASTER="$1" | |
ZONE="$2" | |
read _ _ REF_SERIAL _ < <(dig +short "@$MASTER" "$ZONE" SOA) | |
while read _ _ _ SERIAL _ _ _ _ _ _ IP _; do | |
if [[ "$SERIAL" = "out;" ]]; then | |
MSG="${MSG}Not all servers responded, " | |
if [[ $RET = $STATE_OK ]]; then | |
RET=$STATE_UNKNOWN | |
fi | |
elif [[ "$SERIAL" != "$REF_SERIAL" ]]; then | |
MSG="${MSG}$IP: $SERIAL != $REF_SERIAL, " | |
RET=$STATE_CRITICAL | |
fi | |
done < <(dig -4 +time=1 +nssearch "$ZONE") | |
if [[ -z "$MSG" ]]; then | |
MSG="All servers have zone serial ${REF_SERIAL}" | |
fi | |
echo "${STATES[$RET]}: ${MSG%, }" | |
exit $RET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment