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 10.1.1.1 admin admin
To get a single stat, in this case upstream bitrate
./getmodemstats.py 10.1.1.1 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
#!/usr/bin/python
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.read_until("username:")
tn.write(user+"\n")
tn.read_until("password:")
tn.write(pw+"\n")
tn.write("\n")
tn.read_until("TP-LINK(conf)#")
tn.write("adsl show info\n")
output = tn.read_until("cmd:SUCC")
tn.write('\x1d')
if stat == None:
print output
else:
for item in output.split("\n"):
if stat in item:
line = item.split("=")
print line[1]