My ISP got bought, moved, etc and suddenly my trusty old Cisco 678 DSL modem no longer sufficed. Grr. But oh well, Actiontec DSL modems aren’t that expensive, so I got a GT624R and things were groovy again. But the Cisco supported SNMP so that I could gather network stats for mrtg; the Actiontec does not. So I had to write my own script to get interface stats and output it in mrtg format, for anyone interested it’s below the jump.
#!/usr/bin/perl use Net::Telnet (); # Put your hostname here my $host = "actiontec"; # Put your admin username here my $username = "admin"; # Put your admin password here my $passwd = "PASSWORD"; $t = new Net::Telnet(Timeout => 10, Prompt => '/# $/'); $t->open($host); $t->login($username, $passwd); my @lines = $t->cmd("grep nas0 /proc/net/dev"); my @stats = split(/[: ]+/, $lines[0]); # Receive print "$stats[2]\n"; # Transmit print "$stats[10]\n"; @lines = $t->cmd("uptime"); if ($lines[0] =~ s/.* up (.*), load average: .*//m) { $uptime = $1; } else { # errr something went wrong just print it all $uptime = $lines[0]; } print "$uptime\n"; print "$host\n";
I don’t claim to write pretty perl. :)
Hrm. Could I bug you for a screenshot of the output? :) Just wanted to see how well it works.. :D