-
Notifications
You must be signed in to change notification settings - Fork 2
/
prtg-cmstats-sb6141.pl
126 lines (110 loc) · 4.34 KB
/
prtg-cmstats-sb6141.pl
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
# Returns XML formatted data from a motorola cable modem for PRTG
# Skylar Gasai / https://github.com/YandereSkylar/cabletools
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
use LWP::Simple;
use Math::Round;
use List::Util qw(sum);
use List::Util qw( min max );
use List::MoreUtils qw( minmax );
my @dpw;
my @snr;
my @upw;
print '<?xml version="1.0" encoding="Windows-1252" ?>' . "\n";
print "<prtg>\n";
my $ua = LWP::UserAgent->new;
my $content = $ua->get("http://192.168.100.1/indexData.htm");
$content->decoded_content =~ m/System Up Time<\/TD>\n <TD>(.+)s<\/TD><\/TR>/;
my $uptime = $1;
print "<text> Up " . $uptime . "s</text>\n";
#$uptime =~ s/:/ /;
#$uptime .= "s";
# $uptime =~ m/(\d+) days (\d+)h:(\d+)m:(\d+)/;
# my $updays = $1;
# my $uphours = $2;
# my $upmins = $3;
# my $upsecs = $4;
# #print "Up $updays d $uphours h $upmins m $upsecs s";
# $uptime = $upsecs + ($upmins * 60) + ($uphours * 3600) + ($updays * 86400);
# print "<result>\n";
# print "<channel>Cable Modem Uptime</channel>\n";
# print "<unit>TimeHours</unit>\n";
# print "<value>" . $uptime . "</value>\n";
# print "</result>\n";
my $content = $ua->get("http://192.168.100.1/cmSignalData.htm"); # Set up for an 8-channel modem
# Downstream power level
$content->decoded_content =~ m/<TD>(.+) dBmV\n\ <\/TD><TD>(.+) dBmV\n\ <\/TD><TD>(.+) dBmV\n\ <\/TD><TD>(.+) dBmV\n\ <\/TD><TD>(.+) dBmV\n\ <\/TD><TD>(.+) dBmV\n\ <\/TD><TD>(.+) dBmV\n\ <\/TD><TD>(.+) dBmV/;
@dpw[0] = $1;
@dpw[1] = $2;
@dpw[2] = $3;
@dpw[3] = $4;
@dpw[4] = $5;
@dpw[5] = $6;
@dpw[6] = $7;
@dpw[7] = $8;
print "<result>\n";
print "<channel>Downstream Power Level</channel>\n";
print "<customUnit>dBmV</customUnit>\n";
print "<float>1</float>\n";
print "<LimitMode>1</LimitMode>\n";
print "<LimitMaxWarning>8</LimitMaxWarning>\n";
print "<LimitMaxError>15</LimitMaxError>\n";
print "<LimitMinWarning>-4</LimitMinWarning>\n";
print "<LimitMinError>-15</LimitMinError>\n";
print "<LimitWarningMsg>Signal level out of recommended range.</LimitWarningMsg>\n";
print "<LimitErrorMsg>Signal level out of recommended range.</LimitErrorMsg>\n";
print "<value>" . nearest(0.1, mean(@dpw)) . "</value>\n";
print "</result>\n";
$content->decoded_content =~ m/<TD>(.+) dB\ <\/TD><TD>(.+) dB\ <\/TD><TD>(.+) dB\ <\/TD><TD>(.+) dB\ <\/TD><TD>(.+) dB\ <\/TD><TD>(.+) dB <\/TD><TD>(.+) dB <\/TD><TD>(.+) dB/;
@snr[0] = $1;
@snr[1] = $2;
@snr[2] = $3;
@snr[3] = $4;
@snr[4] = $5;
@snr[5] = $6;
@snr[6] = $7;
@snr[7] = $8;
print "<result>\n";
print "<channel>Downstream SNR</channel>\n";
print "<customUnit>dB</customUnit>\n";
print "<float>1</float>\n";
print "<LimitMode>1</LimitMode>\n";
print "<LimitMinWarning>33</LimitMinWarning>\n";
print "<LimitMinError>30</LimitMinError>\n";
print "<LimitWarningMsg>Signal level out of recommended range.</LimitWarningMsg>\n";
print "<LimitErrorMsg>Signal level out of recommended range.</LimitErrorMsg>\n";
print "<value>" . nearest(0.1, mean(@snr)) . "</value>\n";
print "</result>\n";
# Set up for 4 upstream channels
$content->decoded_content =~ m/<TD>(.+) dBmV\ <\/TD><TD>(.+) dBmV\ <\/TD><TD>(.+) dBmV\ <\/TD><TD>(.+) dBmV\ <\/TD><\/TR>/;
@upw[0] = $1;
@upw[1] = $2;
@upw[2] = $3;
@upw[3] = $4;
print "<result>\n";
print "<channel>Upstream Power Level</channel>\n";
print "<customUnit>dBmV</customUnit>\n";
print "<float>1</float>\n";
print "<LimitMode>1</LimitMode>\n";
print "<LimitMaxWarning>50</LimitMaxWarning>\n";
print "<LimitMaxError>55</LimitMaxError>\n";
print "<LimitWarningMsg>Signal level out of recommended range.</LimitWarningMsg>\n";
print "<LimitErrorMsg>Signal level out of recommended range.</LimitErrorMsg>\n";
print "<value>" . nearest(0.1, mean(@upw)) . "</value>\n";
print "</result>\n";
print "</prtg>";
sub mean {
return sum(@_)/@_;
}