-
Notifications
You must be signed in to change notification settings - Fork 2
/
prtg-cmstats-sb8200.pl
192 lines (176 loc) · 9.55 KB
/
prtg-cmstats-sb8200.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# 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/>.
#
# Updated by John Walshaw 7-15-2018 for SB8200 in DOCSIC 3.1 mode
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;
# Set up for a 29-channel modem
my $content = $ua->get("http://192.168.100.1/cmconnectionstatus.html");
# Downstream power level
$content->decoded_content =~ m/Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.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+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n/;
#my $test1 = $1;
#my $test2 = $2;
#my $ofdm = $29;
#print "<text> Test " . $test1 . "</text>\n";
#print "<text> Test " . $test2 . "</text>\n";
#print "<text> OFDM " . $ofdm . "</text>\n";
@dpw[25] = $1;
@dpw[1] = $2;
@dpw[2] = $3;
@dpw[3] = $4;
@dpw[4] = $5;
@dpw[5] = $6;
@dpw[6] = $7;
@dpw[7] = $8;
@dpw[8] = $9;
@dpw[9] = $10;
@dpw[10] = $11;
@dpw[11] = $12;
@dpw[12] = $13;
@dpw[13] = $14;
@dpw[14] = $15;
@dpw[15] = $16;
@dpw[16] = $17;
@dpw[17] = $18;
@dpw[18] = $19;
@dpw[19] = $20;
@dpw[20] = $21;
@dpw[21] = $22;
@dpw[22] = $23;
@dpw[23] = $24;
@dpw[24] = $25;
@dpw[26] = $26;
@dpw[27] = $27;
@dpw[28] = $28;
my $ofdm = $29;
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";
print "<result>\n";
print "<channel>OFDM 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, $ofdm) . "</value>\n";
print "</result>\n";
$content->decoded_content =~ m/dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+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(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+dBmV<\/td>\n.+<td>(.+) dB<\/td>\n/;
#my $test1 = $1;
#my $test2 = $2;
#my $ofdmsnr = $29;
#print "<text> Test " . $test1 . "</text>\n";
#print "<text> Test " . $test2 . "</text>\n";
#print "<text> OFDM " . $ofdmsnr . "</text>\n";
@snr[25] = $1;
@snr[1] = $2;
@snr[2] = $3;
@snr[3] = $4;
@snr[4] = $5;
@snr[5] = $6;
@snr[6] = $7;
@snr[7] = $8;
@snr[8] = $9;
@snr[9] = $10;
@snr[10] = $11;
@snr[11] = $12;
@snr[12] = $13;
@snr[13] = $14;
@snr[14] = $15;
@snr[15] = $16;
@snr[16] = $17;
@snr[17] = $18;
@snr[18] = $19;
@snr[19] = $20;
@snr[20] = $21;
@snr[21] = $22;
@snr[22] = $23;
@snr[23] = $24;
@snr[24] = $25;
@snr[26] = $26;
@snr[27] = $27;
@snr[28] = $28;
my $ofdmsnr = $29;
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";
print "<result>\n";
print "<channel>Downstream OFDM 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, $ofdmsnr) . "</value>\n";
print "</result>\n";
# Set up for 4 upstream channels
$content->decoded_content =~ m/Upstream Bonded Channels<\/strong><\/th><\/tr>\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n.+\n.+\n.+\n.+\n.+\n.+\n.+Hz<\/td>\n.+<td>(.+) dBmV<\/td>\n/;
#my $test1 = $1;
#my $test2 = $2;
#print "<text> Test " . $test1 . "</text>\n";
#print "<text> Test " . $test2 . "</text>\n";
@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(@_)/@_;
}