From 8e37cb24787d28fc6feb8d414501224c46c3548a Mon Sep 17 00:00:00 2001 From: Chl Date: Sun, 5 Jan 2020 20:18:35 +0100 Subject: [PATCH] nagios/glue_records: standalone + warn if no IP --- nagios/check_glue_records.sh | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/nagios/check_glue_records.sh b/nagios/check_glue_records.sh index 788f2ca..65f67d4 100755 --- a/nagios/check_glue_records.sh +++ b/nagios/check_glue_records.sh @@ -8,22 +8,29 @@ # Stop at the first non-catched error set -e -# Output -OUTPUT_EXIT_STATUS=0 -OUTPUT_DETAIL_OK="" -OUTPUT_DETAIL_WARNING="" -OUTPUT_DETAIL_CRITICAL="" -#OUTPUT_PERFDATA="" - -# Defaults -CHECK_SOA=1 - # For monitoring plugins PROGPATH=$( echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,' ) REVISION="0.1" # Include check_range() -. $PROGPATH/utils.sh +#. $PROGPATH/utils.sh +# No need for check_range() at the moment, we just copy +# the states to be standalone (easier to use that way) +STATE_OK=0 +STATE_WARNING=1 +STATE_CRITICAL=2 +STATE_UNKNOWN=3 +STATE_DEPENDENT=4 + +# Defaults +CHECK_SOA=1 + +# Output +OUTPUT_EXIT_STATUS=$STATE_OK +OUTPUT_DETAIL_OK="" +OUTPUT_DETAIL_WARNING="" +OUTPUT_DETAIL_CRITICAL="" +#OUTPUT_PERFDATA="" # # Help function @@ -88,6 +95,11 @@ while [ "$#" -gt 0 ]; do # Query this TLD server on our domain and loop on each IP address "additionally" # given, aka. the glue records LIST_IP_NS_SERVERS="$( dig +norec +nocomments +noquestion +nostats +nocmd @"$NS_TLD" "$DOMAIN" NS | sed -n 's/.*IN[[:space:]]\+\(A\|AAAA\)[[:space:]]\+\(.*\)$/\2/p' )" + if [ -z "$LIST_IP_NS_SERVERS" ] && [ "$OUTPUT_EXIT_STATUS" -ne "$STATE_CRITICAL" ]; then + OUTPUT_EXIT_STATUS=$STATE_WARNING + OUTPUT_DETAIL_WARNING="$OUTPUT_DETAIL_WARNING No glue records for domain $DOMAIN ?" + continue + fi for IPADDR in $LIST_IP_NS_SERVERS; do # Query our server OUTPUT=$( dig @"$IPADDR" $DOMAIN SOA +short 2>&1 ) @@ -107,7 +119,7 @@ while [ "$#" -gt 0 ]; do # Check that SOA records are all the same if [ "$CHECK_SOA" -ne 0 ] && [ "$OUTPUT_EXIT_STATUS" -ne "$STATE_CRITICAL" ] && [ "$( echo "$LIST_SOA" | uniq | wc -l )" -ne 1 ]; then OUTPUT_EXIT_STATUS=$STATE_WARNING - OUTPUT_DETAIL_WARNING="SOA records discrepancies for domain $DOMAIN : $LIST_SOA" + OUTPUT_DETAIL_WARNING="$OUTPUT_DETAIL_WARNING SOA records discrepancies for domain $DOMAIN : $LIST_SOA" fi # Clean up after each domain