-
Notifications
You must be signed in to change notification settings - Fork 4
/
adslstatus
executable file
·131 lines (107 loc) · 4.71 KB
/
adslstatus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::INET;
sub read_to {
my ($sock, $until) = @_;
my $read;
while (1) {
$read .= <$sock>;
last if $read =~ /$until$/
}
return $read;
}
sub read_status {
my $modem_host = $ENV{modem_host} || die "No modem_host set\n";
my $modem_password = $ENV{modem_password} || die "No modem_password set\n";
my $remote = IO::Socket::INET->new( PeerAddr => $modem_host, PeerPort => '23' );
print $remote "\r\n";
read_to($remote, 'Password: ');
print $remote "$modem_password\r\n\r\n";
read_to($remote, '> ');
print $remote "adsl status\r\n\r\n";
my $status = read_to($remote, '> ');
print $remote "exit\r\n\r\n";
close $remote;
return $status;
}
sub read_values {
my $status = read_status;
my %values;
($values{ds_rate}) = $status =~ /DS Actual Rate\s+:\s+(\d+)\s+bps/;
($values{ds_attainable_rate}) = $status =~ /DS Attainable Rate\s+:\s+(\d+)\s+bps/;
($values{us_rate}) = $status =~ /US Actual Rate\s+:\s+(\d+)\s+bps/;
($values{us_attainable_rate}) = $status =~ /US Attainable Rate\s+:\s+(\d+)\s+bps/;
$values{ds_rate} /= 1000;
$values{ds_attainable_rate} /= 1000;
$values{us_rate} /= 1000;
$values{us_attainable_rate} /= 1000;
($values{near_attenuation}) = $status =~ /NE Current Attenuation\s+:\s+(\d+)\s+dB/;
($values{near_snr_margin}) = $status =~ /Cur SNR Margin\s+:\s+(\d+)\s+dB/;
($values{near_psd}) = $status =~ /DS actual PSD\s+:\s+(\d+\.\s*\d+)\s+dB/;
$values{near_psd} =~ s/\s//g;
($values{far_attenuation}) = $status =~ /Far Current Attenuation\s+:\s+(\d+)\s+dB/;
($values{far_snr_margin}) = $status =~ /Far SNR Margin\s+:\s+(\d+)\s+dB/;
($values{far_psd}) = $status =~ /US actual PSD\s+:\s+(\d+\.\s*\d+)\s+dB/;
$values{far_psd} =~ s/\s//g;
return \%values;
}
$0 =~ /adslstatus_(.+)$/;
my $type = $1;
unless ( $1 eq 'speed' || $1 eq 'linestats' ) {
die "Must be called as either 'adslstatus_speed' or 'adslstatus_linestats'\n";
}
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
print "graph_category ADSL\n";
if ( $type eq 'speed' ) {
print "graph_title Connection speeds\n";
print "graph_vlabel kbps\n";
print "graph_scale no\n";
print "downstream.label Downstream speed\n";
print "downstream.draw LINE2\n";
print "downstream_attainable.label Downstream attainable speed\n";
print "downstream_attainable.draw LINE2\n";
print "upstream.label Upstream speed\n";
print "upstream.draw LINE2\n";
print "upstream_attainable.label Upstream attainable speed\n";
print "upstream_attainable.draw LINE2\n";
} elsif ( $type eq 'linestats' ) {
print "graph_title Line statistics\n";
print "graph_vlabel dB\n";
print "graph_scale no\n";
print "graph_info See http://www.kitz.co.uk/adsl/index.htm for help interpreting these figures.\n";
print "near_attenuation.label Downstream attenuation\n";
print "near_attenuation.draw LINE2\n";
print "near_attenuation.info Downstream attenuation, lower is better\n";
print "near_snr_margin.label Downstream SNR margin\n";
print "near_snr_margin.draw LINE2\n";
print "near_snr_margin.info Downstream SNR margin, higher is better\n";
print "near_psd.label Downstream PSD\n";
print "near_psd.draw LINE2\n";
print "near_psd.info Downstream power spectrum density\n";
print "far_attenuation.label Upstream attenuation\n";
print "far_attenuation.draw LINE2\n";
print "far_attenuation.info Upstream attenuation, lower is better\n";
print "far_snr_margin.label Upstream SNR margin\n";
print "far_snr_margin.draw LINE2\n";
print "far_snr_margin.info Upstream SNR margin, higher is better\n";
print "far_psd.label Upstream PSD\n";
print "far_psd.draw LINE2\n";
print "far_psd.info Upstream power spectrum density\n";
}
exit 0;
}
my $values = read_values;
if ( $type eq 'speed' ) {
print "downstream.value ".$values->{ds_rate}."\n";
print "downstream_attainable.value ".$values->{ds_attainable_rate}."\n";
print "upstream.value ".$values->{us_rate}."\n";
print "upstream_attainable.value ".$values->{us_attainable_rate}."\n";
} elsif ( $type eq 'linestats' ) {
print "near_attenuation.value ".$values->{near_attenuation}."\n";
print "near_snr_margin.value ".$values->{near_snr_margin}."\n";
print "near_psd.value ".$values->{near_psd}."\n";
print "far_attenuation.value ".$values->{far_attenuation}."\n";
print "far_snr_margin.value ".$values->{far_snr_margin}."\n";
print "far_psd.value ".$values->{far_psd}."\n";
}