Wasted Evening


Spent far too much time trying to get my WRT54g to talk SNMP again after upgrading it to a newer (hopefully more stable) firmware revision. I'd trash the whole thing and drop OpenWRT on it if:

  • It was slightly better documented (it isn't clear how I can go about doing MAC address filtering and other niceties that I can do via the "standard" web interface).
  • It was something I could actually hand over to other people (i.e., "normal" folk) for administration.

As it is, I'd rate OpenWRT as being tremendously powerful, but not something I want to waste time with, not at my age. So I'm still running one of the umpteen stock firmware variants, and have had to resort to telnet monitoring much along the lines of my SpeedTouch HOWTO.

Here is the little Perl script that I came up with (the resulting .txt file is then picked up by my master RRDTool script and used to generate graphs):

$ cat cable.pl
#!/usr/bin/perl
use Net::Telnet();
$szStatFile = $ENV{HOME} . "/var/spool/rrd/cable.txt";

$oLinksys = new Net::Telnet( Timeout=>10, Prompt=>'/\]#/');
$oLinksys->open("192.168.0.1");
$oLinksys->login("root", "my_password_of_course");
foreach('eth0', 'eth1', 'vlan1') {
  $i = $_;
  @lines = $oLinksys->cmd("ifconfig $i | grep bytes");
  foreach( @lines ) {
    if(/\s+RX bytes:(\d+).+TX bytes:(\d+)/) {
      $szBuffer .= "$i N:$1:$2\n";
    }
  }
}

$oLinksys->cmd(String=>"exit", Errmode=>"return");
open( FILE, ">$szStatFile");
print FILE $szBuffer;
close( FILE );

Before you ask, I decided to query each interface individually to minimize monitoring traffic (which is also why I chose not to use SSH). Took me a whole 5 minutes to come up with this - and a few hours to figure out which firmware versions supported SNMP, whether I could compile my own, etc.

Sometimes I forget that "Tech Made Simple" motto up on the right.

Good thing I have it on every page, I guess.


See Also: