#!/bin/sh

HOST=`echo $0 | perl -pe "s/^.+snmp_hp_(.*?)_[0-9]+/\\$1/;"`
PORT=`echo $0 | perl -pe "s/^.+snmp_hp_.*?_([0-9]+)/\\$1/;"`

if [ "$1" = "autoconf" ]; then
	if [ -x /usr/bin/snmpget ]; then
		echo yes
		exit 0
	else
		echo "no (/usr/bin/snmpget not found)"
		exit 1
	fi
fi

if [ "$1" = "config" ]; then

	echo "graph_order down up" 
	echo "graph_title Switch $HOST Port $PORT Traffic"
	echo 'graph_args --base 1000'
	echo 'graph_vlabel bits out (-) / in (+) per ${graph_period}'
	echo 'graph_category Snmp'
#	echo "graph_info This graph shows the traffic of the $INTERFACE network interface. Please note that the traffic is shown in bits per second, not bytes. IMPORTANT: Since the data source for this plugin use 32bit counters, this plugin is really unreliable and unsuitable for most 100Mb (or faster) interfaces, where bursts are expected to exceed 50Mbps. This means that this plugin is usuitable for most production environments. To avoid this problem, use the ip_ plugin instead."
	echo 'down.label received'
        echo 'down.type COUNTER'
        echo 'down.graph no'
        echo 'down.cdef down,8,*'
        echo 'up.label bps'
	echo 'up.type COUNTER'
	echo 'up.negative down'
	echo 'up.cdef up,8,*'
	exit 0
fi;

snmpget -v1 -c public $HOST .1.3.6.1.2.1.2.2.1.10.$PORT .1.3.6.1.2.1.2.2.1.16.$PORT | sed -e 's/^.*ifIn.*Counter32:/down.value/' -e 's/^.*ifOut.*Counter32:/up.value/'
