Building a DSL Info Bot with Selenium and Plotly

Table of Contents
About
A python bot, that uses Selenium, in order to automatically access the Router/Modem’s web-based setup page and get DSL Link info. It uses Plotly to create an interactive Plot as an HTML web page.
It also supports the export of the data to an InfluxDB Bucket for further monitoring and visualizing.
Currently gets the following info:
- CRC Errors
- FEC Errors
- Showtime_start
Support for the following Routers/Modems:
- ZTE Nova Routers (H267N, H288A, …)
The need behind this project, was to monitor my DSL Link information over time, to correlate with various internet outages or sudden internet speed issues.
2024 Update: Right now this project is unused, since I have upgraded my internet connection to Fiber and all of these issues are gone 😄.
GitHub repository: https://github.com/thanoskoutr/DSL-Info-Bot
Technologies
The main technologies used for this project (language, tools, libraries, database):
Installation
Clone Repository
Clone the repo:
Change directory:
Python Virtual Environment
Install venv
On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command:
Create virtual environment
Create a virtual environment on the top directory of the project:
Activate the virtual environment
Install required dependencies
Minimum Python version tested: Python 3.6.9
Maximum Python version tested: Python 3.8.5
Dependencies
You can install manually, without a virtual environment, the project dependencies:
Download Web-Driver for Selenium
Selenium requires a driver to interface with the chosen browser. For this project the Chrome and Firefox driver is supported, used in headless mode in order to not require a GUI.
Install Chromium
In order to use the chromium driver, chromium or chrome needs to be installed. If you have already a chrome installation in your system, there is nothing to be done. Else, install a chrome version.
For Ubuntu 20.04, use wget
to download the latest Google Chrome .deb
package:
Install Google Chrome package:
Download Chrome Driver
Download the chrome browser driver, based on the installed chromium version in your system from this link
Check Chrome version:
For the Chrome version 89 driver, for Linux 64-bit, download with:
Extract the driver, using unzip
:
Install Mozilla Firefox
In order to use the firefox driver, Firefox needs to be installed. If you have already a Firefox installation in your system, there is nothing to be done. Else, install a Firefox version from here or:
For Ubuntu/Debian Distros
For Arch/Arch based Distros
Download Firefox Driver
Download the Firefox browser driver, based on the installed Firefox version in your system from this link
Check Firefox version:
For the latest Firefox version driver, for Linux 64-bit, download with:
Extract the driver, using tar
:
Add driver to PATH
In order for selenium to use the binary driver, it has to be in the PATH
environmental variable. The preferred place for local binaries is to place the driver in the /usr/local/bin
directory:
Selenium Guides - Documentation
Add Environmental Variables
Create the .env
file from .env-test
:
Fill in the environmental variables needed:
- Router’s web-based setup page (like
http://192.168.1.1/
) - Router’s Username
- Router’s Password
Run Program
From the project’s top directory, run:
- A file named
dsl_info.csv
should be created in the directory that contains the fetched info. - A file named
dsl_info_headers.csv
should be created in the directory that contains the info headers. - Firefox is the default browser, running without GUI.
Run Program with arguments
From the project’s top directory, run with help
option to see all available options:
$ python3 main.py -h
usage: main.py [-h] [-d {firefox,chrome}] [--headless {True,False}] [-t TIMEOUT] [-f FILE]
DSL-Info-Bot - A python bot, that uses Selenium, in order to automatically access the Router/Modem's web-based setup page and get DSL Link
info.
optional arguments:
-h, --help show this help message and exit
-d {firefox,chrome}, --driver {firefox,chrome}
The browser driver to use.
--headless {True,False}
Run without a GUI.
-t TIMEOUT, --timeout TIMEOUT
The maximum time to wait for page loading.
-f FILE, --file FILE The file name of the csv where the data will be saved.
Run Plot Script
From the project’s top directory, run:
- Reads the
.csv
files with the headers and the data - Creates a
plot.html
file that can be viewed on a browser.
Run Plot Script with arguments
From the project’s top directory, run with help
option to see all available options:
$ python3 create_plot.py -h
usage: create_plot.py [-h] [-c CSV] [-d CSV_HEADERS]
A plot script in order to visualize the data in the csv file.
optional arguments:
-h, --help show this help message and exit
-c CSV, --csv CSV The file name of the csv with the data.
-d CSV_HEADERS, --csv_headers CSV_HEADERS
The file name of the csv with the data headers.
Serve Plot - View on Browser
If you are in a headless environment you can serve the .html
files using the http.server
python module.
By running this command from the project’s top directory, you’ll be able to access the files in your directory through your browser at localhost:8420
:
There are more elegant (and safe) ways to do this, but this is a quick and dirty solution.
Create a Cron Job
In order to run the script after a time interval on a linux machine:
Open crontab:
In order to run the script every 5 minutes, change the path to the repo accordingly:
In order to run the script, update the plot every 5 minutes and serve the html plot, change the path to the repo accordingly:
We need to use the bash shell in order to execute the source
command and we need to export the PATH
variable in order for cron to be able to find the driver.
The dsl-info.csv
file should be created or updated in the repo directory.
InfluxDB
In order to add dsl_info.csv
to a InfluxDB Bucket, we have to convert theme using the convert_times.py
script that converts the showtime_start_value
and the current_date
values to duration
and timestamp
data formats that InfluxDB can process.
To do that, create a new dsl_info.csv
file:
And convert the fields on the new dsl_info_influxdb.csv
file:
Now we can add them to a DSL-Info
bucket using the following commands, by passing only one measurement at each time: