forked from maschinenlesbar/fritzdocsis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfritzdocsis_.php
executable file
·175 lines (168 loc) · 6.66 KB
/
fritzdocsis_.php
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
#!/usr/bin/php
<?php
// Configure me hard!
// Please configure Fritz!Box Login Data in /lib/fritzbox_user.conf.php
$tmpFile="/tmp/fritzdocsis.db.";
$tmpFileMaxAge="60";
// NO NEED TO EDIT BELOW HERE!
require_once(__DIR__."/lib/fritzbox_api.class.php");
require_once(__DIR__."/lib/lua_parser.class.php");
require_once(__DIR__."/lib/sbLib.php");
// Check if we have to do a new DOCSIS query
if(!file_exists($tmpFile."downstream") || (filemtime($tmpFile."downstream") < time() - $tmpFileMaxAge)) {
// Get us a new fritzbox handler
$fritz = new fritzbox_api();
/*
// Refresh the Page
$params = array(
'getpage' => '../html/de/menus/menu2.html',
'var:menu' => 'internet',
'var:pagename' => 'docsis',
'var:errorpagename' => 'docsis',
'var:type' => '0',
);
$fritz->doPostForm($params);
*/
// Get the "Kabel Informationen" details page
$params = array('getpage' => '/internet/docsis_info.lua');
$output = $fritz->doGetRequest($params);
// Disconnect from the Webinterface
$fritz = null;
$dat = formatLua($output);
$downstream=array();
$upstream=array();
for($i=0; $i<100; $i++) {
// find Downstream channel IDs
if(array_key_exists("docsis:status/snmpOidCom/int/1/3/6/1/2/1/10/127/1/1/1/1/1/".$i,$dat["QUERIES"])) {
// Generate a more DOCSIS-OID like data structure (see http://www.oidview.com/mibs/0/DOCS-IF-MIB.html)
$channel=array(
"docsIfDownChannelId" => $i,
"docsIfDownChannelFrequency" => $dat["QUERIES"]["docsis:status/snmpOidCom/int/1/3/6/1/2/1/10/127/1/1/1/1/2/".$i],
"docsIfDownChannelPower" => $dat["QUERIES"]["docsis:status/snmpOidCom/int/1/3/6/1/2/1/10/127/1/1/1/1/6/".$i],
"docsIfSigQCorrecteds" => $dat["QUERIES"]["docsis:status/snmpOidCom/int/1/3/6/1/2/1/10/127/1/1/4/1/3/".$i],
"docsIfSigQUncorrectables" => $dat["QUERIES"]["docsis:status/snmpOidCom/int/1/3/6/1/2/1/10/127/1/1/4/1/4/".$i],
// And now AVM switched to another MIB for no reason (see http://www.oidview.com/mibs/4491/DOCS-IF3-MIB.html)
"docsIf3SignalQualityExtRxMER" => $dat["QUERIES"]["docsis:status/snmpOidCom/int/1/3/6/1/4/1/4491/2/1/20/1/24/1/1/".$i],
// And back to the former
"docsIfDownChannelInterleave" => $dat["QUERIES"]["docsis:status/snmpOidCom/int_2_ds_interleaving/1/3/6/1/2/1/10/127/1/1/1/1/5/".$i],
"docsIfDownChannelModulation" => $dat["QUERIES"]["docsis:status/snmpOidCom/int_2_ds_mod_type/1/3/6/1/2/1/10/127/1/1/1/1/4/".$i],
);
array_push($downstream,$channel);
}
if(array_key_exists("docsis:status/snmpOidCom/int/1/3/6/1/2/1/10/127/1/1/2/1/1/".$i,$dat["QUERIES"])) {
// Generate the same for upstream
$channel=array(
"docsIfUpChannelId" => $i,
"docsIfUpChannelType" => $dat["QUERIES"]["docsis:status/snmpOidCom/int_2_us_ch_type/1/3/6/1/2/1/10/127/1/1/2/1/15/".$i],
);
// Because AVM didn't stick to standard SNMP we need to fumble upstream power and modulation out of a real mess!
// DISCLAIMER: I'm not resposible for breaking SNMP naming here! *grumble
$upChannels=explode(",",$dat["QUERIES"]["docsis:status/ChdbEntry/us_usid_a"]);
$upPower=explode(",",$dat["QUERIES"]["docsis:status/UpstreamDbEntry/txPower_a"]);
// Modulation is even more inconsistent, not useable ATM
//$upModulation=explide(",",$dat["QUERIES"]["docsis:status/UcdChannels/usModType_a"]);
for($h=0;$h < count($upChannels); $h++) {
// Pretty ugly: Channel Number 0 seems to mean "not used" to AVM
if($upChannels[$h]!="0") {
$channel["docsIfUpChannelPower"]=$upPower[$h];
}
}
array_push($upstream,$channel);
}
}
// Serialize what we have
file_put_contents($tmpFile."downstream",serialize($downstream));
file_put_contents($tmpFile."upstream",serialize($upstream));
} else {
// Unserialize from file
$downstream=unserialize(file_get_contents($tmpFile."downstream"));
$upstream=unserialize(file_get_contents($tmpFile."upstream"));
}
// Enable to see magic happening
/*
print_r($downstream);
print_r($upstream);
exit;
*/
// Munin plugin part
// Check if the user wants a config suggestions
if(isset($argv[1])) {
if($argv[1]=="suggest") {
foreach(array_keys($downstream) as $downId) {
echo "ln -s ".$argv[0]." /etc/munin/plugins/fritzdocsis_down_".$downId."\n";
echo "ln -s ".$argv[0]." /etc/munin/plugins/fritzdocsis_downerr_".$downId."\n";
}
foreach(array_keys($upstream) as $upId) {
echo "ln -s ".$argv[0]." /etc/munin/plugins/fritzdocsis_up_".$upId."\n";
}
exit(0);
}
}
// Detect our function derived from our name:
// fritzbox_up_1 -> output upstream channel 1 information
// fritzbox_down_5 -> output downstream channel 5 information
preg_match("/.*_(up|down|downerr)_([0-9])/",$argv[0],$selector);
// up or down?
$mode=$selector[1];
// channel id?
$chId=$selector[2];
/*
* MUNIN fritzdocsis_up_N
* Shows Upstream Power levels
*/
if($mode=="up" && !empty($argv[1])){
if($argv[1] == "config") {
echo "graph_title FritzBox DOCSIS Upstream Channel $chId"."\n";
echo "graph_vlabel Upstream Channel $chId"."\n";
echo "graph_scale no"."\n";
echo "graph_category fritzbox"."\n";
echo "power.label Power Level [dBmV]"."\n";
echo "power.critical 40:50"."\n";
exit(0);
}
}
if($mode=="up") {
echo "power.value ".($upstream[$chId]["docsIfUpChannelPower"]/10)."\n";
}
/*
* MUNIN fritzdocsis_down_N
* Shows Downstream Power levels and line loss
*/
if($mode=="down" && !empty($argv[1])){
if($argv[1] == "config") {
echo "graph_title FritzBox DOCSIS Downstream Channel $chId"."\n";
echo "graph_vlabel Downstream Channel $chId"."\n";
echo "graph_scale no"."\n";
echo "graph_category fritzbox"."\n";
echo "power.label Power Level [dBmV]"."\n";
echo "power.critical -3:8"."\n";
echo "snr.label MSE [dB]"."\n";
exit(0);
}
}
if($mode=="down") {
echo "power.value ".($downstream[$chId]["docsIfDownChannelPower"]/10)."\n";
echo "snr.value ".($downstream[$chId]["docsIf3SignalQualityExtRxMER"]/10)."\n";
}
/*
* MUNIN fritzdocsis_downerr_N
* Shows Correctable and Uncorrectable error
*/
if($mode=="downerr" && !empty($argv[1])){
if($argv[1] == "config") {
echo "graph_title FritzBox DOCSIS Downstream Channel $chId Errors"."\n";
echo "graph_vlabel Channel $chId Errors"."\n";
echo "graph_scale no"."\n";
echo "graph_category fritzbox"."\n";
echo "correctable.label Correctable Errors"."\n";
echo "correctable.type COUNTER"."\n";
echo "uncorrectable.label Uncorrectable Errors"."\n";
echo "uncorrectable.type COUNTER"."\n";
exit(0);
}
}
if($mode=="downerr") {
echo "correctable.value ".$downstream[$chId]["docsIfSigQCorrecteds"]."\n";
echo "uncorrectable.value ".$downstream[$chId]["docsIfSigQUncorrectables"]."\n";
}
?>