WikiDevi.Wi-Cat.RU:DD-WRT/Configure RSS feed output
The contents of this How-To will show you how to do the following:
-Create a script that will output information to an accessible location in a format that is easy to modify. -Transform the data into RSS format and ready for reading by a program.
Router Setup
You will need to have this script load on startup (refer to this):
mkdir -p /tmp/www while [ 1 ]; do sed -n 's%.* src=\(192.168.[0-9.]*\).*%\1%p' /proc/net/ip_conntrack | sort | uniq -c | awk '{t++; print "Connection",t":",$2,"has",$1,"connections open.";}' | tee /tmp/www/stat.html awk '/MemTotal:/ {mt = $2} /MemFree:/ {mf = $2} /Buffers:/ {mb = $2} /^Cached:/ {mc = $2} END { printf( "Free: %2d%%\n",(mf/mt)*100); printf( "Used: %2d%%\n",((mt-mf)/mt)*100); printf( "Buffers: %2d%%\n",(mb/(mt-mf))*100); printf( "Cached: %2d%%\n",(mc/(mt-mf))*100); }' /proc/meminfo | tee -a /tmp/www/stat.html awk '{ printf( "Load: %3d%%\n",$1*100); }' /proc/loadavg | tee -a /tmp/www/stat.html awk '{ printf( "Uptime: %2.2f Hours\n", $2/3600); }' /proc/uptime | tee -a /tmp/www/stat.html sleep 30; done;
This script will parse out various peices of status information from the files located on the router. If you need more or less of the information or different formatting, you can edit this down to please you. The other script that will read this is independent so it can take more or less lines of information as needed without a hicup. The only syntax requirement for proper reading in the other script is that each status must be fully contained on its own line (but even that isn't really manditory). The output is stored in the file:
/tmp/www/stat.html
And the can be accessed at:
http://routerip/user/stat.html
This is a sample of what this file will contain:
Connection 1: 192.168.1.1 has 476 connections open. Connection 2: 192.168.1.143 has 267 connections open. Free: 9% Used: 90% Buffers: 12% Cached: 35% Load: 45% Uptime: 1.30 Hours
Computer Setup
This setup assumes you have a linux system (I use Kubuntu). This can probably also be done in windows, but a bit differently, I will attempt to explain the process so that if anyone wants to they can easily understand what is going on and reproduce it in windows if they have the knowledge. We will be using this shell script:
#!/bin/bash rm /tmp/rssfeed.xml; echo '<?xml version="1.0" ?><rss version="2.0"><channel><title>Router Connection Status</title><link>http://192.168.1.1</link><description>WRT54G</description>' | tee -a /tmp/rssfeed.xml; wget -q -O - http://192.168.1.1/user/stat.html | awk '{print "<item><title>"$0"</title><link>http://192.168.1.1/</link><description></description></item>"}' | tee -a /tmp/rssfeed.xml; echo '</channel></rss>' | tee -a /tmp/rssfeed.xml;
I have the script run every minute using Cron. Basically what it does is it downloades the stat.html file you have hosted on your router and uses that to create a /tmp/rssfeed.xml file. The created /tmp/rssfeed.xml file, that conforms to RSS markup standards, can then be inputted into a program of your choice. Firstly it adds an RSS header to the start of the file:
<?xml version="1.0" ?> <rss version="2.0"> <channel> <title>Router Connection Status</title> <link>http://192.168.1.1</link> <description>WRT54G</description>
Then it will add the RSS markup around each status line, so this:
Connection 1: 192.168.1.1 has 476 connections open.
will become:
<item> <title>Connection 1: 192.168.1.1 has 476 connections open.</title> <link>http://192.168.1.1/</link> <description></description> </item>
And then a footer markup to the end of the file:
</channel></rss>
Once it completes you have a /tmp/rssfeed.xml file that looks something like this:
<?xml version="1.0" ?> <rss version="2.0"> <channel><title>Router Connection Status</title><link>http://192.168.1.1</link><description>WRT54G</description> <item> <title>Connection 1: 192.168.1.1 has 71 connections open.</title> <link>http://192.168.1.1/</link> <description></description> </item> <item> <title>Connection 2: 192.168.1.143 has 65 connections open.</title> <link>http://192.168.1.1/</link> <description></description> </item> <item><title>Free: 11%</title> <link>http://192.168.1.1/</link> <description></description> </item> <item> <title>Used: 88%</title> <link>http://192.168.1.1/</link> <description></description> </item> <item> <title>Buffers: 12%</title> <link>http://192.168.1.1/</link> <description></description> </item> <item> <title>Cached: 36%</title> <link>http://192.168.1.1/</link> <description></description> </item> <item> <title>Load: 30%</title> <link>http://192.168.1.1/</link> <description></description> </item> <item><title>Uptime: 0.29 Hours</title> <link>http://192.168.1.1/</link> <description></description> </item> </channel> </rss>
This is basically an all purpose script that will change any input file into a format that an RSS reader can see. The best results are seen when the input file has each status on individual an line. You could technically combine both the router and computer scripts into one (both are shell scripts), located only on the router, but you can not host a non-html file in the /tmp/www and access it's contents without telnet/ssh. Without additional resources (samba, mmc, ect.) there aren't many other places to access the file. You could also probably setup a script to login via telnet/ssh to gather the settings as needed only utilizing the computer, which maybe an interesting alternative which doesn't rewrite to the flash as much (which technically burns out over time).