#!/bin/sh

# Copyright (c) 2010 Bernd Zeimetz <bzed@debian.org>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE

PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

if [ "$1" = "config" ]; then
        echo graph_title cable modem power level
        echo 'graph_args --base 1000'
        echo 'graph_vlabel dBmV'
        echo 'graph_category network'
        echo 'graph_info This graph shows receive and transmit power levels of the Scientific-Atlanta cable modem.'
        echo "receive.label receive"
        echo "receive.info Receive power level"
        echo 'receive.draw LINE2'
        echo 'receive.type GAUGE'
        echo "transmit.label transmit"
        echo "transmit.info Transmit power level"
        echo "transmit.draw LINE2"
        echo "transmit.type GAUGE"
        exit 0
fi

wget -q -O - http://192.168.100.1/system.asp | grep dBmV | \
    sed -e 's,.*&nbsp;,,;s, dBmV.*,,' \
        -e '1s/^/receive.value /' \
        -e '2s/^/transmit.value /'