ADSL stats perl script (attached). Useful?
Posted: Mon Jun 16, 2014 5:18 pm
Don't know if this is useful to anyone else, here is a perl script that obtains the ADSL stats from a billion router. I'm no perl expert, but I was hoping to tweak it to monitor my line over time, and creating a CSV file with some stats that I can graph with regards to error rates over time.
If anyone wants to take it and improve on it, feel free, but please share the love...
You will need the perl libexpect-perl library and you will need to edit the file and put your router password in.
Tested on 7800DXL.
Output from mine:
The Perl script
If anyone wants to take it and improve on it, feel free, but please share the love...
You will need the perl libexpect-perl library and you will need to edit the file and put your router password in.
Tested on 7800DXL.
Output from mine:
Code: Select all
[1402934652] PROCESS_SERVICE_CHECK_RESULT;adslmodem;ADSL sync;0;ADSL2+ No Defect Showtime |'snr-down'=6.0dB 'snr-up'=5.8dB 'atten-down'=30.5dB 'atten-up'=15.7dB 'power-down'=0.0dB 'power-up'=12.8dB 'RS(Downstream):'=124745701 'RS(Upstream):'=1013355 'RSCorr(Downstream):'=18994 'RSCorr(Upstream):'=0 'RSUnCorr(Downstream):'=0 'RSUnCorr(Upstream):'=0
Code: Select all
#!/usr/bin/perl -w
use Expect;
$e = Expect->new();
$e->debug(0);
$e->log_stdout(0);
# Start Telnet session.
$e->spawn("telnet 192.168.1.254");
# Log in.
$e->expect(
5,
[ 'ogin',
sub {$self = shift; $self->send("admin\n"); exp_continue;} ],
[ 'Password:',
sub {$self = shift; $self->send("PASSWORD_CHANGEME\n"); exp_continue;} ],
'> '
);
$e->send("adsl info --show\n");
$e->expect(5, "> ");
my $result = $e->before();
print $result;
if ($result)
{
adslinfoshow($result);
}
$e->send("logout\n");
sub adslinfoshow
{
my $status = "";
my $performance = "";
my $returncode = 3;
foreach (split(/\n/, $_[0]))
{
s/\r$//;
/^Status: (G\.994 Training)/i and do { $status .= "$1 "; $returncode = 1; next; };
/^Status: (G\.992 Started)/i and do { $status .= "$1 "; $returncode = 1; next; };
/^Status: (G\.992 Channel Analysis)/i and do { $status .= "$1 "; $returncode = 1; next; };
/^Status: (G\.992 Message Exchange)/i and do { $status .= "$1 "; $returncode = 1; next; };
/^Status: (Idle)/i and do { $status .= "$1 "; $returncode = 2; next; };
/^Mode:\s+(.*)$/i and do { $status .= "$1 "; next; };
/^Channel:\s+(.*)$/i and do { $status .= "$1 "; next; };
/^Line Status:\s+(.*)$/i and
do { $status .= "$1 "; next; };
/^Training Status:\s+(.*)$/i and
do { $status .= "$1 ";
$1 eq "Showtime" and $returncode = 0;
next; };
/^SNR\s?\(dB\):\s+(.+?)\s+(.+?)$/ and
do { $performance .= "'snr-down'=$1dB 'snr-up'=$2dB "; next; };
/^Attn\s?\(dB\):\s+(.+?)\s+(.+?)$/ and
do { $performance .= "'atten-down'=$1dB 'atten-up'=$2dB "; next; };
/^Pwr\s?\(dBm\):\s+(.+?)\s+(.+?)$/ and
do { $performance .= "'power-down'=$1dB 'power-up'=$2dB "; next; };
/^Max\s?\(Kbps\):\s+(.+?)\s+(.+?)$/ and
do { $performance .= "'maxrate-down'=$1kbps 'maxrate-up'=$2kbps "; next; };
/^Rate\s?\(Kbps\):\s+(.+?)\s+(.+?)$/ and
do { $status .= "$1/$2kbps ";
$performance .= "'rate-down'=$1kbps 'rate-up'=$2kbps "; next; };
/^RS:\s+(.+?)\s+(.+?)$/ and
do { $performance .= "'RS(Downstream):'=$1 'RS(Upstream):'=$2 "; next; };
/^RSCorr:\s+(.+?)\s+(.+?)$/ and
do { $performance .= "'RSCorr(Downstream):'=$1 'RSCorr(Upstream):'=$2 "; next; };
/^RSUnCorr:\s+(.+?)\s+(.+?)$/ and
do { $performance .= "'RSUnCorr(Downstream):'=$1 'RSUnCorr(Upstream):'=$2 "; next; };
}
my $timestamp = time;
print "[$timestamp] PROCESS_SERVICE_CHECK_RESULT;adslmodem;ADSL sync;$returncode;$status|$performance\n";
}