1
0
Fork 0

Compare commits

...

3 commits

Author SHA1 Message Date
Chl
8e37cb2478 nagios/glue_records: standalone + warn if no IP 2020-01-05 20:18:35 +01:00
Chl
90a94aa61a nagios: add check_glue_records.sh 2020-01-05 03:33:34 +01:00
Chl
7e971a5c76 script-debit: rewrite 2019-10-14 03:45:02 +02:00
3 changed files with 189 additions and 30 deletions

150
nagios/check_glue_records.sh Executable file
View file

@ -0,0 +1,150 @@
#!/bin/sh
# Small script to check that all servers behind the glue records :
# - are reachable (IPv4 and IPv6 alike),
# - show the same SOA record.
# GPL v3+
# Stop at the first non-catched error
set -e
# For monitoring plugins
PROGPATH=$( echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,' )
REVISION="0.1"
# Include check_range()
#. $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
#
usage() {
cat <<EOF
Usage :
$0 [-sS] domain.com [[-sS] domain.net] ...
-s : don't check for SOA records discrepancies
-S : nevermind, do check for SOA discrepancies (default)
EOF
}
# Some early checks
if ! which dig >/dev/null 2>&1 ; then
echo "UNKNOWN 'dig' not found"
exit $STATE_UNKNOWN
fi
# We loop until there is no more parameters, be it
# either options or domains
while [ "$#" -gt 0 ]; do
# Parameters management
while getopts hsS OPT; do
case "$OPT" in
'h')
usage
exit
;;
's')
CHECK_SOA=0;
;;
'S')
CHECK_SOA=1;
;;
\?)
usage
exit 1
;;
esac
done
shift $( expr $OPTIND - 1 )
DOMAIN="$1"
shift
# Exit if no domain has been specified
# (it's kind of weird and I don't like it)
if [ -z "$DOMAIN" ]; then
echo "UNKNOWN: no domain tested."
exit $STATE_UNKNOWN
fi
# Get the TLD of the domain (example.net -> net)
TLD="$( echo "$DOMAIN" | sed 's/[^.]*\.\([^.]\)/\1/' )"
# ...and get one random server for this TLD
NS_TLD="$( dig +short "$TLD" NS | sort -R | tail -n 1 )"
# 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 )
if [ "$?" -eq 0 ]; then
# The server responded, store the SOA for later analyze
LIST_SOA="$( printf "%s\n%s" "$LIST_SOA" "$OUTPUT" | grep -v "^$" )"
else
# No response ?
if [ "$OUTPUT_EXIT_STATUS" -ne $STATE_CRITICAL ]; then
OUTPUT_DETAIL_CRITICAL="Problematic server behind IP"
OUTPUT_EXIT_STATUS=$STATE_CRITICAL
fi
OUTPUT_DETAIL_CRITICAL="$OUTPUT_DETAIL_CRITICAL $IPADDRESS"
fi
done
# 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="$OUTPUT_DETAIL_WARNING SOA records discrepancies for domain $DOMAIN : $LIST_SOA"
fi
# Clean up after each domain
unset LIST_SOA
OUTPUT_DETAIL_OK="$OUTPUT_DETAIL_OK $DOMAIN"
done
case "$OUTPUT_EXIT_STATUS" in
'0')
printf "OK%s" "$OUTPUT_DETAIL_OK"
;;
'1')
printf "WARNING %s" "$OUTPUT_DETAIL_WARNING"
;;
'2')
printf "CRITICAL %s" "$OUTPUT_DETAIL_CRITICAL"
;;
*)
printf "UNKNOWN"
;;
esac
# Perfdata
#printf "|%s\n" "$OUTPUT_PERFDATA"
printf "\n"
# Exit with return status
exit $OUTPUT_EXIT_STATUS

View file

@ -1,30 +0,0 @@
#!/bin/sh
# Ce script donne la volumétrie d'une interface réseau à intervalle régulier
# (se base sur /proc/net/dev)
FICHIER_PROC=/proc/net/dev
INTERFACE="eth0"
DELAI="10"
OLD_VOLUME_IN=0
OLD_VOLUME_OUT=0
VOLUME_IN=0
VOLUME_OUT=0
while true ; do
VOLUME_IN=$( cat "$FICHIER_PROC" | grep "$INTERFACE:" | sed 's/^[[:space:]]*eth0:\([[:digit:]]\+\)[[:space:]]\+.*/\1/' )
VOLUME_OUT=$( cat "$FICHIER_PROC" | grep "$INTERFACE:" | sed 's/^[[:space:]]*eth0:\([[:digit:]]\+[[:space:]]\+\)\{8\}\([[:digit:]]\+\)[[:space:]]\+.*/\2/' )
if [ "$OLD_VOLUME_IN" -eq "0" ] ; then
echo "Please wait..."
else
printf "%s: %10d o/s reception, %10d o/s emission\n" "$INTERFACE" $(( ( $VOLUME_IN - $OLD_VOLUME_IN ) / $DELAI )) $(( ( $VOLUME_OUT - $OLD_VOLUME_OUT ) / $DELAI ))
fi
OLD_VOLUME_IN=$VOLUME_IN
OLD_VOLUME_OUT=$VOLUME_OUT
sleep "$DELAI"
done

39
script_debit2.sh Executable file
View file

@ -0,0 +1,39 @@
#!/bin/sh
# Ce script donne la volumétrie d'une interface réseau à intervalle régulier
# (se base sur /proc/net/dev)
FICHIER_PROC=/proc/net/dev
DELAI="1"
# Try to get a pretty formatter
FORMATTER="cat -"
if which numfmt >/dev/null 2>&1; then
FORMATTER="numfmt --field 2-3 --to si --padding 7"
fi
# Factorize the parsing
getdata() {
cat "$1" | sed -e '1d;2d' -e 's/^[[:space:]]*//' -e 's/[[:space:]]\+/ /g' | cut -f 1,2,10 -d " "
}
# First grab
OLDDATA="$( getdata "$FICHIER_PROC" )"
while sleep "$DELAI" ; do
NEWDATA="$( getdata "$FICHIER_PROC" )"
# header
printf "\n% 15s\t% 6s\t% 6s\n" " " "IN" "OUT"
echo "$NEWDATA" | while read INTERFACE VOLUME_IN VOLUME_OUT; do
# Again, scope issues with read and pipes so we make a one-time loop :)
echo "$OLDDATA" | grep "$INTERFACE" | while read DUMP OLD_VOLUME_IN OLD_VOLUME_OUT; do
VOLUME_IN="$(( $VOLUME_IN - $OLD_VOLUME_IN ))"
VOLUME_OUT="$(( $VOLUME_OUT - $OLD_VOLUME_OUT ))"
printf "% 15s\t%d\t%d\n" "$INTERFACE" "$VOLUME_IN" "$VOLUME_OUT" | $FORMATTER
done
done
OLDDATA="$NEWDATA"
done