andresp / cablemodem-status

Python based DOCSIS modem performance metrics collection tool using the built-in HTML portal of common devices.
MIT License
13 stars 3 forks source link

Add support for the TC4400 modem #15

Open DeflateAwning opened 1 year ago

andresp commented 1 year ago

Thanks for opening the issue. Do you have access to a TC4400? Unfortunately I don't, but I'm happy to take a contribution to the project if you do.

DeflateAwning commented 1 year ago

I do yeah, I may work on it eventually! Any suggestions on where to start/things to watch out for?

andresp commented 1 year ago

That depends a bit in particular how you need to authenticate to the modem. If it's a simple process you could follow the process from the MB8600 modem. If you need to run complex javascript and if it is too complicated to replicate through a few POST calls, then you can follow the TG3492 approach, where Selenium is leveraged to navigate the actual login page through a virtual browser session.

DeflateAwning commented 12 months ago

The way auth works is you just pass simple HTTP Authentication parameters with every request

andresp commented 8 months ago

I've refactored the code a bit. You should be able to create a copy of the Technicolor_xb7 modem or similar and focus on implementing the collectStatus() method, then register your modem in modemtype.py with a new string. Said string can then be used in a configuration. If possible, add a few unittests for the new modem with sample content and responses (successful, failed logins, sample channels page, etc.).

I may add more tests to the existing modems soon, so you could use that as a template to follow.

biochemie commented 4 months ago

Dumping this out here as I used this to get a scraper for the TC4400 going. I'm not entirely sure where the rest of the script went that did the output/formatting, especially considering the CODA45 scraper I wrote after that is in its (mostly) complete state (had a full telegraf output operational but never got to finishing the syslog or json output formats before we had to get yet another modem). But thought this would at least help to lay out the page scraping for a modem config file.

import requests
from bs4 import BeautifulSoup as bs
from pandas import read_html as rh

auth = requests.auth.HTTPBasicAuth('admin', 'bEn2o#US9s')

if __name__ == '__main__':
    # Pull modem page data
    d = requests.get("http://192.168.100.1/cmconnectionstatus.html", auth=auth)
    # Pull modem event logs
    l = requests.get("http://192.168.100.1/cmeventlog.html", auth=auth)
    # Parse out the page data
    dp = bs(d.text, 'lxml')
    lp = bs(l.text, 'lxml')
    # Pull out the tables of interest
    ds, us, md = dp.find_all('table')[1:4]
    ip = rh(str(md))[0][0][1].split('=')[1]
    uptime = rh(str(md))[0][1][1]
    ds = rh(str(ds), skiprows=1)[0]
    us = rh(str(us), skiprows=1)[0]