Changing to independant script

This commit is contained in:
JosÃe UPV
2020-02-13 18:53:39 +01:00
parent d7f6fc205f
commit 09feaf1fd4
2 changed files with 36 additions and 26 deletions
+30
View File
@@ -33,6 +33,7 @@ if (!empty($dot1d)) {
foreach($data2 as $portLocal => $data3)
foreach($data3 as $vlanLocal => $data4)
$fdbPort_table[$vlanLocal]=array('dot1qTpFdbPort' => array_combine(array_keys($data4[0]),array_fill(0,count($data4[0]),$portLocal)));
} else {
// nokia/ALCATEL-IND1-MAC-ADDRESS-MIB::slMacAddressDisposition
$dot1d = snmpwalk_group($device, 'slMacAddressDisposition', 'ALCATEL-IND1-MAC-ADDRESS-MIB', 0,array(),'nokia');
@@ -44,3 +45,32 @@ if (!empty($dot1d)) {
$fdbPort_table[$vlanLocal]=array('dot1qTpFdbPort' => array_combine(array_keys($data2),array_fill(0,count($data2),$portLocal)));
}
}
if (!empty($fdbPort_table)) {
// Build dot1dBasePort to port_id dictionary
$portid_dict = array();
$dot1dBasePortIfIndex = snmpwalk_group($device, 'dot1dBasePortIfIndex', 'BRIDGE-MIB');
foreach ($dot1dBasePortIfIndex as $portLocal => $data) {
$port = get_port_by_index_cache($device['device_id'], $data['dot1dBasePortIfIndex']);
$portid_dict[$portLocal] = $port['port_id'];
}
// Collect data and populate $insert
foreach ($fdbPort_table as $vlan_id => $data) {
foreach ($data[$data_oid] as $mac => $dot1dBasePort) {
if ($dot1dBasePort == 0) {
d_echo("No port known for $mac\n");
continue;
}
$mac_address = implode(array_map('zeropad', explode(':', $mac)));
if (strlen($mac_address) != 12) {
d_echo("MAC address padding failed for $mac\n");
continue;
}
$port_id = $portid_dict[$dot1dBasePort];
$insert[$vlan_id][$mac_address]['port_id'] = $port_id;
d_echo("vlan $vlan_id mac $mac_address port ($dot1dBasePort) $port_id\n");
}
}
}
echo PHP_EOL;
+6 -26
View File
@@ -19,15 +19,14 @@
*
* @package LibreNMS
* @link http://librenms.org
* @copyright LibreNMS contributors
* @copyright 2017 Tony Murray
* @copyright 2017 Tony Murray
* @author Tony Murray <[email protected]>
* @author cjwbath
*/
if(empty($fdbPort_table)) {
// Try Q-BRIDGE-MIB::dot1qTpFdbPort first
$fdbPort_table = snmpwalk_group($device, 'dot1qTpFdbPort', 'Q-BRIDGE-MIB');
}
// Try Q-BRIDGE-MIB::dot1qTpFdbPort first
$fdbPort_table = snmpwalk_group($device, 'dot1qTpFdbPort', 'Q-BRIDGE-MIB');
if (!empty($fdbPort_table)) {
echo 'Q-BRIDGE-MIB:';
$data_oid = 'dot1qTpFdbPort';
@@ -49,28 +48,9 @@ if (!empty($fdbPort_table)) {
$port = get_port_by_index_cache($device['device_id'], $data['dot1dBasePortIfIndex']);
$portid_dict[$portLocal] = $port['port_id'];
}
// Build VLAN fdb index to real VLAN ID dictionary
$vlan_cur_table = snmpwalk_group($device, 'dot1qVlanFdbId', 'Q-BRIDGE-MIB', 2);
$vlan_fdb_dict = array();
// Indexed first by dot1qVlanTimeMark, which we ignore
foreach ($vlan_cur_table as $dot1qVlanTimeMark => $a) {
// Then by VLAN ID mapped to a single member array with the dot1qVlanFdbId
foreach ($a as $vid => $data) {
// Flip it round into the dictionary
$vlan_fdb_dict[$data['dot1qVlanFdbId']] = $vid;
}
}
print_r($vlan_fdb_dict);
// Collect data and populate $insert
foreach ($fdbPort_table as $vlanIndex => $data) {
// Look the dot1qVlanFdbId up to a real VLAN number; if undefined assume the
// index *is* the VLAN number. Code in fdb-table.inc.php to map to the
// device VLANs table should catch anything invalid.
$vlan = isset($vlan_fdb_dict[$vlanIndex]) ? $vlan_fdb_dict[$vlanIndex] : $vlanIndex;
foreach ($fdbPort_table as $vlan => $data) {
foreach ($data[$data_oid] as $mac => $dot1dBasePort) {
if ($dot1dBasePort == 0) {
d_echo("No port known for $mac\n");