1
0
Fork 0
scripts-admin-quickndirty-p.../nagios/check_network_volume.sh

61 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
EXCLUDE_REGEXP='(lo|bond|vmbr)'
#
# Help function
#
usage() {
cat <<EOF
This script simply outputs the number of packets and volume of data
emitted and received by network devices. Its status is always 0/OK.
Usage :
$0 [-e egrep_exclude_pattern]
Example :
$0 -e '(lo|^br-|^veth)'
Default values:
egrep_exclude_pattern: $EXCLUDE_REGEXP
EOF
}
#
# Loop on parameters + tests
#
while getopts he: f; do
case "$f" in
'h')
usage
exit
;;
'e')
EXCLUDE_REGEXP="$OPTARG"
;;
\?)
usage
exit 1
;;
esac
done
# We don't bother buffering, let's output as we go
printf "OK |"
# Loop on each device
for i in $( cat /proc/net/dev | sed -n 's/^[[:space:]]*\([a-z0-9\.\-]\+\):.*/\1/p' | sort ); do
if [ $( echo "$i" | egrep -c -e "$EXCLUDE_REGEXP" ) -gt 0 ]; then
continue
fi
VOLUME_RECU="$( cat /proc/net/dev | sed -n "s/^[[:space:]]*$i:[[:space:]]*//p" | sed 's/[[:space:]]\+/ /g' | cut -d " " -f 1 )"
VOLUME_EMIS="$( cat /proc/net/dev | sed -n "s/^[[:space:]]*$i:[[:space:]]*//p" | sed 's/[[:space:]]\+/ /g' | cut -d " " -f 9 )"
PAQUETS_RECUS="$( cat /proc/net/dev | sed -n "s/^[[:space:]]*$i:[[:space:]]*//p" | sed 's/[[:space:]]\+/ /g' | cut -d " " -f 2 )"
PAQUETS_EMIS="$( cat /proc/net/dev | sed -n "s/^[[:space:]]*$i:[[:space:]]*//p" | sed 's/[[:space:]]\+/ /g' | cut -d " " -f 10 )"
printf " %s_packets_in=%d %s_packets_out=%d %s_volume_in=%d %s_volume_out=%d" "$i" "$PAQUETS_RECUS" "$i" "$PAQUETS_EMIS" "$i" "$VOLUME_RECU" "$i" "$VOLUME_EMIS"
done
printf "\n"