From 91fed0b1182db2f6a46b7f0aec76211fea39133f Mon Sep 17 00:00:00 2001 From: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:20:10 +0200 Subject: [PATCH] Refactor discovery-protocols (#15324) Refactor discovery-protocols Update zynos.yaml Update discovery-protocols.inc.php Allow unordered for LLDP-MIB discovery in Zyxel switches --- includes/definitions/zynos.yaml | 4 ++++ .../discovery/discovery-protocols.inc.php | 21 +++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/includes/definitions/zynos.yaml b/includes/definitions/zynos.yaml index c9e4e01b4b..f9bf52bdee 100644 --- a/includes/definitions/zynos.yaml +++ b/includes/definitions/zynos.yaml @@ -18,3 +18,7 @@ discovery: - '/^XS/' - '/^XGS/' - '/^ZyXEL/' +oids: + unordered: + - LLDP-MIB::lldpRemTable + - .1.0.8802.1.1.2.1.4.2.1.3 diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index cf562e5204..98fbcb3095 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -7,7 +7,7 @@ global $link_exists; if ($device['os'] == 'ironware') { echo ' Brocade FDP: '; - $fdp_array = snmpwalk_group($device, 'snFdpCacheEntry', 'FOUNDRY-SN-SWITCH-GROUP-MIB', 2); + $fdp_array = SnmpQuery::hideMib()->walk('FOUNDRY-SN-SWITCH-GROUP-MIB::snFdpCacheEntry')->table(2); foreach ($fdp_array as $key => $fdp_if_array) { $interface = get_port_by_ifIndex($device['device_id'], $key); @@ -43,7 +43,7 @@ if ($device['os'] == 'ironware') { if (isset($device['os_group']) && $device['os_group'] == 'cisco') { echo ' CISCO-CDP-MIB: '; - $cdp_array = snmpwalk_group($device, 'cdpCache', 'CISCO-CDP-MIB', 2); + $cdp_array = SnmpQuery::hideMib()->walk('CISCO-CDP-MIB::cdpCache')->table(2); foreach ($cdp_array as $key => $cdp_if_array) { $interface = get_port_by_ifIndex($device['device_id'], $key); @@ -87,15 +87,15 @@ if (isset($device['os_group']) && $device['os_group'] == 'cisco') { if (($device['os'] == 'routeros') && version_compare($device['version'], '7.7', '<')) { echo ' LLDP-MIB: '; - $lldp_array = snmpwalk_group($device, 'lldpRemEntry', 'LLDP-MIB', 3); + $lldp_array = SnmpQuery::hideMib()->walk('LLDP-MIB::lldpRemEntry')->table(3); if (! empty($lldp_array)) { // workaround for routeros returning the incorrect index if (! empty($lldp_array[0][0])) { $lldp_array = $lldp_array[0][0]; } - $lldp_ports = snmpwalk_group($device, 'mtxrInterfaceStatsName', 'MIKROTIK-MIB'); - $lldp_ports_num = snmpwalk_group($device, 'mtxrNeighborInterfaceID', 'MIKROTIK-MIB'); + $lldp_ports = SnmpQuery::hideMib()->walk('MIKROTIK-MIB::mtxrInterfaceStatsName')->table(); + $lldp_ports_num = SnmpQuery::hideMib()->walk('MIKROTIK-MIB::mtxrNeighborInterfaceID')->table(); foreach ($lldp_array as $key => $lldp) { $local_port_ifName = $lldp_ports[hexdec($lldp_ports_num[$key]['mtxrNeighborInterfaceID'])]['mtxrInterfaceStatsName']; @@ -133,8 +133,7 @@ if (($device['os'] == 'routeros') && version_compare($device['version'], '7.7', echo PHP_EOL; } elseif ($device['os'] == 'pbn' || $device['os'] == 'bdcom') { echo ' NMS-LLDP-MIB: '; - $lldp_array = snmpwalk_group($device, 'lldpRemoteSystemsData', 'NMS-LLDP-MIB'); - + $lldp_array = SnmpQuery::hideMib()->walk('NMS-LLDP-MIB::lldpRemoteSystemsData')->table(); foreach ($lldp_array as $key => $lldp) { d_echo($lldp); $interface = get_port_by_ifIndex($device['device_id'], $lldp['lldpRemLocalPortNum']); @@ -166,7 +165,7 @@ if (($device['os'] == 'routeros') && version_compare($device['version'], '7.7', echo PHP_EOL; } elseif ($device['os'] == 'timos') { echo ' TIMETRA-LLDP-MIB: '; - $lldp_array = snmpwalk_group($device, 'tmnxLldpRemoteSystemsData', 'TIMETRA-LLDP-MIB'); + $lldp_array = SnmpQuery::hideMib()->walk('TIMETRA-LLDP-MIB::tmnxLldpRemoteSystemsData')->table(); foreach ($lldp_array as $key => $lldp) { $ifIndex = key($lldp['tmnxLldpRemPortId']); $MacIndex = key($lldp['tmnxLldpRemPortId'][$ifIndex]); @@ -201,7 +200,7 @@ if (($device['os'] == 'routeros') && version_compare($device['version'], '7.7', } elseif ($device['os'] == 'jetstream') { echo ' JETSTREAM-LLDP MIB: '; - $lldp_array = snmpwalk_group($device, 'lldpNeighborInfoEntry', 'TPLINK-LLDPINFO-MIB'); + $lldp_array = SnmpQuery::hideMib()->walk('TPLINK-LLDPINFO-MIB::lldpNeighborInfoEntry')->table(); foreach ($lldp_array as $key => $lldp) { $IndexId = key($lldp['lldpNeighborPortIndexId']); @@ -238,9 +237,9 @@ if (($device['os'] == 'routeros') && version_compare($device['version'], '7.7', echo PHP_EOL; } else { echo ' LLDP-MIB: '; - $lldp_array = snmpwalk_group($device, 'lldpRemTable', 'LLDP-MIB', 3); + $lldp_array = SnmpQuery::hideMib()->walk('LLDP-MIB::lldpRemTable')->table(3); if (! empty($lldp_array)) { - $lldp_remAddr_num = snmpwalk_cache_multi_oid($device, '.1.0.8802.1.1.2.1.4.2.1.3', [], 'LLDP-MIB', null, '-OQun'); + $lldp_remAddr_num = SnmpQuery::hideMib()->numeric()->walk('.1.0.8802.1.1.2.1.4.2.1.3'); foreach ($lldp_remAddr_num as $key => $value) { $res = preg_match("/1\.0\.8802\.1\.1\.2\.1\.4\.2\.1\.3\.([^\.]*)\.([^\.]*)\.([^\.]*)\.([^\.]*)\.([^\.]*).(([^\.]*)(\.([^\.]*))+)/", $key, $matches); if ($res) {