69 lines
1.1 KiB
Bash
69 lines
1.1 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
# Petit script custom pour relever les compteurs des tables
|
||
|
# de voisins (neighbour) ipv4 (ARP) et ipv6 (Neighbour discorvery)
|
||
|
|
||
|
#
|
||
|
# Fonction d'aide
|
||
|
#
|
||
|
usage() {
|
||
|
cat <<EOF
|
||
|
Usage :
|
||
|
$0 -h
|
||
|
EOF
|
||
|
}
|
||
|
|
||
|
|
||
|
#
|
||
|
# Gestion des paramètres
|
||
|
#
|
||
|
while getopts h f; do
|
||
|
case "$f" in
|
||
|
'h')
|
||
|
usage
|
||
|
exit
|
||
|
;;
|
||
|
|
||
|
'e')
|
||
|
EXCLUSIONS="$( printf "%s\n%s" "$EXCLUSIONS" "$OPTARG" )"
|
||
|
;;
|
||
|
|
||
|
'w')
|
||
|
WARNING_LEVEL=$( printf "%d" "$OPTARG" )
|
||
|
;;
|
||
|
|
||
|
'c')
|
||
|
CRITICAL_LEVEL=$( printf "%d" "$OPTARG" )
|
||
|
;;
|
||
|
|
||
|
\?)
|
||
|
usage
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
if ! which ip >/dev/null 2>&1 || [ "$( ip ntable show | wc -l )" -lt 2 ]; then
|
||
|
echo "UNKNOWN souci avec 'ip ntable show'."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# On lance la commande
|
||
|
printf "OK|"
|
||
|
|
||
|
# Dans l'ordre :
|
||
|
# - la commande...
|
||
|
# - tout sur 1 ligne
|
||
|
# - 1 ligne = 1 couple interface - protocole
|
||
|
# - on picore les quelques éléments intéressants (uniquement refcnt pour le moment)
|
||
|
# - on remet tout sur une ligne
|
||
|
# - pas d'espace en fin de ligne
|
||
|
ip ntable show \
|
||
|
| tr '\n' '@' \
|
||
|
| sed 's/@@/\n/g' \
|
||
|
| sed -n 's/^\(inet6\?\).*dev\s\+\(\S\+\).*\(refcnt\)\s\+\([0-9]\+\).*/\1_\2\3=\4/gp' \
|
||
|
| tr '\n' ' ' \
|
||
|
| sed 's/\s\+$/\n/'
|
||
|
|
||
|
exit 0
|