#!/bin/sh
#
# Wildcard-script to monitor network interfaces. To monitor an
# interface, link vlan_<interface> to this file. E.g.
#
#    ln /usr/share/munin/node/plugins-contrib/vlan_ /etc/munin/node.d/vlan_eth0_1
#
# ...will monitor eth0.1
#
# Parameters:
#
# 	config
# 	autoconf
# 	suggest
#
# $Log$
# Revision 1.5  2004/12/10 10:47:49  jimmyo
# Change name from ${scale} to ${graph_period}, to be more consistent.
#
# Revision 1.4  2004/12/09 22:12:56  jimmyo
# Added "graph_period" option, to make "graph_sums" usable.
#
# Revision 1.3  2004/11/21 00:17:12  jimmyo
# Changed a lot of plugins so they use DERIVE instead of COUNTER.
#
# Revision 1.2  2004/05/20 19:02:37  jimmyo
# Set categories on a bunch of plugins
#
# 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
#
#
#
#%# family=manual
#%# capabilities=autoconf suggest

INTERFACE=`basename $0 | sed 's/^vlan_//g' | tr '_' '.'` 

if [ "$1" = "autoconf" ]; then
	if [ -d /proc/net/vlan -a -r /proc/net/vlan -a -x /proc/net/vlan ]
	then
		echo yes
		exit 0
	else
		echo no
		exit 1
	fi
fi

if [ "$1" = "suggest" ]; then
	if [ -d /proc/net/vlan -a -r /proc/net/vlan -a -x /proc/net/vlan ]
	then
		for file in /proc/net/vlan/*
		do
			if [ ! "$file" = "/proc/net/vlan/config" ]
			then
				basename $file | tr '.' '_'
			fi
		done
	fi
	exit 0
fi

if [ "$1" = "config" ]; then
	echo "graph_order received transmitted" 
	echo "graph_title VLAN $INTERFACE Traffic"
	echo 'graph_args --base 1024'
	echo 'graph_vlabel bits per ${graph_period} in (-) / out (+)'
	echo 'graph_category network'
	echo 'received.label bps'
        echo 'received.type DERIVE'
        echo 'received.min 0'
	echo 'received.graph no'
	echo 'received.cdef received,8,*'
	echo 'received.draw AREA'
        echo 'transmitted.label bps'
	echo 'transmitted.type DERIVE'
	echo 'transmitted.min 0'
	echo 'transmitted.negative received'
	echo 'transmitted.cdef transmitted,8,*'
	echo 'transmitted.draw AREA'
	exit 0
fi;

awk "/bytes received/ { print \"received.value \" \$4 } /bytes transmitted/ { print \"transmitted.value \" \$4 }" < /proc/net/vlan/$INTERFACE

