Skip to content

Instantly share code, notes, and snippets.

@jplitza
Created January 8, 2021 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jplitza/0348316bc19e5a0e98300e780cfe8aeb to your computer and use it in GitHub Desktop.
Save jplitza/0348316bc19e5a0e98300e780cfe8aeb to your computer and use it in GitHub Desktop.
#!/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