#!/bin/bash
# 
# 
# Script to show adsl router stats for routers with Conexant based chips and the standard Conexant web admin gui like the eTec EpicRouter...
#
# Parameters understood:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
#
#
# Magic markers (optional - used by munin-config and installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf
USERNAME=admin
PASSWORD=epicrouter
MAXLABEL=20

if [ "$1" = "autoconf" ]; then
	echo yes
	exit 0
fi

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

	echo 'graph_title ADSL Connection Statistics'
	echo 'graph_args --base 1000 -l 0'
	echo 'graph_vlabel Daily Connection Statistics'
	echo 'st_dw_crc.label Downstream CRC count'
	echo 'st_up_crc.label Upstream CRC count'
	echo 'st_dw_data_rate.label Downstream Data Rate'
	echo 'st_up_data_rate.label Upstream Data Rate'
	echo 'st_dw_line_attenuation.label Downstream Line Attenuation'
	echo 'st_up_line_attenuation.label Upstream Line Attenuation'
	echo 'st_dw_errored_seconds.label Downstream Errored Seconds'
	echo 'st_up_errored_seconds.label Upstream Errored Seconds'
	exit 0
fi

wget -q --http-user=admin --http-passwd=epicrouter http://10.0.0.2/doc/adsl.htm -O /tmp/adsl.htm
echo -en "st_dw_crc.value "
echo $((`grep 'var st_dw_crc' /tmp/adsl.htm | sed 's/[var st_dw_crc=;"]//g'`))
echo -n
echo -en "st_up_crc.value "
echo $((`grep 'var st_up_crc' /tmp/adsl.htm | sed 's/[var st_up_crc=;"]//g'`))
echo -n
echo -en "st_dw_data_rate.value "
echo $((`grep 'var st_dw_data_rate' /tmp/adsl.htm | sed 's/[var st_dw_data_rate=;"]//g'`))
echo -n
echo -en "st_up_data_rate.value "
echo $((`grep 'var st_up_data_rate' /tmp/adsl.htm | sed 's/[var st_up_data_rate=;"]//g'`))
echo -n
echo -en "st_dw_line_attenuation.value "
echo $((`grep 'var st_dw_line_attenuation' /tmp/adsl.htm | sed 's/[var st_dw_line_attenuation=\.;"]//g'`))
echo -n
echo -en "st_up_line_attenuation.value "
echo $((`grep 'var st_up_line_attenuation' /tmp/adsl.htm | sed 's/[var st_up_line_attenuation=;\."]//g'`))
echo -n
echo -en "st_dw_errored_seconds.value "
echo $((`grep 'var st_dw_errored_seconds' /tmp/adsl.htm | sed 's/[var st_dw_errored_seconds=;"]//g'`))
echo -n
echo -en "st_up_errored_seconds.value "
echo $((`grep 'var st_up_errored_seconds' /tmp/adsl.htm | sed 's/[var st_up_errored_seconds=;"]//g'`))
echo -n
rm /tmp/adsl.htm
