Click here to download the entire script as a zip file.
The script is run through a crontab entry. The data is collected from the router using an expect script, which telnets to the router and issues a series of show interface commands at the prompt. The output is then parsed and the relevant fields like status of the interface and current input/output values are saved to a text file. This data is then picked up and saved as a new row in a html table. A new html file is created once in a day and subsequent readings are added it to row by row every hour.
The file router.exp contains the expect program to telnet to the router and get the input/output readings. Make sure this file has executable permissions.
chmod +x router.exp
Modify the file data-router and set the appropriate values. This file contains the user-level password for your Cisco router, the IP address of your router, and the hostname for your router.
userpw=cisco321 hostip=10.10.10.1 hostname=router1
In the file router.exp set the correct path to the data-router file. In my case this is "/home/jay/tmp/web-test/data-router"
set passwdfile "/home/jay/tmp/web-test/data-router"
After this modify the file int-list according to your requirements. Each entry contains an interface number followed by the link description. Ensure that there are no spaces in the description field. The file should not carry any other entries or commented lines.
s1/0 LINK1 s1/1 LINK2 s6/1 LINK3 s1/2 Customer-A s1/3 Customer-B s3/0 Customer-C s3/3 Customer-D s3/1 Customer-E s3/2 Customer-F s6/2 Customer-G s3/4 Customer-H s6/3 Customer-I
Edit the file bandwidth-report and modify the following lines..
reportdir=/var/www/html/reports PROGDIR=/home/jay/tmp/web-test/ starttime=8 COMPANYNAME="My ISP - Mumbai"
PROGDIR specifies the folder where the router.exp and related files are located, reportdir specifies the output directory. The "starttime" variable specifies the hour of the day at which a new report is created . This can have values from 0 to 24. In my case, the report is from 08:00hrs to 07:00hrs the next day. Set the COMPANYNAME variable to the name of your organization.
Set a crontab entry to run the bandwidth-report script every hour.
0 */1 * * * /home/jay/bin/bandwidth-report
Your output report file should look similar to this.
The script can be easily modified to take readings from multiple routers, switches, etc.