Oct 072015

I’ve finally gotten around to working on my projects again after doing some exams.

I wanted to get some ADSL monitoring going so I could get some history on the state of my line, get sync rates etc.

The first thing I needed to do was get the modem stats via a script as Zabbix couldn’t login to the modem properly.
I did a quick python script that can be called from Zabbix to get the modem stats.

The script can be used to either get all the stats at once, or a stat can be specified and only the stat itself will be returned.
e.g. To get all stats
./getmodemstats.py admin admin

To get a single stat, in this case upstream bitrate
./getmodemstats.py admin admin --stat upstreamCurrRate

Onto the script itself, which is also available on GitHub

Copy the below code into a file, name it something like getmodemstats.py, and then run it like the examples above.
This may work for other TP-Link modems, I don’t have any to test with unfortunately

import telnetlib
import argparse

parser = argparse.ArgumentParser(description="Gets TP-Link TD-8840 Modem stats")
parser.add_argument('--stat',help="Stat to retrieve")
parser.add_argument('host',help="modem IP address")
parser.add_argument('user',help="modem username")
parser.add_argument('pw',help="modem password")

args = parser.parse_args()
stat = args.stat
host = args.host
user = args.user
pw = args.pw

tn = telnetlib.Telnet(host)


tn.write("adsl show info\n")
output = tn.read_until("cmd:SUCC")
if stat == None:
print output
for item in output.split("\n"):
if stat in item:
line = item.split("=")
print line[1]


 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>