-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathmactrack_3com.php
More file actions
279 lines (240 loc) · 10.2 KB
/
mactrack_3com.php
File metadata and controls
279 lines (240 loc) · 10.2 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
declare(strict_types = 1);
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| 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 2 |
| 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. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
// register this functions scanning functions
if (!isset($mactrack_scanning_functions)) {
$mactrack_scanning_functions = [];
}
array_push($mactrack_scanning_functions, 'get_3Com_dot1dTpFdbEntry_ports');
/* complete_3com_ifName
for buggy 3com SSII 1100 : they dont have ifName use ifDescr but it contains ':'
making it unusable for 'ignore port'
so transform it in PortN/M where N is stackId and M portnumber
*/
function complete_3com_ifName(&$device, &$ifIndexes) {
mactrack_debug('Start complete_3com_ifName');
// device without ifName detection
foreach ($ifIndexes as $ifidx) {
if ($ifidx['ifName'] != '') {
return;
} else {
break;
}
}
$pattern = '/RMON:V(\d+) Port (\d+) on Unit (\d+)/i';
$pattern2 = '/RMON Port (\d+) on Unit (\d+)/i';
$pattern3 = '/RMON:10\/100 Port (\d+) on Unit (\d+)/i';
$replacement = 'Port${3}/${2}';
$replacement2 = 'Port${2}/${1}';
$replacement3 = 'Port${2}/${1}';
$local_graph_id = db_fetch_assoc_prepared('SELECT local_graph_id
FROM mac_track_interface_graphs
WHERE device_id= ?',
[$device['device_id']]);
sort($local_graph_id);
// Get ifDescr and Format it
$i = 0;
$device_descr_array = xform_standard_indexed_data('.1.3.6.1.2.1.2.2.1.2',$device);
if (cacti_sizeof($device_descr_array)) {
foreach ($device_descr_array as $key => $ifd) {
if ($ifIndexes[$key]['ifName'] == '') {
$ifdesc = $device_descr_array[$key];
$ifdesc = preg_replace($pattern, $replacement, $ifdesc);
$ifdesc = preg_replace($pattern2, $replacement2, $ifdesc);
$ifdesc = preg_replace($pattern3, $replacement3, $ifdesc);
$ifIndexes[$key]['ifName'] = $ifdesc;
db_execute_prepared('UPDATE mac_track_interfaces
SET ifName = ?
WHERE device_id = ?
AND ifIndex = ?',
[$ifdesc, $device['device_id'], $key]);
if ($i < cacti_sizeof($local_graph_id)) {
db_execute('UPDATE mac_track_interface_graphs
SET ifIndex = ?, ifName = ?
WHERE device_id = ?
AND local_graph_id = ?',
[$key, $ifdesc, $device['device_id'], $$local_graph_id[$i]['local_graph_id']]);
}
$i++;
}
}
}
}
/* get_3Com_dot1dTpFdbEntry_ports
same as get_dot1dTpFdbEntry_ports with small modification for 3com devices
*/
function get_3Com_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $highPort = 0) {
global $debug, $scan_date;
// initialize port counters
$device['ports_total'] = 0;
$device['ports_active'] = 0;
$device['ports_trunk'] = 0;
// get the ifIndexes for the device
$ifIndexes = xform_standard_indexed_data('.1.3.6.1.2.1.2.2.1.1', $device);
mactrack_debug('ifIndexes data collection complete');
$ifInterfaces = build_InterfacesTable($device, $ifIndexes, true, false);
complete_3com_ifName($device, $ifInterfaces);
get_3Com_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, '', true, $lowPort, $highPort);
return $device;
}
/* same as get_base_dot1dTpFdbEntry_ports -
but add iftype 117 gbit ethernet.
*/
function get_3Com_base_dot1dTpFdbEntry_ports($site, &$device, &$ifInterfaces, $snmp_readstring = '', $store_to_db = true, $lowPort = 1, $highPort = 9999) {
global $debug, $scan_date;
mactrack_debug('Start get_3Com_base_dot1dTpFdbEntry_ports');
// initialize variables
$port_keys = [];
$return_array = [];
$new_port_key_array = [];
$port_key_array = [];
$port_descr = [];
$port_number = 0;
$ports_active = 0;
$active_ports = 0;
$ports_total = 0;
// cisco uses a hybrid read string, if one is not defined, use the default
if ($snmp_readstring == '') {
$snmp_readstring = $device['snmp_readstring'];
}
// get the operational status of the ports
$active_ports_array = xform_standard_indexed_data('.1.3.6.1.2.1.2.2.1.8', $device);
$indexes = array_keys($active_ports_array);
// get the console port
$link_ports = get_link_port_status($device);
$i = 0;
foreach ($active_ports_array as $port_info) {
if (($ifInterfaces[$indexes[$i]]['ifType'] == 6) && ($ifInterfaces[$indexes[$i]]['linkPort'] != 1)) {
if ($port_info == 1) {
$ports_active++;
}
$ports_total++;
}
$i++;
}
if ($store_to_db) {
mactrack_debug('INFO: HOST: ' . $device['hostname'] . ', TYPE: ' . substr($device['snmp_sysDescr'],0,40) . ', TOTAL PORTS: ' . $ports_total . ', OPER PORTS: ' . $ports_active);
$device['ports_active'] = $ports_active;
$device['ports_total'] = $ports_total;
$device['macs_active'] = 0;
}
if ($ports_active > 0) {
// get bridge port to ifIndex mapping
$bridgePortIfIndexes = xform_standard_indexed_data('.1.3.6.1.2.1.17.1.4.1.2', $device, $snmp_readstring);
$port_status = xform_stripped_oid('.1.3.6.1.2.1.17.4.3.1.3', $device, $snmp_readstring);
// get device active port numbers
$port_numbers = xform_stripped_oid('.1.3.6.1.2.1.17.4.3.1.2', $device, $snmp_readstring);
// get the ignore ports list from device
// $device['ignorePorts'] = $device['ignorePorts'].':Port1/50';
$ignore_ports = port_list_to_array($device['ignorePorts']);
/* determine user ports for this device and transfer user ports to
a new array.
*/
$i = 0;
foreach ($port_numbers as $key => $port_number) {
if (($highPort == 0) ||
(($port_number >= $lowPort) &&
($port_number <= $highPort))) {
$ifname = $ifInterfaces[$bridgePortIfIndexes[$port_number]]['ifName'];
if (!in_array($ifname, $ignore_ports, true)) {
if (isset($port_status[$key]) && $port_status[$key] == '3') {
$port_key_array[$i]['key'] = $key;
$port_key_array[$i]['port_number'] = $port_number;
$i++;
}
}
}
}
/* compare the user ports to the bridge port data, store additional
relevant data about the port.
*/
$i = 0;
foreach ($port_key_array as $port_key) {
// map bridge port to interface port and check type
if ($port_key['port_number'] > 0) {
if (cacti_sizeof($bridgePortIfIndexes) != 0) {
/* some hubs do not always return a port number in the bridge table.
test for it by isset and substitute the port number from the ifTable
if it isnt in the bridge table
*/
if (isset($bridgePortIfIndexes[$port_key['port_number']])) {
$brPortIfIndex = mactrack_arr_key($bridgePortIfIndexes, $port_key['port_number']);
} else {
$brPortIfIndex = isset($port_key['port_number']) ? $port_key['port_number'] : '';
}
$brPortIfType = isset($ifInterfaces[$brPortIfIndex]['ifType']) ? $ifInterfaces[$brPortIfIndex]['ifType'] : '';
} else {
$brPortIfIndex = $port_key['port_number'];
$brPortIfType = isset($ifInterfaces[$port_key['port_number']]['ifType']) ? $ifInterfaces[$port_key['port_number']]['ifType'] : '';
}
if (((($brPortIfType >= 6) &&
($brPortIfType <= 9)) || $brPortIfType == 117) &&
(!isset($ifInterfaces[$brPortIfIndex]['portLink']))) {
// set some defaults
$new_port_key_array[$i]['vlan_id'] = 'N/A';
$new_port_key_array[$i]['vlan_name'] = 'N/A';
$new_port_key_array[$i]['mac_address'] = 'NOT USER';
$new_port_key_array[$i]['port_number'] = 'NOT USER';
$new_port_key_array[$i]['port_name'] = 'N/A';
// now set the real data
$new_port_key_array[$i]['key'] = $port_key['key'];
$new_port_key_array[$i]['port_number'] = $port_key['port_number'];
$new_port_key_array[$i]['port_name'] = $ifInterfaces[$brPortIfIndex]['ifName'];
$i++;
}
}
}
mactrack_debug('Port number information collected.');
// map mac address
// only continue if there were user ports defined
if (cacti_sizeof($new_port_key_array) > 0) {
// get the bridges active MAC addresses
$port_macs = xform_stripped_oid('.1.3.6.1.2.1.17.4.3.1.1', $device, $snmp_readstring, true);
foreach ($port_macs as $key => $port_mac) {
$port_macs[$key] = xform_mac_address($port_mac);
}
foreach ($new_port_key_array as $key => $port_key) {
$new_port_key_array[$key]['mac_address'] = mactrack_arr_key($port_macs, $port_key['key']);
}
mactrack_debug('Port mac address information collected.');
} else {
mactrack_debug('No user ports on this network.');
}
} else {
mactrack_debug('No user ports on this network.');
}
if ($store_to_db) {
if ($ports_active <= 0) {
$device['last_runmessage'] = 'Data collection completed ok';
} elseif (cacti_sizeof($new_port_key_array) > 0) {
$device['last_runmessage'] = 'Data collection completed ok';
$device['macs_active'] = cacti_sizeof($new_port_key_array);
db_store_device_port_results($device, $new_port_key_array, $scan_date);
} else {
$device['last_runmessage'] = 'WARNING: Poller did not find active ports on this device.';
}
} else {
return $new_port_key_array;
}
}