#!/bin/sh

case $1 in
   config)
        cat <<'EOM'
graph_title Huawei B315s bandwidth usage
graph_info Huawei B315s bandwidth usage
graph_vlabel kbps
graph_category huawei
in.label bytes in
in.type DERIVE
in.min 0
out.label bytes out
out.type DERIVE
out.min 0
EOM
        exit 0;;
esac

wget -q http://192.168.43.1/html/home.html -O /dev/null --save-cookies /tmp/cookie --keep-session-cookies
echo -n 'in.value '
wget -qO- http://192.168.43.1/api/monitoring/traffic-statistics --load-cookies /tmp/cookie |grep -m 1 'CurrentDownload' | grep -o '[0-9]*'
echo -n 'out.value '
wget -qO- http://192.168.43.1/api/monitoring/traffic-statistics --load-cookies /tmp/cookie |grep -m 1 'CurrentUpload' | grep -o '[0-9]*'