#!/bin/sh
#
# Wildcard-plugin to monitor network interfaces. To monitor an
# interface, link if_err_<interface> to this file. E.g.
#
#    ln -s /usr/share/munin/node/plugins-auto/if_err_ /etc/munin/node.d/if_err_eth0
#
# ...will monitor eth0.
#
# Any devince found in /proc/net/dev can be monitored. Examples include
# ipsec*, eth*, irda* and lo. Please note that vlans and aliases cannot
# be monitored with this plugin.
#
# $Log: if_err_.in,v $
# Revision 1.1  2004/01/02 18:50:01  jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.3  2003/11/07 22:12:50  jimmyo
# Changed deprecated plugin options
#
# Revision 1.2  2003/11/07 17:43:16  jimmyo
# Cleanups and log entries
#
#
#
# Magic markers (optional - used by munin-config and some installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf suggest

HOSTNAME=$FQDN
INTERFACE=`basename $0 | sed 's/^if_err_//g'`

if [ "$1" = "autoconf" ]; then
	if [ -r /proc/net/dev ]; then
		echo yes
		exit 0
	else
		echo "no (/proc/net/dev not found)"
		exit 1
	fi
fi

if [ "$1" = "suggest" ]; then
	if [ -r /proc/net/dev ]; then
		grep eth /proc/net/dev | cut -f1 -d: | sed 's/ //g'
		exit 0
	else
		exit 1
	fi
fi

if [ "$1" = "config" ]; then
        echo "host_name $HOSTNAME"
	echo "graph_order rcvd trans" 
	echo "graph_title $INTERFACE errors"
	echo 'graph_args --base 1000'
	echo 'graph_vlabel packets in (-) / out (+)'
	echo 'rcvd.label packets per min'
        echo 'rcvd.type COUNTER'
        echo 'rcvd.graph no'
        echo 'rcvd.cdef rcvd,8,*'
        echo 'rcvd.warning 1'
        echo 'trans.label packets per min'
	echo 'trans.type COUNTER'
	echo 'trans.negative rcvd'
	echo 'trans.cdef trans,8,*'
        echo 'trans.warning 1'
	exit 0
fi;

grep $INTERFACE /proc/net/dev | cut -f2 -d: | awk "{ print \"rcvd.value \" \$3 \"\ntrans.value \" \$11}"

