Commit version 24.12.13800

This commit is contained in:
2025-01-06 17:35:06 -05:00
parent b7f6a79c2c
commit 55d9218816
6133 changed files with 4239740 additions and 1374287 deletions

View File

@ -4,9 +4,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
@ -19,39 +19,41 @@ $dot1d_baseports = snmp_cache_table($device, 'dot1dBasePortIfIndex', [], 'BRIDGE
foreach ($hwdot1qVlan as $vlan_num => $vlan) {
$vlan_array = [
'ifIndex' => $vlan['hwVlanInterfaceIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['hwdot1qVlanName'],
//'vlan_mtu' => '',
'vlan_type' => $vlan['hwdot1qVlanType'],
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
$vlan_array = [
'ifIndex' => $vlan['hwVlanInterfaceIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['hwdot1qVlanName'],
//'vlan_mtu' => '',
'vlan_type' => $vlan['hwdot1qVlanType'],
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
// Convert hex to binary map
$binary = hex2binmap($vlan['hwdot1qVlanPorts']);
// Convert hex to binary map
$binary = hex2binmap($vlan['hwdot1qVlanPorts']);
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i]) {
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i]) {
//if ($use_baseports) {
// Skip all unknown indexes (OBS-2958)
if (!isset($dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'])) { continue; }
$ifIndex = $dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'];
// } else {
// $ifIndex = $i;
// }
//$binary_debug[$vlan_num][$i] = $ifIndex; // DEBUG
//if ($use_baseports) {
// Skip all unknown indexes (OBS-2958)
if (!isset($dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'])) {
continue;
}
$ifIndex = $dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'];
// } else {
// $ifIndex = $i;
// }
//$binary_debug[$vlan_num][$i] = $ifIndex; // DEBUG
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
];
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
];
}
}
}
}
// EOF

View File

@ -4,9 +4,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/

View File

@ -4,9 +4,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
@ -21,39 +21,39 @@
// Note, same for AtiStackSwitch9000-MIB
$vlan_oids = snmpwalk_cache_oid($device, 'atiStkSwVlanName', [], $mib);
$vlan_oids = snmpwalk_cache_oid($device, 'atiStkSwVlanConfigEntryStatus', $vlan_oids, $mib);
$vlan_oids = snmpwalk_cache_oid($device, 'atiStkSwVlanTaggedPortListModule1', $vlan_oids, $mib);
$vlan_oids = snmpwalk_cache_oid($device, 'atiStkSwVlanConfigEntryStatus', $vlan_oids, $mib);
$vlan_oids = snmpwalk_cache_oid($device, 'atiStkSwVlanTaggedPortListModule1', $vlan_oids, $mib);
//$vlan_oids = snmpwalk_cache_oid($device, 'atiStkSwVlanUntaggedPortListModule1', $vlan_oids, $mib);
print_debug_vars($vlan_oids);
$vtp_domain_index = '1'; // Yep, always use domain index 1
//$ports_vlans = [];
foreach ($vlan_oids as $vlan_num => $vlan)
{
// Skip not exist vlans
if ($vlan['atiStkSwVlanConfigEntryStatus'] != 'active') { continue; }
foreach ($vlan_oids as $vlan_num => $vlan) {
// Skip not exist vlans
if ($vlan['atiStkSwVlanConfigEntryStatus'] != 'active') {
continue;
}
$vlan_array = [
//'ifIndex' => $vlan['vlanPortNumber'],
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => strlen($vlan['atiStkSwVlanName']) ? $vlan['atiStkSwVlanName'] : "Vlan $vlan_num",
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$vlan_array = [
//'ifIndex' => $vlan['vlanPortNumber'],
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => strlen($vlan['atiStkSwVlanName']) ? $vlan['atiStkSwVlanName'] : "Vlan $vlan_num",
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
foreach (list_to_range($vlan['atiStkSwVlanTaggedPortListModule1']) as $ifIndex)
{
//$ports_vlans[$ifIndex]['tagged'][] = $vlan_num;
$discovery_ports_vlans[$ifIndex][$vlan_num] = array('vlan' => $vlan_num);
}
// foreach (list_to_range($vlan['atiStkSwVlanUntaggedPortListModule1']) as $ifIndex)
// {
// $ports_vlans[$ifIndex]['untagged'][] = $vlan_num;
// }
foreach (list_to_range($vlan['atiStkSwVlanTaggedPortListModule1']) as $ifIndex) {
//$ports_vlans[$ifIndex]['tagged'][] = $vlan_num;
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
}
// foreach (list_to_range($vlan['atiStkSwVlanUntaggedPortListModule1']) as $ifIndex)
// {
// $ports_vlans[$ifIndex]['untagged'][] = $vlan_num;
// }
}
//print_vars($ports_vlans);

View File

@ -0,0 +1,39 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
$vlan_oids = snmpwalk_cache_oid($device, 'vifName', [], 'BISON-ROUTER-MIB');
if (!snmp_status()) {
return;
}
$vlan_oids = snmpwalk_cache_oid($device, 'vifCvid', $vlan_oids, 'BISON-ROUTER-MIB');
print_debug_vars($vlan_oids);
$vtp_domain_index = '1'; // Yep, always use domain index 1
foreach ($vlan_oids as $vifIndex => $vlan) {
$vlan_num = $vlan['vifCvid'];
$vlan_array = [
'ifIndex' => $vifIndex,
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan['vifCvid'],
'vlan_name' => $vlan['vifName'],
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
}
// EOF

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
@ -14,145 +14,160 @@
$vtpversion = snmp_get_oid($device, 'vtpVersion.0', 'CISCO-VTP-MIB', NULL, OBS_SNMP_ALL_NUMERIC);
switch ($vtpversion) {
case 'none':
case '1':
case '2':
case '3':
case 'one':
case 'two':
case 'three':
// FIXME - can have multiple VTP domains.
$vtpdomains = snmpwalk_cache_oid($device, 'vlanManagementDomains', array(), 'CISCO-VTP-MIB');
if (snmp_status()) {
//$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanEntry', array(), 'CISCO-VTP-MIB');
$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanState', [], 'CISCO-VTP-MIB');
$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanType', $vtpvlans, 'CISCO-VTP-MIB');
$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanName', $vtpvlans, 'CISCO-VTP-MIB');
$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanMtu', $vtpvlans, 'CISCO-VTP-MIB');
$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanIfIndex', $vtpvlans, 'CISCO-VTP-MIB');
}
case 'none':
case '1':
case '2':
case '3':
case 'one':
case 'two':
case 'three':
// FIXME - can have multiple VTP domains.
$vtpdomains = snmpwalk_cache_oid($device, 'vlanManagementDomains', [], 'CISCO-VTP-MIB');
if (snmp_status()) {
//$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanEntry', array(), 'CISCO-VTP-MIB');
$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanState', [], 'CISCO-VTP-MIB');
$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanType', $vtpvlans, 'CISCO-VTP-MIB');
$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanName', $vtpvlans, 'CISCO-VTP-MIB');
$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanMtu', $vtpvlans, 'CISCO-VTP-MIB');
$vtpvlans = snmpwalk_cache_twopart_oid($device, 'vtpVlanIfIndex', $vtpvlans, 'CISCO-VTP-MIB');
}
foreach ($vtpdomains as $vtp_domain_index => $vtpdomain) {
// Skip disabled vtp domains
if (in_array($vtpdomain['managementDomainRowStatus'], array('notInService', 'notReady', 'destroy'))) {
continue;
}
foreach ($vtpdomains as $vtp_domain_index => $vtpdomain) {
// Skip disabled vtp domains
if (in_array($vtpdomain['managementDomainRowStatus'], [ 'notInService', 'notReady', 'destroy' ])) {
continue;
}
if ($vtpdomain['managementDomainName']) {
echo("(Domain $vtp_domain_index ".$vtpdomain['managementDomainName'].")");
} else {
echo("(Domain $vtp_domain_index".")");
}
if ($vtpdomain['managementDomainName']) {
echo("(Domain $vtp_domain_index " . $vtpdomain['managementDomainName'] . ")");
} else {
echo("(Domain $vtp_domain_index" . ")");
}
foreach ($vtpvlans[$vtp_domain_index] as $vlan_id => $vlan) {
// Skip extra entries with unknown state
if (!isset($vlan['vtpVlanState'], $vlan['vtpVlanType'])) { continue; }
foreach ($vtpvlans[$vtp_domain_index] as $vlan_id => $vlan) {
// Skip extra entries with unknown state
if (!isset($vlan['vtpVlanState'], $vlan['vtpVlanType'])) {
continue;
}
$vlan_array = array('ifIndex' => $vlan['vtpVlanIfIndex'],
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_id,
'vlan_name' => $vlan['vtpVlanName'],
'vlan_mtu' => $vlan['vtpVlanMtu'],
'vlan_type' => $vlan['vtpVlanType'],
'vlan_status' => $vlan['vtpVlanState'],
'vlan_context' => 0); // Vlan context exist validated below
$discovery_vlans[$vtp_domain_index][$vlan_id] = $vlan_array;
// Vlan context exist validated below
$vlan_array = [
'ifIndex' => $vlan['vtpVlanIfIndex'],
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_id,
'vlan_name' => $vlan['vtpVlanName'],
'vlan_mtu' => $vlan['vtpVlanMtu'],
'vlan_type' => $vlan['vtpVlanType'],
'vlan_status' => $vlan['vtpVlanState'],
'vlan_context' => 0
];
$discovery_vlans[$vtp_domain_index][$vlan_id] = $vlan_array;
}
}
break;
}
}
break;
}
// Check if per port vlans (with contexts) supported by Q-BRIDGE-MIB
$check_ports_vlans = isset($config['os'][$device['os']]['snmp']['virtual']) &&
$config['os'][$device['os']]['snmp']['virtual'];
if ($check_ports_vlans && is_device_mib($device, 'Q-BRIDGE-MIB')) {
// This shit only seems to work on Cisco (probably only IOS/IOS-XE and NX-OS)
// But don't worry, walking do only if vlans previously found
// This shit only seems to work on Cisco (probably only IOS/IOS-XE and NX-OS),
// But doesn't worry, walking do only if vlans previously found
list($ios_version) = explode('(', $device['version']);
$ios_version = explode('(', $device['version'])[0];
if (!safe_empty($device['snmp_context'])) {
// Already configured snmp context
print_warning("WARNING: Device already configured with SNMP context, polling ports vlans not possible.");
$check_ports_vlans = FALSE;
} elseif ($device['snmp_version'] === 'v3' && $device['os'] === "ios" && ($ios_version * 10) <= 121) {
// vlan context not worked on Cisco IOS <= 12.1 (SNMPv3)
print_error("ERROR: For VLAN context to work on this device please use SNMP v2/v1 for this device (or upgrade IOS).");
$check_ports_vlans = FALSE;
}
if (!safe_empty($device['snmp_context'])) {
// Already configured snmp context
print_warning("WARNING: Device already configured with SNMP context, polling ports vlans not possible.");
$check_ports_vlans = FALSE;
} elseif ($device['snmp_version'] === 'v3' && $device['os'] === "ios" && version_compare($ios_version, '12.1', '<=')) {
// vlan context isn't worked on Cisco IOS <= 12.1 (SNMPv3)
print_error("ERROR: For VLAN context to work on this device please use SNMP v2/v1 for this device (or upgrade IOS).");
$check_ports_vlans = FALSE;
}
}
if ($check_ports_vlans && safe_count($discovery_vlans)) { // Per port vlans walking allowed (see above)
// Fetch first domain index
$vtp_domain_index = array_key_first($discovery_vlans);
// Fetch first domain index
$vtp_domain_index = array_key_first($discovery_vlans);
foreach ($discovery_vlans[$vtp_domain_index] as $vlan_id => $entry) {
/* Per port vlans */
$vlans = array_keys($discovery_vlans[$vtp_domain_index]);
shuffle($vlans); // Shuffle vlans, prevent vlan1 be first
foreach ($vlans as $vlan_id) {
/* Per port vlans */
// /usr/bin/snmpbulkwalk -v2c -c kglk5g3l454@988 -OQUs -m BRIDGE-MIB -M /opt/observium/mibs/ udp:sw2.ahf:161 dot1dStpPortEntry
// /usr/bin/snmpbulkwalk -v2c -c kglk5g3l454@988 -OQUs -m BRIDGE-MIB -M /opt/observium/mibs/ udp:sw2.ahf:161 dot1dBasePortEntry
// /usr/bin/snmpbulkwalk -v2c -c kglk5g3l454@988 -OQUs -m BRIDGE-MIB -M /opt/observium/mibs/ udp:sw2.ahf:161 dot1dStpPortEntry
// /usr/bin/snmpbulkwalk -v2c -c kglk5g3l454@988 -OQUs -m BRIDGE-MIB -M /opt/observium/mibs/ udp:sw2.ahf:161 dot1dBasePortEntry
// FIXME - do this only when vlan type == ethernet?
// Cisco IOS Vlans:
// 0, 4095 For system use only. You cannot see or use these VLANs.
// 1002-1005 Cisco defaults for FDDI and Token Ring. You cannot delete VLANs 1002-1005
if (is_numeric($vlan_id) &&
$vlan_id != 4095 && ($vlan_id < 1002 || $vlan_id > 1005)) { // Ignore reserved VLAN IDs
$vlan_data = [];
// FIXME - do this only when vlan type == ethernet?
// Cisco IOS Vlans:
// 0, 4095 For system use only. You cannot see or use these VLANs.
// 1002-1005 Cisco defaults for FDDI and Token Ring. You cannot delete VLANs 1002-1005
if (is_numeric($vlan_id) &&
$vlan_id != 4095 && ($vlan_id < 1002 || $vlan_id > 1005)) { // Ignore reserved VLAN IDs
$vlan_data = [];
// Vlan specific context
if ($device['snmp_version'] === 'v3') {
$context = 'vlan-' . $vlan_id;
} else {
$context = $vlan_id;
}
// Vlan specific context
if ($device['snmp_version'] === 'v3') {
$context = 'vlan-' . $vlan_id;
} else {
$context = $vlan_id;
}
$context_valid = snmp_virtual_exist($device, $context);
if ($context_valid) {
$device_context = $device;
// Add vlan context for snmp auth
$device_context['snmp_context'] = $context;
// Set retries to 1 for speedup walking
//$device_context['snmp_retries'] = 1;
$context_valid = snmp_virtual_exist($device, $context);
if ($context_valid) {
$device_context = $device;
// Add vlan context for snmp auth
$device_context['snmp_context'] = $context;
// Set retries to 1 for speedup walking
//$device_context['snmp_retries'] = 1;
$vlan_data = snmpwalk_cache_oid($device_context, "dot1dBasePortIfIndex", $vlan_data, "BRIDGE-MIB");
if (snmp_status()) {
// FIXME. disable STP by default?
$vlan_data = snmpwalk_cache_oid($device_context, "dot1dStpPortEntry", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
//$vlan_data = snmpwalk_cache_oid($device_context, "dot1dStpPortPriority", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
//$vlan_data = snmpwalk_cache_oid($device_context, "dot1dStpPortState", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
//$vlan_data = snmpwalk_cache_oid($device_context, "dot1dStpPortPathCost", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
$vlan_data = snmpwalk_cache_oid($device_context, "dot1dBasePortIfIndex", $vlan_data, "BRIDGE-MIB");
if (snmp_status()) {
// FIXME. disable STP by default?
$vlan_data = snmpwalk_cache_oid($device_context, "dot1dStpPortEntry", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
//$vlan_data = snmpwalk_cache_oid($device_context, "dot1dStpPortPriority", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
//$vlan_data = snmpwalk_cache_oid($device_context, "dot1dStpPortState", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
//$vlan_data = snmpwalk_cache_oid($device_context, "dot1dStpPortPathCost", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
}
unset($device_context);
// At this point vlan context is validated and exist
$discovery_vlans[$vtp_domain_index][$vlan_id]['vlan_context'] = 1;
} elseif ($context_valid === FALSE &&
!snmp_virtual_exist($device, $context, 'dot1dBaseNumPorts')) {
// dot1dBaseBridgeAddress.0 = 0:0:0:0:0:0
// dot1dBaseNumPorts.0 = 0
// dot1dBaseType.0 = transparent-only
print_debug("VLANs context failed, loop stopped.");
// Stop loop for other vlans
break;
}
if ($vlan_data) {
print_debug(str_pad("dot1d id", 10) . str_pad("ifIndex", 10) . str_pad("Port Name", 25) .
str_pad("Priority", 10) . str_pad("State", 15) . str_pad("Cost", 10));
}
foreach ($vlan_data as $vlan_port_id => $vlan_port) {
$ifIndex = $vlan_port['dot1dBasePortIfIndex'];
$discovery_ports_vlans[$ifIndex][$vlan_id] = [
'vlan' => $vlan_id,
// FIXME. move STP to separate table
'baseport' => $vlan_port_id,
'priority' => $vlan_port['dot1dStpPortPriority'],
'state' => $vlan_port['dot1dStpPortState'],
'cost' => $vlan_port['dot1dStpPortPathCost']
];
}
} else {
unset($module_stats[$vlan_id]);
}
unset($device_context);
// At this point vlan context is validated and exist
$discovery_vlans[$vtp_domain_index][$vlan_id]['vlan_context'] = 1;
} elseif ($context_valid === FALSE) {
// Stop loop for other vlans
break;
}
if ($vlan_data)
{
print_debug(str_pad("dot1d id", 10).str_pad("ifIndex", 10).str_pad("Port Name", 25).
str_pad("Priority", 10).str_pad("State", 15).str_pad("Cost", 10));
}
foreach ($vlan_data as $vlan_port_id => $vlan_port) {
$ifIndex = $vlan_port['dot1dBasePortIfIndex'];
$discovery_ports_vlans[$ifIndex][$vlan_id] = array('vlan' => $vlan_id,
// FIXME. move STP to separate table
'baseport' => $vlan_port_id,
'priority' => $vlan_port['dot1dStpPortPriority'],
'state' => $vlan_port['dot1dStpPortState'],
'cost' => $vlan_port['dot1dStpPortPathCost']);
}
} else {
unset($module_stats[$vlan_id]);
/* End per port vlans */
}
/* End per port vlans */
}
}
echo(PHP_EOL);

View File

@ -1,12 +1,12 @@
<?php
/*
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) Adam Armstrong
*
*/

View File

@ -4,9 +4,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
@ -27,72 +27,61 @@ print_debug_vars($vlan_oids);
$vtp_domain_index = '1'; // Yep, always use domain index 1
foreach ($vlan_oids as $vlan_num => $vlan)
{
// Skip not exist vlans
if ($vlan['vlanRowStatus'] != 'active') { continue; }
foreach ($vlan_oids as $vlan_num => $vlan) {
// Skip not exist vlans
if ($vlan['vlanRowStatus'] != 'active') {
continue;
}
$vlan_array = [
'ifIndex' => $vlan['vlanPortNumber'],
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => strlen($vlan['vlanName']) ? $vlan['vlanName'] : "Vlan $vlan_num",
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$vlan_array = [
'ifIndex' => $vlan['vlanPortNumber'],
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => strlen($vlan['vlanName']) ? $vlan['vlanName'] : "Vlan $vlan_num",
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
}
$ports_vlans_oids = snmpwalk_cache_oid($device, 'portMode', [], 'DCN-MIB');
$oids = [];
foreach ($ports_vlans_oids as $ifIndex => $entry)
{
if ($entry['portMode'] == 'trunk')
{
$oids[] = 'portTrunkAllowedvlan';
}
elseif ($entry['portMode'] == 'hybrid')
{
$oids[] = 'portHybridTaggedAllowedvlan';
}
$oids = [];
foreach ($ports_vlans_oids as $ifIndex => $entry) {
if ($entry['portMode'] == 'trunk') {
$oids[] = 'portTrunkAllowedvlan';
} elseif ($entry['portMode'] == 'hybrid') {
$oids[] = 'portHybridTaggedAllowedvlan';
}
}
foreach (array_unique($oids) as $oid)
{
$ports_vlans_oids = snmpwalk_cache_oid($device, $oid, $ports_vlans_oids, 'DCN-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
foreach (array_unique($oids) as $oid) {
$ports_vlans_oids = snmpwalk_cache_oid($device, $oid, $ports_vlans_oids, 'DCN-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
}
print_debug_vars($ports_vlans_oids);
foreach ($ports_vlans_oids as $ifIndex => $entry)
{
foreach ($ports_vlans_oids as $ifIndex => $entry) {
if ($entry['portMode'] == 'trunk')
{
$binary = hex2binmap($entry['portTrunkAllowedvlan']);
}
elseif ($entry['portMode'] == 'hybrid')
{
$binary = hex2binmap($entry['portHybridTaggedAllowedvlan']);
} else {
continue;
}
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++)
{
if ($binary[$i] && $i > 0)
{
$vlan_num = $i;
//print_debug("ifIndex = $ifIndex, \$i = $i, mode {$entry['portMode']}");
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num]))
{
$discovery_ports_vlans[$ifIndex][$vlan_num] = array('vlan' => $vlan_num);
}
if ($entry['portMode'] == 'trunk') {
$binary = hex2binmap($entry['portTrunkAllowedvlan']);
} elseif ($entry['portMode'] == 'hybrid') {
$binary = hex2binmap($entry['portHybridTaggedAllowedvlan']);
} else {
continue;
}
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i] && $i > 0) {
$vlan_num = $i;
//print_debug("ifIndex = $ifIndex, \$i = $i, mode {$entry['portMode']}");
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num])) {
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
}
}
}
}
}

View File

@ -4,9 +4,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*
*/
@ -23,19 +23,20 @@ Es2952-MIB::vlanAdminStatus.2 = INTEGER: disable(2)
Es2952-MIB::vlanAdminStatus.500 = INTEGER: enable(1)
*/
$oids = [];
$oids = [];
$vlan_oids = [];
foreach (snmpwalk_cache_oid($device, 'vlanAdminStatus', [], 'Es2952-MIB') as $vlan_num => $vlan)
{
// Filter only enabled Vlans
if ($vlan['vlanAdminStatus'] != 'enable') { continue; }
foreach (snmpwalk_cache_oid($device, 'vlanAdminStatus', [], 'Es2952-MIB') as $vlan_num => $vlan) {
// Filter only enabled Vlans
if ($vlan['vlanAdminStatus'] != 'enable') {
continue;
}
$vlan_oids[$vlan_num] = $vlan;
$vlan_oids[$vlan_num] = $vlan;
// Additional Oids for multiget:
$oids[] = 'vlanName.' . $vlan_num;
$oids[] = 'vlanTaggedPorts.' . $vlan_num;
// Additional Oids for multiget:
$oids[] = 'vlanName.' . $vlan_num;
$oids[] = 'vlanTaggedPorts.' . $vlan_num;
}
$vlan_oids = snmp_get_multi_oid($device, $oids, $vlan_oids, 'Es2952-MIB', NULL, OBS_SNMP_ALL_HEX);
@ -43,20 +44,21 @@ print_debug_vars($vlan_oids);
$vtp_domain_index = '1'; // Yep, always use domain index 1
foreach ($vlan_oids as $vlan_num => $vlan)
{
// Skip not exist vlans
if ($vlan['vlanAdminStatus'] != 'enable') { continue; }
foreach ($vlan_oids as $vlan_num => $vlan) {
// Skip not exist vlans
if ($vlan['vlanAdminStatus'] != 'enable') {
continue;
}
$vlan_array = array(//'ifIndex' => $vlan[''], // ??
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => strlen($vlan['vlanName']) ? snmp_hexstring($vlan['vlanName']) : "Vlan $vlan_num",
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational');
$vlan_array = [//'ifIndex' => $vlan[''], // ??
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => strlen($vlan['vlanName']) ? snmp_hexstring($vlan['vlanName']) : "Vlan $vlan_num",
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'];
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
}

View File

@ -5,9 +5,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
@ -26,72 +26,71 @@ $vtp_domain_index = '1'; // Yep, always use domain index 1
//EXTREME-VLAN-MIB::extremeVlanIfAdminStatus.1000008 = INTEGER: true(1)
//EXTREME-VLAN-MIB::extremeVlanIfAdminStatus.1000011 = INTEGER: false(2)
$vlan_oids = snmpwalk_cache_oid($device, 'extremeVlanIfDescr', array(), 'EXTREME-VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'extremeVlanIfDescr', [], 'EXTREME-VLAN-MIB');
if (!snmp_status())
{
// New Extreme SLX devices have very limited VLANs information
if (!snmp_status()) {
// New Extreme SLX devices have very limited VLANs information
// EXTREME-VLAN-MIB::extremeStatsPortIfIndex.201334784."99" = INTEGER: 201334784
// EXTREME-VLAN-MIB::extremeStatsVlanNameIndex.201334784."99" = STRING: 99
$vlan_stats = snmpwalk_cache_twopart_oid($device, 'extremeStatsVlanNameIndex', array(), 'EXTREME-VLAN-MIB');
if (!snmp_status())
{
return;
}
foreach ($vlan_stats as $ifIndex => $tmp)
{
foreach ($tmp as $vlan_num => $vlan)
{
// I'm not sure if this string is always vlan number string
if (!is_numeric($vlan_num)) { continue; }
// Now find port from ifDescr
// IF-MIB::ifDescr.201334784 = STRING: Ethernet 0/1
// IF-MIB::ifDescr.1207959651 = STRING: Ve 99
$vlan_name = 'Ve '.$vlan_num;
$vlan_index = dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND `ifDescr` = ? AND `deleted` = ? LIMIT 1", array($device['device_id'], $vlan_name, 0));
$vlan_array = array('ifIndex' => $vlan_index,
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan_name,
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational');
// Device Vlans
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
// Port Vlans
$discovery_ports_vlans[$ifIndex][$vlan_num] = array('vlan' => $vlan_num);
// EXTREME-VLAN-MIB::extremeStatsPortIfIndex.201334784."99" = INTEGER: 201334784
// EXTREME-VLAN-MIB::extremeStatsVlanNameIndex.201334784."99" = STRING: 99
$vlan_stats = snmpwalk_cache_twopart_oid($device, 'extremeStatsVlanNameIndex', [], 'EXTREME-VLAN-MIB');
if (!snmp_status()) {
return;
}
}
// End new SLX devices
return;
foreach ($vlan_stats as $ifIndex => $tmp) {
foreach ($tmp as $vlan_num => $vlan) {
// I'm not sure if this string is always vlan number string
if (!is_numeric($vlan_num)) {
continue;
}
// Now find port from ifDescr
// IF-MIB::ifDescr.201334784 = STRING: Ethernet 0/1
// IF-MIB::ifDescr.1207959651 = STRING: Ve 99
$vlan_name = 'Ve ' . $vlan_num;
$vlan_index = dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND `ifDescr` = ? AND `deleted` = ? LIMIT 1", [$device['device_id'], $vlan_name, 0]);
$vlan_array = ['ifIndex' => $vlan_index,
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan_name,
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'];
// Device Vlans
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
// Port Vlans
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
}
}
// End new SLX devices
return;
}
$vlan_oids = snmpwalk_cache_oid($device, 'extremeVlanIfVlanId', $vlan_oids, 'EXTREME-VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'extremeVlanIfStatus', $vlan_oids, 'EXTREME-VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'extremeVlanIfType', $vlan_oids, 'EXTREME-VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'extremeVlanIfVlanId', $vlan_oids, 'EXTREME-VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'extremeVlanIfStatus', $vlan_oids, 'EXTREME-VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'extremeVlanIfType', $vlan_oids, 'EXTREME-VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'extremeVlanIfAdminStatus', $vlan_oids, 'EXTREME-VLAN-MIB');
print_debug_vars($vlan_oids);
foreach ($vlan_oids as $index => $vlan)
{
// Skip not exist vlans
if (in_array($vlan['extremeVlanIfStatus'], array('notInService', 'notReady', 'destroy'))) { continue; }
foreach ($vlan_oids as $index => $vlan) {
// Skip not exist vlans
if (in_array($vlan['extremeVlanIfStatus'], ['notInService', 'notReady', 'destroy'])) {
continue;
}
$vlan_num = $vlan['extremeVlanIfVlanId'];
$vlan_array = array('ifIndex' => $index,
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['extremeVlanIfDescr'],
//'vlan_mtu' => $vlan[''],
'vlan_type' => $vlan['extremeVlanIfType'],
'vlan_status' => $vlan['extremeVlanIfAdminStatus']);
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
$vlan_num = $vlan['extremeVlanIfVlanId'];
$vlan_array = ['ifIndex' => $index,
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['extremeVlanIfDescr'],
//'vlan_mtu' => $vlan[''],
'vlan_type' => $vlan['extremeVlanIfType'],
'vlan_status' => $vlan['extremeVlanIfAdminStatus']];
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
}
@ -101,33 +100,28 @@ foreach ($vlan_oids as $index => $vlan)
//00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
//EXTREME-VLAN-MIB::extremeVlanOpaqueTaggedPorts.1000056.3 = Hex-STRING: 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00
//00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
$ports_vlans_oids = snmpwalk_cache_twopart_oid($device, 'extremeVlanOpaqueTaggedPorts', array(), 'EXTREME-VLAN-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
$ports_vlans_oids = snmpwalk_cache_twopart_oid($device, 'extremeVlanOpaqueTaggedPorts', [], 'EXTREME-VLAN-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
print_debug_vars($ports_vlans_oids);
foreach ($ports_vlans_oids as $index => $entry)
{
foreach ($ports_vlans_oids as $index => $entry) {
$vlan_num = $vlan_oids[$index]['extremeVlanIfVlanId'];
foreach ($entry as $slot => $vlan)
{
$binary = hex2binmap($vlan['extremeVlanOpaqueTaggedPorts']);
$vlan_num = $vlan_oids[$index]['extremeVlanIfVlanId'];
foreach ($entry as $slot => $vlan) {
$binary = hex2binmap($vlan['extremeVlanOpaqueTaggedPorts']);
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++)
{
if ($binary[$i] && $i > 0)
{
$port_map = $slot.':'.($i + 1);
$ifIndex = dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND (`ifDescr` LIKE ? OR `ifName` = ?) AND `deleted` = ? LIMIT 1", array($device['device_id'], '% '.$port_map, $port_map, 0));
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i] && $i > 0) {
$port_map = $slot . ':' . ($i + 1);
$ifIndex = dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND (`ifDescr` LIKE ? OR `ifName` = ?) AND `deleted` = ? LIMIT 1", [$device['device_id'], '% ' . $port_map, $port_map, 0]);
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num]))
{
$discovery_ports_vlans[$ifIndex][$vlan_num] = array('vlan' => $vlan_num);
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num])) {
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
}
}
}
}
}
}
}
// EOF

View File

@ -0,0 +1,15 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
include __DIR__ . '/radlan-vlan-mib.inc.php';
// EOF

View File

@ -5,120 +5,110 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
$vlan_oids = snmpwalk_cache_oid($device, 'hwL2VlanDescr', array(), 'HUAWEI-L2VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'hwL2VlanDescr', [], 'HUAWEI-L2VLAN-MIB');
if (!snmp_status())
{
return;
if (!snmp_status()) {
return;
}
$vlan_oids = snmpwalk_cache_oid($device, 'hwL2VlanIfIndex', $vlan_oids, 'HUAWEI-L2VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'hwL2VlanRowStatus', $vlan_oids, 'HUAWEI-L2VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'hwL2VlanType', $vlan_oids, 'HUAWEI-L2VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'hwL2VlanIfIndex', $vlan_oids, 'HUAWEI-L2VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'hwL2VlanRowStatus', $vlan_oids, 'HUAWEI-L2VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'hwL2VlanType', $vlan_oids, 'HUAWEI-L2VLAN-MIB');
$vlan_oids = snmpwalk_cache_oid($device, 'hwL2VlanCreateStatus', $vlan_oids, 'HUAWEI-L2VLAN-MIB');
//$vlan_oids = snmpwalk_cache_oid($device, 'hwL2VlanPortList', $vlan_oids, 'HUAWEI-L2VLAN-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
print_debug_vars($vlan_oids);
$vtp_domain_index = '1'; // Yep, always use domain index 1
foreach ($vlan_oids as $vlan_num => $vlan)
{
// Skip not exist vlans
if (in_array($vlan['hwL2VlanRowStatus'], array('notInService', 'notReady', 'destroy'))) { continue; }
foreach ($vlan_oids as $vlan_num => $vlan) {
// Skip not exist vlans
if (in_array($vlan['hwL2VlanRowStatus'], ['notInService', 'notReady', 'destroy'])) {
continue;
}
$vlan_array = array('ifIndex' => $vlan['hwL2VlanIfIndex'],
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['hwL2VlanDescr'],
//'vlan_mtu' => $vlan[''],
'vlan_type' => $vlan['hwL2VlanType'],
'vlan_status' => $vlan['hwL2VlanCreateStatus']);
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
$vlan_array = ['ifIndex' => $vlan['hwL2VlanIfIndex'],
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['hwL2VlanDescr'],
//'vlan_mtu' => $vlan[''],
'vlan_type' => $vlan['hwL2VlanType'],
'vlan_status' => $vlan['hwL2VlanCreateStatus']];
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
}
if (!is_device_mib($device, 'HUAWEI-L2IF-MIB'))
{
// Skip ports vlans if this mib disabled
return;
if (!is_device_mib($device, 'HUAWEI-L2IF-MIB')) {
// Skip ports vlans if this mib disabled
return;
}
$vlan_max = max(array_keys($discovery_vlans[$vtp_domain_index])); // Detect maximum vlan number on device
// port index map
$ports_vlans_indexes = snmpwalk_cache_oid($device, 'hwL2IfPortIfIndex', array(), 'HUAWEI-L2IF-MIB');
$ports_vlans_indexes = snmpwalk_cache_oid($device, 'hwL2IfPortIfIndex', [], 'HUAWEI-L2IF-MIB');
// Normal Trunk ports
$ports_vlans_oids = snmpwalk_cache_oid($device, 'hwL2IfTrunkAllowPassVlanListLow', array(), 'HUAWEI-L2IF-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
if ($vlan_max > 2047)
{
$ports_vlans_oids = snmpwalk_cache_oid($device, 'hwL2IfTrunkAllowPassVlanListHigh', $ports_vlans_oids, 'HUAWEI-L2IF-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
$ports_vlans_oids = snmpwalk_cache_oid($device, 'hwL2IfTrunkAllowPassVlanListLow', [], 'HUAWEI-L2IF-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
if ($vlan_max > 2047) {
$ports_vlans_oids = snmpwalk_cache_oid($device, 'hwL2IfTrunkAllowPassVlanListHigh', $ports_vlans_oids, 'HUAWEI-L2IF-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
}
// Hybrid tagged ports
$ports_vlans_oids = snmpwalk_cache_oid($device, 'hwL2IfHybridTaggedVlanListLow', $ports_vlans_oids, 'HUAWEI-L2IF-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
if ($vlan_max > 2047)
{
$ports_vlans_oids = snmpwalk_cache_oid($device, 'hwL2IfHybridTaggedVlanListHigh', $ports_vlans_oids, 'HUAWEI-L2IF-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
if ($vlan_max > 2047) {
$ports_vlans_oids = snmpwalk_cache_oid($device, 'hwL2IfHybridTaggedVlanListHigh', $ports_vlans_oids, 'HUAWEI-L2IF-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
}
print_debug_vars($ports_vlans_indexes);
print_debug_vars($ports_vlans_oids);
foreach ($ports_vlans_oids as $index => $vlan)
{
if (!isset($ports_vlans_indexes[$index])) { continue; } // Skip unknown
$ifIndex = $ports_vlans_indexes[$index]['hwL2IfPortIfIndex'];
foreach ($ports_vlans_oids as $index => $vlan) {
if (!isset($ports_vlans_indexes[$index])) {
continue;
} // Skip unknown
$ifIndex = $ports_vlans_indexes[$index]['hwL2IfPortIfIndex'];
foreach (array('TrunkAllowPass', 'HybridTagged') as $oid)
{
$oid_name = 'hwL2If' . $oid . 'VlanListLow';
// 0-2047 VLAN list. Value 0 is reserved
$binary = hex2binmap($vlan[$oid_name]);
foreach (['TrunkAllowPass', 'HybridTagged'] as $oid) {
$oid_name = 'hwL2If' . $oid . 'VlanListLow';
// 0-2047 VLAN list. Value 0 is reserved
$binary = hex2binmap($vlan[$oid_name]);
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++)
{
if ($binary[$i] && $i > 0)
{
$vlan_num = $i;
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i] && $i > 0) {
$vlan_num = $i;
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num]))
{
$discovery_ports_vlans[$ifIndex][$vlan_num] = array('vlan' => $vlan_num);
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num])) {
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
}
}
}
}
}
$oid_name = 'hwL2If' . $oid . 'VlanListHigh';
// 2048-4095 VLAN list. Value 4095 is reserved
if (isset($vlan[$oid_name]))
{
$binary = hex2binmap($vlan[$oid_name]);
$oid_name = 'hwL2If' . $oid . 'VlanListHigh';
// 2048-4095 VLAN list. Value 4095 is reserved
if (isset($vlan[$oid_name])) {
$binary = hex2binmap($vlan[$oid_name]);
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++)
{
if ($binary[$i] && $i < 2047)
{
$vlan_num = 2048 + $i;
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i] && $i < 2047) {
$vlan_num = 2048 + $i;
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num]))
{
$discovery_ports_vlans[$ifIndex][$vlan_num] = array('vlan' => $vlan_num);
}
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num])) {
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
}
}
}
}
}
}
}
}
}

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
@ -14,10 +14,10 @@
$dot1q_ports = snmpwalk_cache_twopart_oid($device, 'ieee8021QBridgeVlanStaticName', [], 'IEEE8021-Q-BRIDGE-MIB');
//$dot1q_ports = snmpwalk_cache_twopart_oid($device, 'ieee8021QBridgeVlanStaticTable', [], 'IEEE8021-Q-BRIDGE-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
if (!snmp_status()) {
return;
return;
}
$dot1q_ports = snmpwalk_cache_twopart_oid($device, 'ieee8021QBridgeVlanStaticRowStatus', $dot1q_ports, 'IEEE8021-Q-BRIDGE-MIB');
$dot1q_ports = snmpwalk_cache_twopart_oid($device, 'ieee8021QBridgeVlanStaticRowStatus', $dot1q_ports, 'IEEE8021-Q-BRIDGE-MIB');
$dot1q_ports = snmpwalk_cache_twopart_oid($device, 'ieee8021QBridgeVlanStaticEgressPorts', $dot1q_ports, 'IEEE8021-Q-BRIDGE-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
/* Base port ifIndex association */
@ -42,74 +42,74 @@ if ($use_baseports)
/* End base port ifIndex association */
foreach ($dot1q_ports as $domain_index => $vlans) {
$binary_debug = []; // DEBUG
foreach ($vlans as $vlan_num => $vlan) {
$vlan['ifIndex'] = $vlan_num;
$binary_debug = []; // DEBUG
foreach ($vlans as $vlan_num => $vlan) {
$vlan['ifIndex'] = $vlan_num;
$vlan_array = [
'ifIndex' => $vlan['ifIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['ieee8021QBridgeVlanStaticName'],
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
/* End vlans discovery */
/* Per port vlans */
// Convert hex to binary map
$binary = hex2binmap($vlan['ieee8021QBridgeVlanStaticEgressPorts']);
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i]) {
//$ifIndex = $i + $vlan_ifindex_min; // This is incorrect ifIndex association!
if ($use_baseports) {
// Skip all unknown indexes (OBS-2958)
if (!isset($dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'])) {
continue;
}
$ifIndex = $dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'];
} else {
$ifIndex = $i;
}
$binary_debug[$vlan_num][$i] = $ifIndex; // DEBUG
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
// FIXME. move STP to separate table
//'baseport' => $vlan_port_id,
//'priority' => $vlan_port['dot1dStpPortPriority'],
//'state' => $vlan_port['dot1dStpPortState'],
//'cost' => $vlan_port['dot1dStpPortPathCost']
$vlan_array = [
'ifIndex' => $vlan['ifIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['ieee8021QBridgeVlanStaticName'],
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
}
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
/* End vlans discovery */
/* Per port vlans */
// Convert hex to binary map
$binary = hex2binmap($vlan['ieee8021QBridgeVlanStaticEgressPorts']);
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i]) {
//$ifIndex = $i + $vlan_ifindex_min; // This is incorrect ifIndex association!
if ($use_baseports) {
// Skip all unknown indexes (OBS-2958)
if (!isset($dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'])) {
continue;
}
$ifIndex = $dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'];
} else {
$ifIndex = $i;
}
$binary_debug[$vlan_num][$i] = $ifIndex; // DEBUG
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
// FIXME. move STP to separate table
//'baseport' => $vlan_port_id,
//'priority' => $vlan_port['dot1dStpPortPriority'],
//'state' => $vlan_port['dot1dStpPortState'],
//'cost' => $vlan_port['dot1dStpPortPathCost']
];
}
}
}
}
print_debug_vars($binary_debug); // DEBUG
print_debug_vars($binary_debug); // DEBUG
}
// As last point validate access ports that vlan is added (some devices not report it in ieee8021QBridgeVlanStaticTable)
$dot1q_ports = snmpwalk_cache_twopart_oid($device, 'ieee8021QBridgePvid', [], 'IEEE8021-Q-BRIDGE-MIB');
foreach ($dot1q_ports as $domain_index => $vlans) {
foreach ($vlans as $entry) {
$vlan_num = $entry['ieee8021QBridgePvid'];
if (!isset($discovery_vlans[$domain_index][$vlan_num])) {
$vlan_array = [
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => 'VLAN ' . $vlan_num,
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
foreach ($vlans as $entry) {
$vlan_num = $entry['ieee8021QBridgePvid'];
if (!isset($discovery_vlans[$domain_index][$vlan_num])) {
$vlan_array = [
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => 'VLAN ' . $vlan_num,
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
}
}
}
}
echo(PHP_EOL);

View File

@ -6,38 +6,38 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
if (is_device_mib($device, 'CISCO-VTP-MIB')) {
// Q-BRIDGE-MIB is default mib, need excludes Cisco
return;
// Q-BRIDGE-MIB is default mib, need excludes Cisco
return;
}
$domain_index = '1';
if (safe_count($discovery_vlans[$domain_index]) &&
is_device_mib($device, [ 'CISCOSB-vlan-MIB', 'RADLAN-vlan-MIB', 'Dell-vlan-MIB',
is_device_mib($device, [ 'CISCOSB-vlan-MIB', 'HPE-vlan-MIB', 'RADLAN-vlan-MIB', 'Dell-vlan-MIB',
'DLINK-3100-vlan-MIB', 'EDGECORE-vlan-MIB', 'NETGEAR-RADLAN-vlan-MIB',
'A3COM-HUAWEI-LswVLAN-MIB', 'IEEE8021-Q-BRIDGE-MIB' ])) {
// Already discovered by RADLAN based vlans or IEEE8021-Q-BRIDGE-MIB
return;
// Already discovered by RADLAN based vlans or IEEE8021-Q-BRIDGE-MIB
return;
}
// Simplify dot1qVlanStaticTable walk
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qVlanStaticName', [], 'Q-BRIDGE-MIB');
//$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qVlanStaticTable', array(), 'Q-BRIDGE-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
if (!snmp_status()) {
return;
return;
}
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qVlanStaticRowStatus', $dot1q_ports, 'Q-BRIDGE-MIB');
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qVlanStaticRowStatus', $dot1q_ports, 'Q-BRIDGE-MIB');
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qVlanStaticEgressPorts', $dot1q_ports, 'Q-BRIDGE-MIB', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
if (is_device_mib($device, 'JUNIPER-VLAN-MIB')) { // Unsure if other Juniper platforms "affected"
// Fetch Juniper VLAN table for correct tag
$dot1q_ports = snmpwalk_cache_oid($device, 'jnxExVlanTable', $dot1q_ports, 'JUNIPER-VLAN-MIB');
// Fetch Juniper VLAN table for correct tag
$dot1q_ports = snmpwalk_cache_oid($device, 'jnxExVlanTable', $dot1q_ports, 'JUNIPER-VLAN-MIB');
}
/* Base port ifIndex association */
@ -63,111 +63,114 @@ if ($use_baseports)
$binary_debug = []; // DEBUG
foreach ($dot1q_ports as $vlan_num => $vlan) {
$vlan['ifIndex'] = $vlan_num;
// FTOS vlan fix
if ($device['os'] === 'ftos') {
// Q-BRIDGE-MIB::dot1qVlanStaticEgressPorts.1107787777, where 1107787777 is ifIndex for Vlan interface
//IF-MIB::ifDescr.1107787777 = STRING: Vlan 1
//IF-MIB::ifDescr.1107787998 = STRING: Vlan 222
$vlan_num = rewrite_ftos_vlanid($device, $vlan_num);
if (!is_numeric($vlan_num)) { continue; } // Skip unknown
}
$vlan['ifIndex'] = $vlan_num;
// JunOS Vlan fix
if (isset($vlan['jnxExVlanTag'])) {
$vlan_num = $vlan['jnxExVlanTag'];
}
$vlan_array = [
'ifIndex' => $vlan['ifIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['dot1qVlanStaticName'],
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
/* End vlans discovery */
/* Per port vlans */
// Convert hex to binary map
$binary = hex2binmap($vlan['dot1qVlanStaticEgressPorts']);
if ($device['os'] === 'ftos') { // FTOS specific
// FTOS devices use harder way for detect VLANs and associate ports
// See: https://www.force10networks.com/CSPortal20/TechTips/0041B_displaying_vlan_ports.aspx
// Port associations based on slot/port, each 12 hex pair (96 bin) is slot
foreach (str_split($binary, 96) as $slot => $binary_map) {
$length = strlen($binary_map);
for ($i = 0; $i < $length; $i++) {
if ($binary_map[$i]) {
// Now find slot/port from ifDescr
$port_map = '% '.$slot.'/'.($i + 1);
$ifIndex = dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND `ifDescr` LIKE ? AND `deleted` = ? LIMIT 1", [ $device['device_id'], $port_map, 0 ]);
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
// FIXME. move STP to separate table
//'baseport' => $vlan_port_id,
//'priority' => $vlan_port['dot1dStpPortPriority'],
//'state' => $vlan_port['dot1dStpPortState'],
//'cost' => $vlan_port['dot1dStpPortPathCost']
];
if ($device['os'] === 'ftos') {
// FTOS vlan fix
// Q-BRIDGE-MIB::dot1qVlanStaticEgressPorts.1107787777, where 1107787777 is ifIndex for Vlan interface
//IF-MIB::ifDescr.1107787777 = STRING: Vlan 1
//IF-MIB::ifDescr.1107787998 = STRING: Vlan 222
$vlan_num = rewrite_ftos_vlanid($device, $vlan_num);
if (!is_numeric($vlan_num)) {
continue; // Skip unknown
}
}
} elseif (isset($vlan['jnxExVlanTag'])) {
// JunOS Vlan fix
$vlan_num = $vlan['jnxExVlanTag'];
}
} else {
// All others
$vlan_array = [
'ifIndex' => $vlan['ifIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['dot1qVlanStaticName'],
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
/* End vlans discovery */
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i]) {
//$ifIndex = $i + $vlan_ifindex_min; // This is incorrect ifIndex association!
if ($use_baseports) {
// Skip all unknown indexes (OBS-2958)
if (!isset($dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'])) { continue; }
$ifIndex = $dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'];
} else {
$ifIndex = $i;
/* Per port vlans */
// Convert hex to binary map
$binary = hex2binmap($vlan['dot1qVlanStaticEgressPorts']);
if ($device['os'] === 'ftos') {
// FTOS devices use harder way for detect VLANs and associate ports
// See: https://www.force10networks.com/CSPortal20/TechTips/0041B_displaying_vlan_ports.aspx
// Port associations based on slot/port, each 12 hex pair (96 bin) is slot
foreach (str_split($binary, 96) as $slot => $binary_map) {
$length = strlen($binary_map);
for ($i = 0; $i < $length; $i++) {
if ($binary_map[$i]) {
// Now find slot/port from ifDescr
$port_map = '% ' . $slot . '/' . ($i + 1);
$ifIndex = dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND `ifDescr` LIKE ? AND `deleted` = ? LIMIT 1", [$device['device_id'], $port_map, 0]);
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
// FIXME. move STP to separate table
//'baseport' => $vlan_port_id,
//'priority' => $vlan_port['dot1dStpPortPriority'],
//'state' => $vlan_port['dot1dStpPortState'],
//'cost' => $vlan_port['dot1dStpPortPathCost']
];
}
}
}
} else {
// All others
// Assign binary vlans map to ports
$length = strlen($binary);
for ($i = 0; $i < $length; $i++) {
if ($binary[$i]) {
//$ifIndex = $i + $vlan_ifindex_min; // This is incorrect ifIndex association!
if ($use_baseports) {
// Skip all unknown indexes (OBS-2958)
if (!isset($dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'])) {
continue;
}
$ifIndex = $dot1d_baseports[$i + 1]['dot1dBasePortIfIndex'];
} else {
$ifIndex = $i;
}
$binary_debug[$vlan_num][$i] = $ifIndex; // DEBUG
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
// FIXME. move STP to separate table
//'baseport' => $vlan_port_id,
//'priority' => $vlan_port['dot1dStpPortPriority'],
//'state' => $vlan_port['dot1dStpPortState'],
//'cost' => $vlan_port['dot1dStpPortPathCost']
];
}
}
$binary_debug[$vlan_num][$i] = $ifIndex; // DEBUG
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
// FIXME. move STP to separate table
//'baseport' => $vlan_port_id,
//'priority' => $vlan_port['dot1dStpPortPriority'],
//'state' => $vlan_port['dot1dStpPortState'],
//'cost' => $vlan_port['dot1dStpPortPathCost']
];
}
}
}
}
print_debug_vars($binary_debug); // DEBUG
// As last point validate access ports that vlan is added (some devices not report it in dot1qVlanStaticTable)
$dot1q_ports = snmpwalk_cache_oid($device, 'dot1qPvid', [], 'Q-BRIDGE-MIB');
foreach ($dot1q_ports as $entry) {
$vlan_num = $entry['dot1qPvid'];
if (!isset($discovery_vlans[$domain_index][$vlan_num])) {
$vlan_array = [
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => 'VLAN '.$vlan_num,
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
}
$vlan_num = $entry['dot1qPvid'];
if (!isset($discovery_vlans[$domain_index][$vlan_num])) {
$vlan_array = [
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => 'VLAN ' . $vlan_num,
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
}
}
echo(PHP_EOL);

View File

@ -1,12 +1,12 @@
<?php
/*
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
@ -21,115 +21,147 @@
$vlan_list = snmpwalk_cache_oid($device, 'rldot1qVlanStaticName', [], $mib);
print_debug_vars($vlan_list);
if (!snmp_status()) { return; }
if (!snmp_status()) {
return;
}
$domain_index = '1';
// Vlan 1 always exist on device, but not always discovered in snmp :/
$discovery_vlans[$domain_index]['1'] = [
//'ifIndex' => $entry['ifIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => '1',
'vlan_name' => 'Vlan 1',
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$sql = 'SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` >= 100000 AND `ifIndex` < 200000 AND `ifType` = ? AND `deleted` = ?';
foreach (dbFetchRows($sql, [ $device['device_id'], 'propVirtual', '0' ]) as $entry) {
if (is_intnum($entry['ifDescr'])) {
$vlan_num = $entry['ifDescr'];
} elseif (str_istarts($entry['ifName'], 'Vlan')) {
$vlan_num = str_ireplace([ 'Vlan', ' ' ], '', $entry['ifName']);
} else {
print_debug("Vlan port not found:");
print_debug_vars($entry);
continue;
}
if (isset($vlan_list[$vlan_num])) {
$vlan_list[$vlan_num]['ifIndex'] = $entry['ifIndex'];
$vlan_list[$vlan_num]['ifOperStatus'] = $entry['ifOperStatus'];
} elseif ($vlan_num == 1) {
$discovery_vlans[$domain_index]['1']['ifIndex'] = $entry['ifIndex'];
}
}
$vlan_max = 1;
foreach ($vlan_list as $vlan_num => $entry) {
if ($vlan_num > $vlan_max) {
// Store max vlan number, for fetch only relevant vlan data
$vlan_max = (int) $vlan_num;
}
$vlan_array = [
'ifIndex' => $entry['ifIndex'] ?: [ 'NULL' ],
//'ifIndex' => $entry['ifIndex'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $entry['dot1qVlanStaticName'] ?: "Vlan $vlan_num",
'vlan_vlan' => '1',
'vlan_name' => 'Vlan 1',
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
];
$sql = 'SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` >= 100000 AND `ifIndex` < 200000 AND `ifType` = ? AND `deleted` = ?';
foreach (dbFetchRows($sql, [$device['device_id'], 'propVirtual', '0']) as $entry) {
if (is_intnum($entry['ifDescr'])) {
$vlan_num = $entry['ifDescr'];
} elseif (str_istarts($entry['ifName'], 'Vlan')) {
$vlan_num = str_ireplace(['Vlan', ' '], '', $entry['ifName']);
} else {
print_debug("Vlan port not found:");
print_debug_vars($entry);
continue;
}
if (isset($vlan_list[$vlan_num])) {
$vlan_list[$vlan_num]['ifIndex'] = $entry['ifIndex'];
$vlan_list[$vlan_num]['ifOperStatus'] = $entry['ifOperStatus'];
} elseif ($vlan_num == 1) {
$discovery_vlans[$domain_index]['1']['ifIndex'] = $entry['ifIndex'];
}
}
$vlan_max = 1;
foreach ($vlan_list as $vlan_num => $entry) {
if ($vlan_num > $vlan_max) {
// Store max vlan number, for fetch only relevant vlan data
$vlan_max = (int)$vlan_num;
}
$vlan_array = [
'ifIndex' => $entry['ifIndex'] ?: ['NULL'],
'vlan_domain' => $domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $entry['rldot1qVlanStaticName'] ?: "Vlan $vlan_num",
//'vlan_mtu' => '',
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$domain_index][$vlan_num] = $vlan_array;
}
// keep max vlan for polling
set_entity_attrib('device', $device, 'radlan_vlan_max', $vlan_max);
/* End vlans discovery */
$vlan_ports = snmpwalk_cache_oid($device, 'vlanPortModeState', [], $mib);
if (!snmp_status()) { return; }
if (!snmp_status()) {
return;
}
$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticEgressList1to1024', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticEgressList1to1024', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
$vlan_ports = snmpwalk_cache_oid($device, 'vlanTrunkModeList1to1024', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticUntaggedEgressList1to1024', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticForbiddenList1to1024', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
if ($vlan_max > 1024) {
$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticEgressList1025to2048', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticUntaggedEgressList1025to2048', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticForbiddenList1025to2048', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticEgressList1025to2048', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
$vlan_ports = snmpwalk_cache_oid($device, 'vlanTrunkModeList1025to2048', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticUntaggedEgressList1025to2048', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticForbiddenList1025to2048', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
}
if ($vlan_max > 2048) {
$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticEgressList2049to3072', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticUntaggedEgressList2049to3072', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticForbiddenList2049to3072', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticEgressList2049to3072', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
$vlan_ports = snmpwalk_cache_oid($device, 'vlanTrunkModeList2049to3072', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticUntaggedEgressList2049to3072', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticForbiddenList2049to3072', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
}
if ($vlan_max > 3072) {
$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticEgressList3073to4094', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticUntaggedEgressList3073to4094', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticForbiddenList3073to4094', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticEgressList3073to4094', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
$vlan_ports = snmpwalk_cache_oid($device, 'vlanTrunkModeList3073to4094', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticUntaggedEgressList3073to4094', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
//$vlan_ports = snmpwalk_cache_oid($device, 'rldot1qPortVlanStaticForbiddenList3073to4094', $vlan_ports, $mib, NULL, OBS_SNMP_ALL_HEX);
}
print_debug_vars($vlan_ports);
$vlan_oids = [
$vlan_access_oids = [
1 => 'rldot1qPortVlanStaticEgressList1to1024',
1025 => 'rldot1qPortVlanStaticEgressList1025to2048',
2049 => 'rldot1qPortVlanStaticEgressList2049to3072',
3073 => 'rldot1qPortVlanStaticEgressList3073to4094',
];
$vlan_trunk_oids = [
1 => 'vlanTrunkModeList1to1024',
1025 => 'vlanTrunkModeList1025to2048',
2049 => 'vlanTrunkModeList2049to3072',
3073 => 'vlanTrunkModeList3073to4094',
];
foreach ($vlan_ports as $ifIndex => $entry) {
foreach ($vlan_oids as $vlan_start => $oid) {
if (isset($entry[$oid]) && preg_match('/[1-9a-f]/i', $entry[$oid])) {
// not default
$binmap = hex2binmap($entry[$oid]);
$vlan_len = strlen($binmap);
$vlan_end = $vlan_start + $vlan_len - 1;
$vlan_count = substr_count($binmap, '1');
for ($i = 0; $i < $vlan_len; $i++) {
$vlan_num = $vlan_start + $i;
if ($binmap[$i]) {
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
];
// decrease significant vlans and break if all found
$vlan_count--;
if ($vlan_count === 0) {
switch ($entry['vlanPortModeState']) {
case '1':
case '11': // general is mostly same as 'trunk', only radlan type
case '3':
case '13':
$trunk = 'dot1Q';
$vlan_oids = $vlan_trunk_oids;
break;
}
}
}
print_debug("ifIndex $ifIndex Egress ($vlan_start-$vlan_end): " . $binmap);
case '7':
case '17':
$trunk = 'qinq';
$vlan_oids = $vlan_trunk_oids; // FIXME. I not sure!
break;
default:
$trunk = 'Egress';
$vlan_oids = $vlan_access_oids;
}
foreach ($vlan_oids as $vlan_start => $oid) {
if (isset($entry[$oid]) && preg_match('/[1-9a-f]/i', $entry[$oid])) {
// not default
$binmap = hex2binmap($entry[$oid]);
$vlan_len = strlen($binmap);
$vlan_end = $vlan_start + $vlan_len - 1;
$vlan_count = substr_count($binmap, '1');
for ($i = 0; $i < $vlan_len; $i++) {
$vlan_num = $vlan_start + $i;
if ($binmap[$i]) {
$discovery_ports_vlans[$ifIndex][$vlan_num] = [
'vlan' => $vlan_num,
];
// decrease significant vlans and break if all found
$vlan_count--;
if ($vlan_count === 0) {
break;
}
}
}
print_debug("ifIndex $ifIndex $trunk ($vlan_start-$vlan_end): " . $binmap);
}
}
}
}
// EOF

View File

@ -5,9 +5,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
@ -25,33 +25,33 @@ RAPID-CITY::rcVlanStaticMembers.1 = Hex-STRING: 00
RAPID-CITY::rcVlanStaticMembers.2 = Hex-STRING: 00
*/
$vlan_oids = snmpwalk_cache_oid($device, 'rcVlanName', array(), 'RAPID-CITY');
$vlan_oids = snmpwalk_cache_oid($device, 'rcVlanName', [], 'RAPID-CITY');
if (!snmp_status())
{
return;
if (!snmp_status()) {
return;
}
$vlan_oids = snmpwalk_cache_oid($device, 'rcVlanType', $vlan_oids, 'RAPID-CITY');
$vlan_oids = snmpwalk_cache_oid($device, 'rcVlanIfIndex', $vlan_oids, 'RAPID-CITY');
$vlan_oids = snmpwalk_cache_oid($device, 'rcVlanType', $vlan_oids, 'RAPID-CITY');
$vlan_oids = snmpwalk_cache_oid($device, 'rcVlanIfIndex', $vlan_oids, 'RAPID-CITY');
$vlan_oids = snmpwalk_cache_oid($device, 'rcVlanRowStatus', $vlan_oids, 'RAPID-CITY');
print_debug_vars($vlan_oids);
$vtp_domain_index = '1'; // Yep, always use domain index 1
foreach ($vlan_oids as $vlan_num => $vlan)
{
// Skip not exist vlans
if (in_array($vlan['rcVlanRowStatus'], array('notInService', 'notReady', 'destroy'))) { continue; }
foreach ($vlan_oids as $vlan_num => $vlan) {
// Skip not exist vlans
if (in_array($vlan['rcVlanRowStatus'], ['notInService', 'notReady', 'destroy'])) {
continue;
}
$vlan_array = array('ifIndex' => $vlan['rcVlanIfIndex'],
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['rcVlanName'],
//'vlan_mtu' => $vlan[''],
'vlan_type' => $vlan['rcVlanType'],
'vlan_status' => 'operational');
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
$vlan_array = ['ifIndex' => $vlan['rcVlanIfIndex'],
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => $vlan['rcVlanName'],
//'vlan_mtu' => $vlan[''],
'vlan_type' => $vlan['rcVlanType'],
'vlan_status' => 'operational'];
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
}
@ -60,21 +60,18 @@ RAPID-CITY::rcVlanPortVlanIds.513 = Hex-STRING: 00 08
RAPID-CITY::rcVlanPortVlanIds.514 = Hex-STRING: 00 03 00 04 00 05 00 06
*/
$ports_vlans_oids = snmpwalk_cache_oid($device, 'rcVlanPortVlanIds', array(), 'RAPID-CITY', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
$ports_vlans_oids = snmpwalk_cache_oid($device, 'rcVlanPortVlanIds', [], 'RAPID-CITY', NULL, OBS_SNMP_ALL_MULTILINE | OBS_SNMP_HEX);
print_debug_vars($ports_vlans_oids);
foreach ($ports_vlans_oids as $ifIndex => $entry)
{
foreach ($ports_vlans_oids as $ifIndex => $entry) {
foreach (str_split(str_replace(' ', '', $entry['rcVlanPortVlanIds']), 4) as $vlan_hex)
{
$vlan_num = hexdec($vlan_hex);
foreach (str_split(str_replace(' ', '', $entry['rcVlanPortVlanIds']), 4) as $vlan_hex) {
$vlan_num = hexdec($vlan_hex);
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num]))
{
$discovery_ports_vlans[$ifIndex][$vlan_num] = array('vlan' => $vlan_num);
if (isset($discovery_vlans[$vtp_domain_index][$vlan_num])) {
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
}
}
}
}
// EOF

View File

@ -4,9 +4,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
@ -26,98 +26,104 @@
$vlan_oids = snmpwalk_cache_oid($device, 'vlanConfigTable', [], 'TPLINK-DOT1Q-VLAN-MIB');
print_debug_vars($vlan_oids);
if (!snmp_status()) { return; }
if (!snmp_status()) {
return;
}
// TPLINK-DOT1Q-VLAN-MIB::vlanPortNumber.49153 = STRING: "1/0/1"
// TPLINK-DOT1Q-VLAN-MIB::vlanPortNumber.49154 = STRING: "1/0/2"
$port_descr = [];
foreach(snmpwalk_cache_oid($device, 'vlanPortNumber', [], 'TPLINK-DOT1Q-VLAN-MIB') as $index => $entry) {
$port_descr[$entry['vlanPortNumber']] = $index;
foreach (snmpwalk_cache_oid($device, 'vlanPortNumber', [], 'TPLINK-DOT1Q-VLAN-MIB') as $index => $entry) {
$port_descr[$entry['vlanPortNumber']] = $index;
}
$vtp_domain_index = '1'; // Yep, always use domain index 1
foreach ($vlan_oids as $vlan_num => $vlan) {
// Skip not exist vlans
if ($vlan['dot1qVlanStatus'] !== 'active') { continue; }
$vlan_array = [
'ifIndex' => $vlan_num, // Vlan ifIndex same as Vlan ID
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => safe_empty($vlan['dot1qVlanDescription']) ? "Vlan $vlan_num" : $vlan['dot1qVlanDescription'],
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
// Tagged ports
if (safe_empty($vlan['vlanTagPortMemberAdd'])) { continue; }
// See: https://jira.observium.org/browse/OBS-3827
// TPLINK-DOT1Q-VLAN-MIB::vlanTagPortMemberAdd.10 = STRING: "1/0/4,1/0/11,1/0/13,1/0/15,1/0/19-20"
// TPLINK-DOT1Q-VLAN-MIB::vlanTagPortMemberAdd.2 = STRING: "Gi1/0/3-24,Te1/0/27-28,Gi2/0/3-24,Te2/0/27-28,Po1-3,7,11,13-14"
$members = [];
$i = -1;
foreach (explode(',', $vlan['vlanTagPortMemberAdd']) as $member) {
if (!preg_match('/^\d+(\-\d+)?$/', $member)) {
$i++;
$members[$i] = $member;
} else {
// append to previous
$members[$i] .= ',' . $member;
}
}
$member_base = '';
foreach ($members as $member) {
if (isset($port_descr[$member])) {
$ifIndex = $port_descr[$member];
$discovery_ports_vlans[$ifIndex][$vlan_num] = [ 'vlan' => $vlan_num ];
continue;
// Skip not exist vlans
if ($vlan['dot1qVlanStatus'] !== 'active') {
continue;
}
if (preg_match('/^([^\d]+)(.+)$/', $member, $matches)) {
$member_base = $matches[1];
}
if (str_contains_array($member, [ '-', ',' ])) {
// Expand list to individual ports
if (str_contains($member, '/')) {
// 1/0/19-20,30
// Te2/0/27-28,30
$split_char = '/';
$member_array = explode($split_char, $member);
} elseif (preg_match('/^([^\d]+)(.+)$/', $member, $matches)) {
// Po1-3,7,11,13-14
$split_char = '';
$member_array = [ $matches[1], $matches[2] ];
}
$numbers = array_pop($member_array);
foreach (list_to_range($numbers) as $number) {
$member_new = $member_array;
$member_new[] = $number;
$member_name = implode($split_char, $member_new);
$vlan_array = [
'ifIndex' => $vlan_num, // Vlan ifIndex same as Vlan ID
'vlan_domain' => $vtp_domain_index,
'vlan_vlan' => $vlan_num,
'vlan_name' => safe_empty($vlan['dot1qVlanDescription']) ? "Vlan $vlan_num" : $vlan['dot1qVlanDescription'],
//'vlan_mtu' => $vlan[''],
'vlan_type' => 'ethernet',
'vlan_status' => 'operational'
];
if (isset($port_descr[$member_name])) {
$ifIndex = $port_descr[$member_name];
$discovery_ports_vlans[$ifIndex][$vlan_num] = [ 'vlan' => $vlan_num ];
continue;
$discovery_vlans[$vtp_domain_index][$vlan_num] = $vlan_array;
// Tagged ports
if (safe_empty($vlan['vlanTagPortMemberAdd'])) {
continue;
}
// See: https://jira.observium.org/browse/OBS-3827
// TPLINK-DOT1Q-VLAN-MIB::vlanTagPortMemberAdd.10 = STRING: "1/0/4,1/0/11,1/0/13,1/0/15,1/0/19-20"
// TPLINK-DOT1Q-VLAN-MIB::vlanTagPortMemberAdd.2 = STRING: "Gi1/0/3-24,Te1/0/27-28,Gi2/0/3-24,Te2/0/27-28,Po1-3,7,11,13-14"
$members = [];
$i = -1;
foreach (explode(',', $vlan['vlanTagPortMemberAdd']) as $member) {
if (!preg_match('/^\d+(\-\d+)?$/', $member)) {
$i++;
$members[$i] = $member;
} else {
// append to previous
$members[$i] .= ',' . $member;
}
if (isset($port_descr[$member_base.$member_name])) {
$ifIndex = $port_descr[$member_base.$member_name];
$discovery_ports_vlans[$ifIndex][$vlan_num] = [ 'vlan' => $vlan_num ];
continue;
}
}
} elseif (isset($port_descr[$member_base.$member])) {
$ifIndex = $port_descr[$member_base.$member];
$discovery_ports_vlans[$ifIndex][$vlan_num] = [ 'vlan' => $vlan_num ];
continue;
}
print_debug("Unknown port name for Tagged Vlans: $member");
}
$member_base = '';
foreach ($members as $member) {
if (isset($port_descr[$member])) {
$ifIndex = $port_descr[$member];
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
continue;
}
if (preg_match('/^([^\d]+)(.+)$/', $member, $matches)) {
$member_base = $matches[1];
}
if (str_contains_array($member, ['-', ','])) {
// Expand list to individual ports
if (str_contains($member, '/')) {
// 1/0/19-20,30
// Te2/0/27-28,30
$split_char = '/';
$member_array = explode($split_char, $member);
} elseif (preg_match('/^([^\d]+)(.+)$/', $member, $matches)) {
// Po1-3,7,11,13-14
$split_char = '';
$member_array = [$matches[1], $matches[2]];
}
$numbers = array_pop($member_array);
foreach (list_to_range($numbers) as $number) {
$member_new = $member_array;
$member_new[] = $number;
$member_name = implode($split_char, $member_new);
if (isset($port_descr[$member_name])) {
$ifIndex = $port_descr[$member_name];
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
continue;
}
if (isset($port_descr[$member_base . $member_name])) {
$ifIndex = $port_descr[$member_base . $member_name];
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
continue;
}
}
} elseif (isset($port_descr[$member_base . $member])) {
$ifIndex = $port_descr[$member_base . $member];
$discovery_ports_vlans[$ifIndex][$vlan_num] = ['vlan' => $vlan_num];
continue;
}
print_debug("Unknown port name for Tagged Vlans: $member");
}
}
// EOF