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

@ -6,10 +6,10 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
include('alcatel-ind1-interswitch-protocol-mib.inc.php');
include(__DIR__ . '/alcatel-ind1-interswitch-protocol-mib.inc.php');
// EOF

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
@ -14,113 +14,97 @@
// Same mib type, but different Oid tree
$amap_array = snmpwalk_cache_threepart_oid($device, "aipAMAPportConnectionTable", [], $mib, NULL, OBS_SNMP_ALL_TABLE);
if ($amap_array)
{
$amap_hosts = snmpwalk_cache_twopart_oid($device, 'aipAMAPIpAddr', [], $mib, NULL, OBS_SNMP_ALL_TABLE);
print_debug_vars($amap_array);
print_debug_vars($amap_hosts);
if (safe_empty($amap_array)) {
return;
}
foreach ($amap_array as $aipAMAPLocalConnectionIndex => $entry1)
{
foreach ($entry1 as $remote_mac => $entry2)
{
foreach ($entry2 as $aipAMAPRemConnectionIndex => $amap)
{
$port = get_port_by_index_cache($device, $amap['aipAMAPLocalIfindex']);
$amap_hosts = snmpwalk_cache_twopart_oid($device, 'aipAMAPIpAddr', [], $mib, NULL, OBS_SNMP_ALL_TABLE);
print_debug_vars($amap_array);
print_debug_vars($amap_hosts);
// Remote Hostname
$remote_hostname = $amap['aipAMAPRemHostname'];
foreach ($amap_array as $aipAMAPLocalConnectionIndex => $entry1) {
foreach ($entry1 as $remote_mac => $entry2) {
foreach ($entry2 as $aipAMAPRemConnectionIndex => $amap) {
$port = get_port_by_index_cache($device, $amap['aipAMAPLocalIfindex']);
// Remote address(es)
$remote_address = NULL;
if (isset($amap_hosts[$remote_mac]))
{
// Can be multiple?
$addresses = array_keys($amap_hosts[$remote_mac]);
if (count($addresses) > 1)
{
foreach ($addresses as $addr)
{
$addr_version = get_ip_version($addr);
$addr_type = get_ip_type($addr);
if (in_array($addr_type, [ 'unspecified', 'loopback', 'reserved', 'multicast' ]))
{
continue;
}
elseif ($addr_version == 6 && $addr_type == 'link-local')
{
continue;
}
elseif ($addr_type == 'unicast')
{
// Prefer IPv4/IPv6 unicast
$remote_address = $addr;
break;
}
elseif ($addr_version == 4)
{
// Than prefer IPv4
$remote_address = $addr;
break;
}
$remote_address = $addr;
// Remote Hostname
$remote_hostname = $amap['aipAMAPRemHostname'];
// Remote address(es)
$remote_address = NULL;
if (isset($amap_hosts[$remote_mac])) {
// Can be multiple?
$addresses = array_keys($amap_hosts[$remote_mac]);
if (count($addresses) > 1) {
foreach ($addresses as $addr) {
$addr_version = get_ip_version($addr);
$addr_type = get_ip_type($addr);
if (in_array($addr_type, ['unspecified', 'loopback', 'reserved', 'multicast'])) {
continue;
} elseif ($addr_version == 6 && $addr_type == 'link-local') {
continue;
} elseif ($addr_type == 'unicast') {
// Prefer IPv4/IPv6 unicast
$remote_address = $addr;
break;
} elseif ($addr_version == 4) {
// Than prefer IPv4
$remote_address = $addr;
break;
}
$remote_address = $addr;
}
print_debug("Multiple remote IP addresses detect, selected: $remote_address");
} else {
$remote_address = array_shift($addresses);
}
}
print_debug("Multiple remote IP addresses detect, selected: $remote_address");
} else {
$remote_address = array_shift($addresses);
}
}
$remote_device_id = FALSE;
//$remote_device_id = NULL;
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname, $remote_address, $remote_mac);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname, $remote_address)) // Check all previous autodiscovery rounds
{
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, $remote_address, 'AMAP', $amap['aipAMAPRemDevModelName'], $device, $port);
}
$remote_port_id = NULL;
$if = $amap['aipAMAPRemSlot']."/".$amap['aipAMAPRemPort'];
if ($remote_device_id)
{
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($if, $if, $if, $remote_device_id, 0));
if (!$remote_port_id)
{
if (!is_null($remote_mac))
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname, $remote_address, $remote_mac);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname, $remote_address)) // Check all previous autodiscovery rounds
{
// By MAC
$remote_port_id = get_port_id_by_mac($remote_device_id, $remote_mac);
} else {
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where))
{
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, $remote_address, 'AMAP', $amap['aipAMAPRemDevModelName'], $device, $port);
}
}
}
$neighbour = [
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $amap['aipAMAPRemSlot']."/".$amap['aipAMAPRemPort'],
'remote_platform' => $amap['aipAMAPRemDevModelName'],
'remote_version' => NULL,
'remote_address' => $remote_address,
//'last_change' => $last_change
];
discover_neighbour($port, 'amap', $neighbour);
}
$remote_port_id = NULL;
$if = $amap['aipAMAPRemSlot'] . "/" . $amap['aipAMAPRemPort'];
if ($remote_device_id) {
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
if (!$remote_port_id) {
if (!is_null($remote_mac)) {
// By MAC
$remote_port_id = get_port_id_by_mac($remote_device_id, $remote_mac);
} else {
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where)) {
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
}
}
}
$neighbour = [
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $amap['aipAMAPRemSlot'] . "/" . $amap['aipAMAPRemPort'],
'remote_platform' => $amap['aipAMAPRemDevModelName'],
'remote_version' => NULL,
'remote_address' => $remote_address,
//'last_change' => $last_change
];
discover_neighbour($port, 'amap', $neighbour);
}
}
}
}
// EOF

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
@ -42,157 +42,178 @@ $cdp_array = snmpwalk_cache_twopart_oid($device, "cdpCache", [], "CISCO-CDP-MIB"
// If we get timeout error and device has 'CISCO-FLASH-MIB', sleep and try re-walk
if (snmp_status() === FALSE && is_device_mib($device, 'CISCO-FLASH-MIB') &&
(snmp_error_code() === OBS_SNMP_ERROR_REQUEST_TIMEOUT || snmp_error_code() === OBS_SNMP_ERROR_BULK_REQUEST_TIMEOUT))
{
print_debug('Try to re-walk "CISCO-CDP-MIB"..');
sleep(5); // Additional sleep, see comments in includes/discovery/storage/cisco-flash-mib-inc.php
$cdp_array = snmpwalk_cache_twopart_oid($device, "cdpCache", $cdp_array, "CISCO-CDP-MIB", NULL, $cdp_flags);
(snmp_error_code() === OBS_SNMP_ERROR_REQUEST_TIMEOUT || snmp_error_code() === OBS_SNMP_ERROR_BULK_REQUEST_TIMEOUT)) {
print_debug('Try to re-walk "CISCO-CDP-MIB"..');
sleep(5); // Additional sleep, see comments in includes/discovery/storage/cisco-flash-mib-inc.php
$cdp_array = snmpwalk_cache_twopart_oid($device, "cdpCache", $cdp_array, "CISCO-CDP-MIB", NULL, $cdp_flags);
}
print_debug_vars($cdp_array);
if ($cdp_array) {
// fetch sysUptime for correct last change
// $device_sysUptime = timeticks_to_sec(snmp_get_oid($device, "sysUpTime.0", "SNMPv2-MIB"));
if (safe_empty($cdp_array)) {
return;
}
// Force fetch cdpCacheAddress as HEX strings!
$cdp_array = snmpwalk_cache_twopart_oid($device, "cdpCacheAddress", $cdp_array, "CISCO-CDP-MIB", NULL, OBS_SNMP_ALL_HEX);
foreach ($cdp_array as $ifIndex => $port_neighbours) {
// fetch sysUptime for correct last change
// $device_sysUptime = timeticks_to_sec(snmp_get_oid($device, "sysUpTime.0", "SNMPv2-MIB"));
// Force fetch cdpCacheAddress as HEX strings!
$cdp_array = snmpwalk_cache_twopart_oid($device, "cdpCacheAddress", $cdp_array, "CISCO-CDP-MIB", NULL, OBS_SNMP_ALL_HEX);
foreach ($cdp_array as $ifIndex => $port_neighbours) {
$port = get_port_by_index_cache($device, $ifIndex);
//$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ifIndex));
foreach ($port_neighbours as $cdpCacheDeviceIndex => $cdp_entry) {
// Init
$remote_mac = NULL;
$remote_hostname = '';
// Init
$remote_mac = NULL;
$remote_hostname = '';
// Remote hostname
// NOTE. cdpCacheDeviceId have undocumented limit by 40 chars!
if (preg_match('/^([A-F\d]{2}\s?){6}$/', $cdp_entry['cdpCacheDeviceId'])) {
// HEX mac address
// cdpCacheDeviceId.3.1 = "98 90 96 D1 59 5A "
$remote_hostname = $cdp_entry['cdpCacheDeviceId'];
$remote_mac = str_replace(' ', '', $cdp_entry['cdpCacheDeviceId']);
} elseif (preg_match('/^01 (?<ip>([A-F\d]{2}\s?){4})$/', $cdp_entry['cdpCacheDeviceId'], $matches)) {
// HEX ip address
// cdpCacheDeviceId.5.2 = "01 90 7F 93 3E "
$remote_hostname = hex2ip($matches['ip']);
} else {
$remote_hostname = snmp_hexstring($cdp_entry['cdpCacheDeviceId']);
if (preg_match('/^(?:SEP|SIP|\w+\-)?([a-f\d]{12})$/i', $remote_hostname, $matches)) {
// Meraki report mac instead hostname
// Axis: axis-<mac>
// Cisco IP Phone: SEP<mac>
// SIP-<platform><mac>,
$remote_hostname = $cdp_entry['cdpCacheDeviceId'];
$remote_mac = $matches[1];
} elseif (preg_match(OBS_PATTERN_NOPRINT, $remote_hostname)) {
// Non-printable chars, seems as ID is not hostname, keep as is
$tmp = preg_replace(OBS_PATTERN_NOPRINT, '', $remote_hostname);
if (is_valid_hostname($tmp)) {
print_debug("Probably valid hostname with broken chars? '".$cdp_entry['cdpCacheDeviceId']."' => '$tmp'");
}
$remote_hostname = $cdp_entry['cdpCacheDeviceId'];
// Remote hostname
// NOTE. cdpCacheDeviceId have undocumented limit by 40 chars!
if (preg_match('/^([A-F\d]{2}\s?){6}$/i', $cdp_entry['cdpCacheDeviceId'])) {
// HEX mac address
// cdpCacheDeviceId.3.1 = "98 90 96 D1 59 5A "
// cdpCacheDeviceId.3.1 = "549fc6fd89c7"
$remote_hostname = $cdp_entry['cdpCacheDeviceId'];
$remote_mac = str_replace(' ', '', $cdp_entry['cdpCacheDeviceId']);
} elseif (preg_match('/^01 (?<ip>([A-F\d]{2}\s?){4})$/', $cdp_entry['cdpCacheDeviceId'], $matches)) {
// HEX ip address
// cdpCacheDeviceId.5.2 = "01 90 7F 93 3E "
$remote_hostname = hex2ip($matches['ip']);
} else {
list($remote_hostname) = explode('(', $remote_hostname); // Fix for Nexus CDP neighbors: <hostname>(serial number)
}
}
$hostname_len = strlen($remote_hostname);
// cdpCacheSysName
if (isset($cdp_entry['cdpCacheSysName'])) {
$cdp_entry['cdpCacheSysName'] = snmp_hexstring($cdp_entry['cdpCacheSysName']);
$sysname_len = strlen($cdp_entry['cdpCacheSysName']);
if (is_valid_hostname($cdp_entry['cdpCacheSysName']) && $sysname_len > $hostname_len) {
$remote_hostname = $cdp_entry['cdpCacheSysName'];
} elseif ($sysname_len && preg_match('/^[a-f\d]{12}$/i', $cdp_entry['cdpCacheDeviceId'])) {
// DeviceId is mac, prefer sysName
$remote_hostname = $cdp_entry['cdpCacheSysName'];
}
}
// Remote address
$remote_address = hex2ip($cdp_entry['cdpCacheAddress']);
// Last change
/* Derp. Do not use Last change from neighbour, it's not correct for us
* (seems as changed uptime by remote host, not possible correct calculate unixtime)
$last_change = timeticks_to_sec($cdp_entry['cdpCacheLastChange']);
if ($last_change > 0)
{
$last_change = get_time() - $device_sysUptime + $last_change;
}
*/
// Remote MAC on some devices
$if = NULL;
if (preg_match('/^([A-F\d]{2}\s?){6}$/', $cdp_entry['cdpCacheDevicePort'])) {
$remote_mac = $cdp_entry['cdpCacheDevicePort'];
} else {
$cdp_entry['cdpCacheDevicePort'] = snmp_hexstring($cdp_entry['cdpCacheDevicePort']);
if (preg_match('/^[a-f\d]{12}$/i', $cdp_entry['cdpCacheDevicePort'])) {
$remote_mac = $cdp_entry['cdpCacheDevicePort'];
} else {
$if = $cdp_entry['cdpCacheDevicePort'];
}
}
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname, $remote_address, $remote_mac);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname, $remote_address)) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, $remote_address, 'CDP', $cdp_entry['cdpCachePlatform'], $device, $port);
}
$remote_port_id = NULL;
if ($remote_device_id) {
//$if = $cdp_entry['cdpCacheDevicePort'];
if (!is_null($if)) {
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($if, $if, $if, $remote_device_id, 0));
// Aruba devices can report ifAlias instead ifDescr
if (!$remote_port_id && !isHexString($if)) {
$query = 'SELECT `port_id` FROM `ports` WHERE `ifAlias` = ? AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [ $if, $remote_device_id, 0 ]);
}
}
if (!$remote_port_id) {
if (!is_null($remote_mac)) {
// By MAC
$remote_port_id = get_port_id_by_mac($remote_device_id, $remote_mac);
} elseif (!is_null($if)) {
// Try by ifAlias
$query = 'SELECT `port_id` FROM `ports` WHERE `ifAlias` = ? AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($if, $remote_device_id, 0));
}
if (!$remote_port_id) {
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where))
{
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
$remote_hostname = snmp_hexstring($cdp_entry['cdpCacheDeviceId']);
if (preg_match('/^(?:SEP|SIP|\w+\-)?([a-f\d]{12})$/i', $remote_hostname, $matches)) {
// Meraki report mac instead hostname
// Axis: axis-<mac>
// Cisco IP Phone: SEP<mac>
// SIP-<platform><mac>,
$remote_hostname = $cdp_entry['cdpCacheDeviceId'];
$remote_mac = $matches[1];
} elseif (preg_match(OBS_PATTERN_NOPRINT, $remote_hostname)) {
// Non-printable chars, seems as ID is not hostname, keep as is
$tmp = preg_replace(OBS_PATTERN_NOPRINT, '', $remote_hostname);
if (is_valid_hostname($tmp)) {
print_debug("Probably valid hostname with broken chars? '" . $cdp_entry['cdpCacheDeviceId'] . "' => '$tmp'");
}
$remote_hostname = $cdp_entry['cdpCacheDeviceId'];
} else {
$remote_hostname = explode('(', $remote_hostname)[0]; // Fix for Nexus CDP neighbors: <hostname>(serial number)
}
}
}
}
$hostname_len = strlen($remote_hostname);
$neighbour = [
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $cdp_entry['cdpCacheDevicePort'],
'remote_platform' => $cdp_entry['cdpCachePlatform'],
'remote_version' => $cdp_entry['cdpCacheVersion'],
'remote_address' => $remote_address,
//'last_change' => $last_change
];
discover_neighbour($port, 'cdp', $neighbour);
// cdpCacheSysName
if (isset($cdp_entry['cdpCacheSysName'])) {
$cdp_entry['cdpCacheSysName'] = snmp_hexstring($cdp_entry['cdpCacheSysName']);
$sysname_len = strlen($cdp_entry['cdpCacheSysName']);
if (is_valid_hostname($cdp_entry['cdpCacheSysName']) && $sysname_len > $hostname_len) {
$remote_hostname = $cdp_entry['cdpCacheSysName'];
} elseif ($sysname_len && preg_match('/^[a-f\d]{12}$/i', $cdp_entry['cdpCacheDeviceId'])) {
// DeviceId is mac, prefer sysName
$remote_hostname = $cdp_entry['cdpCacheSysName'];
}
}
// Remote address
$remote_address = hex2ip($cdp_entry['cdpCacheAddress']);
// MGMT address, select best
$mgmt_address = hex2ip($cdp_entry['cdpCachePrimaryMgmtAddr']);
if ($mgmt_address && $remote_address !== $mgmt_address) {
$remote_type = get_ip_type($remote_address);
$mgmt_type = get_ip_type($mgmt_address);
// cdpCacheAddressType.436207616.16318465 = ip
// cdpCacheAddress.436207616.16318465 = "64 69 00 31 " -> 100.105.0.49 (cgnat)
// cdpCachePrimaryMgmtAddrType.436207616.16318465 = ip
// cdpCachePrimaryMgmtAddr.436207616.16318465 = "0A AF 0C 3C " -> 10.175.12.60
// cdpCacheSecondaryMgmtAddrType.436207616.16318465 = ip
// cdpCacheSecondaryMgmtAddr.436207616.16318465 = ""
if (in_array($remote_type, [ 'cgnat', 'link-local' ]) &&
!in_array($mgmt_type, [ 'cgnat', 'link-local' ])) {
print_debug("Select best address:\n cdpCacheAddress - $remote_address ($remote_type),\n* cdpCachePrimaryMgmtAddr - $mgmt_address ($mgmt_type)");
$remote_address = $mgmt_address;
} else {
print_debug("Select best address:\n* cdpCacheAddress - $remote_address ($remote_type),\n cdpCachePrimaryMgmtAddr - $mgmt_address ($mgmt_type)");
}
}
// Last change
/* Derp. Do not use Last change from neighbour, it's not correct for us
* (seems as changed uptime by remote host, not possible correct calculate unixtime)
$last_change = timeticks_to_sec($cdp_entry['cdpCacheLastChange']);
if ($last_change > 0)
{
$last_change = get_time() - $device_sysUptime + $last_change;
}
*/
// Remote MAC on some devices
$if = NULL;
if (preg_match('/^([A-F\d]{2}\s?){6}$/', $cdp_entry['cdpCacheDevicePort'])) {
$remote_mac = $cdp_entry['cdpCacheDevicePort'];
} else {
$cdp_entry['cdpCacheDevicePort'] = snmp_hexstring($cdp_entry['cdpCacheDevicePort']);
if (preg_match('/^[a-f\d]{12}$/i', $cdp_entry['cdpCacheDevicePort'])) {
$remote_mac = $cdp_entry['cdpCacheDevicePort'];
} else {
$if = $cdp_entry['cdpCacheDevicePort'];
}
}
// Try to find a remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname, $remote_address, $remote_mac);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname, $remote_address)) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, $remote_address, 'CDP', $cdp_entry['cdpCachePlatform'], $device, $port);
}
$remote_port_id = NULL;
if ($remote_device_id) {
//$if = $cdp_entry['cdpCacheDevicePort'];
if (!is_null($if)) {
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
// Aruba devices can report ifAlias instead ifDescr
if (!$remote_port_id && !is_hex_string($if)) {
$query = 'SELECT `port_id` FROM `ports` WHERE `ifAlias` = ? AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $remote_device_id, 0]);
}
}
if (!$remote_port_id) {
if (!is_null($remote_mac)) {
// By MAC
$remote_port_id = get_port_id_by_mac($remote_device_id, $remote_mac);
} elseif (!is_null($if)) {
// Try by ifAlias
$query = 'SELECT `port_id` FROM `ports` WHERE `ifAlias` = ? AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $remote_device_id, 0]);
}
if (!$remote_port_id) {
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where)) {
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
}
}
}
$neighbour = [
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $cdp_entry['cdpCacheDevicePort'],
'remote_platform' => $cdp_entry['cdpCachePlatform'],
'remote_version' => $cdp_entry['cdpCacheVersion'],
'remote_address' => $remote_address,
//'last_change' => $last_change
];
discover_neighbour($port, 'cdp', $neighbour);
}
}
}
// EOF

View File

@ -0,0 +1,126 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
/*
CISCO-LWAPP-CDP-MIB::clcCdpApCacheApName.'hqaoM '.1 = STRING: AP6871.6164.87FC
CISCO-LWAPP-CDP-MIB::clcCdpApCacheApAddressType.'hqaoM '.1 = INTEGER: ipv4(1)
CISCO-LWAPP-CDP-MIB::clcCdpApCacheApAddress.'hqaoM '.1 = Hex-STRING: 0A C9 07 04
CISCO-LWAPP-CDP-MIB::clcCdpApCacheLocalInterface.'hqaoM '.1 = INTEGER: 1
CISCO-LWAPP-CDP-MIB::clcCdpApCacheNeighName.'hqaoM '.1 = STRING: uk-hw-c9300-core.nbrown.root.local
CISCO-LWAPP-CDP-MIB::clcCdpApCacheNeighAddressType.'hqaoM '.1 = INTEGER: ipv4(1)
CISCO-LWAPP-CDP-MIB::clcCdpApCacheNeighAddress.'hqaoM '.1 = Hex-STRING: 0A C9 07 01
CISCO-LWAPP-CDP-MIB::clcCdpApCacheNeighInterface.'hqaoM '.1 = STRING: GigabitEthernet1/0/6
CISCO-LWAPP-CDP-MIB::clcCdpApCacheNeighVersion.'hqaoM '.1 = STRING: Cisco IOS Software [Cupertino], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 17.9.4a, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2023 by Cisco Systems, Inc.
Compiled Fri 20-Oct-23 10:44 by mcpre
CISCO-LWAPP-CDP-MIB::clcCdpApCacheAdvtVersion.'hqaoM '.1 = INTEGER: cdpv2(2)
CISCO-LWAPP-CDP-MIB::clcCdpApCachePlatform.'hqaoM '.1 = STRING: cisco C9300L-48P-4X
CISCO-LWAPP-CDP-MIB::clcCdpApCacheCapabilities.'hqaoM '.1 = STRING: "Router Switch IGMP"
CISCO-LWAPP-CDP-MIB::clcCdpApCacheHoldtimeLeft.'hqaoM '.1 = Gauge32: 1715786089 seconds
CISCO-LWAPP-CDP-MIB::clcCdpApCacheDuplex.'hqaoM '.1 = INTEGER: fullduplex(2)
CISCO-LWAPP-CDP-MIB::clcCdpApCacheInterfaceSpeed.'hqaoM '.1 = INTEGER: thousandMbps(4) Mbps
*/
$cdp_flags = OBS_SNMP_ALL_MULTILINE | OBS_SNMP_TABLE | OBS_SNMP_DISPLAY_HINT; // disable hints
$cdp_array = snmpwalk_cache_twopart_oid($device, "clcCdpApCacheEntry", [], "CISCO-LWAPP-CDP-MIB", NULL, $cdp_flags);
print_debug_vars($cdp_array);
if (safe_empty($cdp_array)) {
return;
}
foreach ($cdp_array as $local_mac => $neighbours) {
foreach ($neighbours as $cdpCacheDeviceIndex => $cdp_entry) {
// Local port
$port = get_port_by_index_cache($device, $cdp_entry['clcCdpApCacheLocalInterface']);
// Remote hostname
$remote_hostname = $cdp_entry['clcCdpApCacheNeighName'];
// Remote address
$remote_address = hex2ip($cdp_entry['clcCdpApCacheNeighAddress']);
// Remote MAC on some devices
$if = NULL;
$remote_mac = NULL;
if (preg_match('/^([A-F\d]{2}\s?){6}$/', $cdp_entry['clcCdpApCacheNeighInterface'])) {
$remote_mac = $cdp_entry['clcCdpApCacheNeighInterface'];
} else {
$cdp_entry['clcCdpApCacheNeighInterface'] = snmp_hexstring($cdp_entry['clcCdpApCacheNeighInterface']);
if (preg_match('/^[a-f\d]{12}$/i', $cdp_entry['clcCdpApCacheNeighInterface'])) {
$remote_mac = $cdp_entry['clcCdpApCacheNeighInterface'];
} else {
$if = $cdp_entry['clcCdpApCacheNeighInterface'];
}
}
// Try to find a remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname, $remote_address, $remote_mac);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname, $remote_address)) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, $remote_address, 'CDP', $cdp_entry['cdpCachePlatform'], $device, $port);
}
// Remote port (when a remote device found)
$remote_port_id = NULL;
if ($remote_device_id) {
if (!is_null($if)) {
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
// Aruba devices can report ifAlias instead ifDescr
if (!$remote_port_id && !is_hex_string($if)) {
$query = 'SELECT `port_id` FROM `ports` WHERE `ifAlias` = ? AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $remote_device_id, 0]);
}
}
if (!$remote_port_id) {
if (!is_null($remote_mac)) {
// By MAC
$remote_port_id = get_port_id_by_mac($remote_device_id, $remote_mac);
} elseif (!is_null($if)) {
// Try by ifAlias
$query = 'SELECT `port_id` FROM `ports` WHERE `ifAlias` = ? AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $remote_device_id, 0]);
}
if (!$remote_port_id) {
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where)) {
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
}
}
}
$neighbour = [
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $cdp_entry['clcCdpApCacheNeighInterface'],
'remote_platform' => $cdp_entry['clcCdpApCachePlatform'],
'remote_version' => $cdp_entry['clcCdpApCacheNeighVersion'],
'remote_address' => $remote_address,
//'last_change' => $last_change
];
discover_neighbour($port, 'cdp', $neighbour);
}
}
// EOF

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
*
*/
@ -32,34 +32,37 @@ $dcp_array = snmp_cache_table($device, 'dcpLinkviewTable', [], $mib);
print_debug_vars($dcp_array);
foreach ($dcp_array as $ifIndex => $dcp) {
if ($dcp['dcpLinkviewLocalStatus'] !== 'up') { continue; }
if ($dcp['dcpLinkviewLocalStatus'] !== 'up') {
continue;
}
$port = get_port_by_index_cache($device, $ifIndex);
$port = get_port_by_index_cache($device, $ifIndex);
$remote_hostname = $dcp['dcpLinkviewRemoteHostname'];
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname)) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, NULL, 'DCP', '', $device, $port);
}
$remote_hostname = $dcp['dcpLinkviewRemoteHostname'];
// Try find a remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname)) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, NULL, 'DCP', '', $device, $port);
}
$remote_port_id = NULL;
if ($remote_device_id) {
$if = $dcp['dcpLinkviewRemoteName'];
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($if, $if, $if, $remote_device_id, 0));
}
$remote_port_id = NULL;
if ($remote_device_id) {
$if = $dcp['dcpLinkviewRemoteName'];
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
}
$neighbour = [
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $dcp['dcpLinkviewRemoteName'],
'remote_platform' => '',
'remote_version' => '',
];
discover_neighbour($port, 'dcp', $neighbour);
$neighbour = [
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $dcp['dcpLinkviewRemoteName'],
'remote_platform' => '',
'remote_version' => '',
];
discover_neighbour($port, 'dcp', $neighbour);
}
// 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
*
*/

View File

@ -6,10 +6,10 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
include("isdp-mib.inc.php");
include(__DIR__ . "/isdp-mib.inc.php");
// EOF

View File

@ -6,68 +6,60 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
$fdp_array = snmpwalk_cache_twopart_oid($device, "snFdpCacheEntry", [], "FOUNDRY-SN-SWITCH-GROUP-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
print_debug_vars($fdp_array);
if ($fdp_array)
{
foreach ($fdp_array as $ifIndex => $entry)
{
foreach ($fdp_array as $ifIndex => $entry) {
$port = get_port_by_index_cache($device, $ifIndex);
foreach ($entry as $fdp)
{
// Remote Hostname
$remote_hostname = $fdp['snFdpCacheDeviceId'];
foreach ($entry as $fdp) {
// Remote Hostname
$remote_hostname = $fdp['snFdpCacheDeviceId'];
// Remote address
$remote_address = hex2ip($fdp['snFdpCacheAddress']);
// Remote address
$remote_address = hex2ip($fdp['snFdpCacheAddress']);
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname, $remote_address);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname, $remote_address)) // Check all previous autodiscovery rounds
{
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, $remote_address, 'FDP', $fdp['snFdpCachePlatform'], $device, $port);
}
$remote_port_id = NULL;
$if = $fdp['snFdpCacheDevicePort'];
if ($remote_device_id)
{
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($if, $if, $if, $remote_device_id, 0));
if (!$remote_port_id)
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname, $remote_address);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname, $remote_address)) // Check all previous autodiscovery rounds
{
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where))
{
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, $remote_address, 'FDP', $fdp['snFdpCachePlatform'], $device, $port);
}
}
$neighbour = [
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $fdp['snFdpCacheDevicePort'],
'remote_platform' => $fdp['snFdpCachePlatform'],
'remote_version' => $fdp['snFdpCacheVersion'],
'remote_address' => $remote_address,
//'last_change' => $last_change
];
discover_neighbour($port, 'fdp', $neighbour);
$remote_port_id = NULL;
$if = $fdp['snFdpCacheDevicePort'];
if ($remote_device_id) {
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
if (!$remote_port_id) {
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where)) {
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
}
}
$neighbour = [
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $fdp['snFdpCacheDevicePort'],
'remote_platform' => $fdp['snFdpCachePlatform'],
'remote_version' => $fdp['snFdpCacheVersion'],
'remote_address' => $remote_address,
//'last_change' => $last_change
];
discover_neighbour($port, 'fdp', $neighbour);
}
}
}
// EOF

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
@ -14,80 +14,81 @@
$isdp_array = snmpwalk_cache_twopart_oid($device, 'agentIsdpCacheTable', [], $mib, NULL, OBS_SNMP_ALL_MULTILINE);
print_debug_vars($isdp_array);
if ($isdp_array) {
foreach ($isdp_array as $ifIndex => $port_neighbours) {
//$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ifIndex));
if (empty($isdp_array)) {
return;
}
foreach ($isdp_array as $ifIndex => $port_neighbours) {
$port = get_port_by_index_cache($device, $ifIndex);
foreach ($port_neighbours as $entry_id => $isdp) {
if (safe_empty($isdp['agentIsdpCacheDevicePort']) && safe_empty($isdp['agentIsdpCachePlatform']) &&
safe_empty($isdp['agentIsdpCacheAddress']) && safe_empty($isdp['agentIsdpCacheVersion'])) {
// All neighbour fields is empty, ignore
print_debug("Neighbour ignored: proto[isdp], ".$isdp['agentIsdpCacheDeviceId']);
continue;
}
// Normally not possible, but I keep this ability for search local port
if (!$port && strlen($isdp['agentIsdpCacheLocalIntf'])) {
$if = $isdp['agentIsdpCacheLocalIntf'];
$query = 'SELECT * FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$port = dbFetchRow($query, array($if, $if, $if, $device['device_id'], 0));
}
// Remote Hostname
list($isdp['agentIsdpCacheDeviceId']) = explode('(', $isdp['agentIsdpCacheDeviceId']); // Fix for Nexus ISDP neighbors: <hostname>(serial number)
$remote_hostname = trim($isdp['agentIsdpCacheDeviceId']);
// Remote address
$remote_address = hex2ip($isdp['agentIsdpCacheAddress']);
// Last change
$last_change = timeticks_to_sec($isdp['agentIsdpCacheLastChange']);
if ($last_change > 0)
{
$last_change = get_time() - $last_change;
}
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname, $remote_address);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname, $remote_address)) // Check all previous autodiscovery rounds
{
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, $remote_address, 'ISDP', $isdp['agentIsdpCachePlatform'], $device, $port);
}
$remote_port_id = NULL;
$if = $isdp['agentIsdpCacheDevicePort'];
if ($remote_device_id)
{
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($if, $if, $if, $remote_device_id, 0));
if (!$remote_port_id)
{
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where))
{
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
if (safe_empty($isdp['agentIsdpCacheDevicePort']) && safe_empty($isdp['agentIsdpCachePlatform']) &&
safe_empty($isdp['agentIsdpCacheAddress']) && safe_empty($isdp['agentIsdpCacheVersion'])) {
// All neighbour fields are empty, ignore
print_debug("Neighbour ignored: proto[isdp], " . $isdp['agentIsdpCacheDeviceId']);
continue;
}
}
$neighbour = [
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $isdp['agentIsdpCacheDevicePort'],
'remote_platform' => $isdp['agentIsdpCachePlatform'],
'remote_version' => $isdp['agentIsdpCacheVersion'],
'remote_address' => $remote_address,
'last_change' => $last_change
];
discover_neighbour($port, 'isdp', $neighbour);
// Normally not possible, but I keep this ability for search local port
if (!$port && !safe_empty($isdp['agentIsdpCacheLocalIntf'])) {
$if = $isdp['agentIsdpCacheLocalIntf'];
$query = 'SELECT * FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$port = dbFetchRow($query, [$if, $if, $if, $device['device_id'], 0]);
}
// Remote Hostname
if (str_contains($isdp['agentIsdpCacheDeviceId'], '(')) {
// Fix for Nexus ISDP neighbors: <hostname>(serial number)
$isdp['agentIsdpCacheDeviceId'] = explode('(', $isdp['agentIsdpCacheDeviceId'])[0];
}
$remote_hostname = trim($isdp['agentIsdpCacheDeviceId']);
// Remote address
$remote_address = hex2ip($isdp['agentIsdpCacheAddress']);
// Last change
$last_change = timeticks_to_sec($isdp['agentIsdpCacheLastChange']);
if ($last_change > 0) {
$last_change = get_time() - $last_change;
}
// Try to find a remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $remote_hostname, $remote_address);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($remote_hostname, $remote_address)) // Check all previous autodiscovery rounds
{
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($remote_hostname, $remote_address, 'ISDP', $isdp['agentIsdpCachePlatform'], $device, $port);
}
$remote_port_id = NULL;
$if = $isdp['agentIsdpCacheDevicePort'];
if ($remote_device_id) {
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
if (!$remote_port_id) {
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all ports with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $remote_address, $peer_where)) {
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
}
}
$neighbour = [
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $remote_hostname,
'remote_port' => $isdp['agentIsdpCacheDevicePort'],
'remote_platform' => $isdp['agentIsdpCachePlatform'],
'remote_version' => $isdp['agentIsdpCacheVersion'],
'remote_address' => $remote_address,
'last_change' => $last_change
];
discover_neighbour($port, 'isdp', $neighbour);
}
}
}
// EOF

View File

@ -6,140 +6,52 @@
*
* @package observium
* @subpackage discovery
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
// lldpRemoteSystemsData: lldpRemTable + lldpRemManAddrTable + lldpRemUnknownTLVTable + lldpRemOrgDefInfoTable
$lldpRemTable_oids = array('lldpRemChassisIdSubtype', 'lldpRemChassisId',
'lldpRemPortIdSubtype', 'lldpRemPortId', 'lldpRemPortDesc',
'lldpRemSysName');
$lldp_array = array();
foreach ($lldpRemTable_oids as $oid) {
//$lldp_array = snmpwalk_cache_threepart_oid($device, $oid, $lldp_array, "LLDP-MIB");
$lldp_array = snmpwalk_cache_oid($device, $oid, $lldp_array, "LLDP-MIB");
if (empty($lldp_array)) { break; } // Stop walk if no data
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemChassisIdSubtype', [], "LLDP-MIB");
if (empty($lldp_array)) {
return;
}
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemChassisId', $lldp_array, "LLDP-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemPortIdSubtype', $lldp_array, "LLDP-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemPortId', $lldp_array, "LLDP-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemSysName', $lldp_array, "LLDP-MIB");
if ($lldp_array) {
// lldpRemSysDesc can be multiline
//$lldp_array = snmpwalk_cache_threepart_oid($device, 'lldpRemPortDesc', $lldp_array, "LLDP-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
//$lldp_array = snmpwalk_cache_threepart_oid($device, 'lldpRemSysDesc', $lldp_array, "LLDP-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemSysDesc', $lldp_array, "LLDP-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
// lldpRemSysDesc can be multiline
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemPortDesc', $lldp_array, "LLDP-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemSysDesc', $lldp_array, "LLDP-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
if (is_device_mib($device, 'LLDP-EXT-MED-MIB')) {
if (is_device_mib($device, 'LLDP-EXT-MED-MIB')) {
// See Cumulus Linux
// not exist lldpRemSysName, lldpRemSysDesc
$lldp_array = snmpwalk_cache_oid($device, 'lldpXMedRemSoftwareRev', $lldp_array, "LLDP-EXT-MED-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
$lldp_array = snmpwalk_cache_oid($device, 'lldpXMedRemMfgName', $lldp_array, "LLDP-EXT-MED-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
$lldp_array = snmpwalk_cache_oid($device, 'lldpXMedRemModelNam', $lldp_array, "LLDP-EXT-MED-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
}
// lldpRemManAddrTable
// Case 1:
// LLDP-MIB::lldpRemManAddrSubtype.120.30001.1582.1.4.10.133.3.10 = INTEGER: ipV4(1)
// LLDP-MIB::lldpRemManAddr.120.30001.1582.1.4.10.133.3.10 = Hex-STRING: 0A 85 03 0A
// LLDP-MIB::lldpRemManAddrIfSubtype.120.30001.1582.1.4.10.133.3.10 = INTEGER: ifIndex(2)
// LLDP-MIB::lldpRemManAddrIfId.120.30001.1582.1.4.10.133.3.10 = INTEGER: 2009
// LLDP-MIB::lldpRemManAddrOID.120.30001.1582.1.4.10.133.3.10 = OID: SNMPv2-SMI::zeroDotZero.0
// Case 2:
// LLDP-MIB::lldpRemManAddrIfSubtype.1173570000.129.2.1.4.10.0.10.5 = INTEGER: unknown(1)
// LLDP-MIB::lldpRemManAddrIfSubtype.1173834000.4.6.0.6.132.181.156.89.235.128 = INTEGER: unknown(1)
// LLDP-MIB::lldpRemManAddrIfId.1173570000.129.2.1.4.10.0.10.5 = INTEGER: 0
// LLDP-MIB::lldpRemManAddrIfId.1173834000.4.6.0.6.132.181.156.89.235.128 = INTEGER: 0
// LLDP-MIB::lldpRemManAddrOID.1173570000.129.2.1.4.10.0.10.5 = OID: SNMPv2-SMI::enterprises.14823.2.2.1.2.1.1
// LLDP-MIB::lldpRemManAddrOID.1173834000.4.6.0.6.132.181.156.89.235.128 = OID: SNMPv2-SMI::enterprises.14823.2.2.1.2.1.7
// Case 3:
// LLDP-MIB::lldpRemManAddrIfId.0.2.1.1.4.10.137.41.4 = INTEGER: 0
// LLDP-MIB::lldpRemManAddrIfId.0.3.1.1.4.10.137.41.57 = INTEGER: 2009
// LLDP-MIB::lldpRemManAddrIfId.0.47.1.1.4.10.137.41.19 = INTEGER: 2009
// LLDP-MIB::lldpRemManAddrIfId.0.49.3.1.4.10.129.2.171 = INTEGER: 34
// LLDP-MIB::lldpRemManAddrIfId.0.49.3.2.16.42.2.32.40.255.0.0.0.0.0.0.1.0.0.1.113 = INTEGER: 34
// LLDP-MIB::lldpRemManAddrIfId.0.49.4.1.4.10.129.2.171 = INTEGER: 19
// LLDP-MIB::lldpRemManAddrIfId.0.49.4.2.16.42.2.32.40.255.0.0.0.0.0.0.1.0.0.1.113 = INTEGER: 19
// LLDP-MIB::lldpRemManAddrIfId.0.53.2.1.4.10.129.2.171 = INTEGER: 23
// LLDP-MIB::lldpRemManAddrIfId.0.53.2.2.16.42.2.32.40.255.0.0.0.0.0.0.1.0.0.1.113 = INTEGER: 23
// Case 4:
// LLDP-MIB::lldpRemManAddrSubtype.22 = INTEGER: ipV4(1)
// LLDP-MIB::lldpRemManAddrSubtype.86 = INTEGER: ipV6(2)
// LLDP-MIB::lldpRemManAddr.22 = STRING: "10.31.0.2"
// LLDP-MIB::lldpRemManAddr.86 = STRING: "fe80::d6ca:6dff:fe8e:8b3f"
// Case 5 (multiple IP addresses):
// lldpRemManAddrIfId.31300.2.2.1.4.192.168.13.1 = 5
// lldpRemManAddrIfId.31300.2.2.2.16.32.1.4.112.0.40.11.253.0.0.0.0.0.0.0.0 = 5
// lldpRemManAddrIfId.31300.2.2.2.16.254.128.0.0.0.0.0.0.198.173.52.255.254.216.108.126 = 5
$lldp_addr = snmpwalk_cache_oid($device, 'lldpRemManAddrIfId', [], "LLDP-MIB", NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
$lldp_addr = snmpwalk_cache_oid($device, 'lldpRemManAddr', $lldp_addr, "LLDP-MIB", NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
foreach ($lldp_addr as $index => $entry) {
if (isset($lldp_array[$index])) {
$lldp_array[$index] = array_merge($lldp_array[$index], $entry);
if (isset($entry['lldpRemManAddr'])) {
$addr = hex2ip($entry['lldpRemManAddr']);
$lldp_array[$index]['lldpRemMan'][$addr] = $entry; // For multiple entries
}
continue;
}
$index_array = explode('.', $index);
// LLDP index
$lldpRemTimeMark = array_shift($index_array);
$lldpRemLocalPortNum = array_shift($index_array);
$lldpRemIndex = array_shift($index_array);
$lldp_index = "$lldpRemTimeMark.$lldpRemLocalPortNum.$lldpRemIndex";
if (!isset($lldp_array[$lldp_index])) {
continue;
}
$lldp_array[$lldp_index] = array_merge($lldp_array[$lldp_index], $entry);
// Already exist Oid, just merge
// if (isset($entry['lldpRemManAddr']))
// {
// continue;
// }
// Convert from index part
$lldpAddressFamily = array_shift($index_array);
$len = array_shift($index_array);
$addr = implode('.', $index_array);
if (isset($entry['lldpRemManAddr'])) {
// Already exist Oid, just merge
$addr = hex2ip($entry['lldpRemManAddr']);
//continue;
} elseif ($lldpAddressFamily == 1 || $len == 4) {
// IPv4, ie: 4.10.129.2.171
$lldp_array[$lldp_index]['lldpRemManAddr'] = $addr;
} elseif ($lldpAddressFamily == 2 || $len == 16) {
// IPv6, ie: 16.42.2.32.40.255.0.0.0.0.0.0.1.0.0.1.113
$addr = snmp2ipv6($addr);
$lldp_array[$lldp_index]['lldpRemManAddr'] = $addr;
} elseif ($lldpAddressFamily == 0 && $len == 6) {
// Hrm, I really not know what is this, ie, seems as MAC address:
// 6 132.181.156.89.235.128 84:B5:9C:59:EB:80
continue;
}
$lldp_array[$lldp_index]['lldpRemMan'][$addr] = $entry; // For multiple entries
}
$lldp_array = snmpwalk_cache_oid($device, 'lldpXMedRemMfgName', $lldp_array, "LLDP-EXT-MED-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
$lldp_array = snmpwalk_cache_oid($device, 'lldpXMedRemModelNam', $lldp_array, "LLDP-EXT-MED-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
}
// lldpRemManAddrTable
fetch_oids_lldp_addr($device, $lldp_array);
print_debug_vars($lldp_array, 1);
if ($lldp_array) {
$dot1d_array = snmp_cache_table($device, "dot1dBasePortIfIndex", array(), "BRIDGE-MIB");
//$lldp_local_array = snmpwalk_cache_oid($device, "lldpLocalSystemData", array(), "LLDP-MIB");
$lldp_local_array = snmpwalk_cache_oid($device, "lldpLocPortEntry", array(), "LLDP-MIB");
$dot1d_array = snmp_cache_table($device, "dot1dBasePortIfIndex", [], "BRIDGE-MIB");
//$lldp_local_array = snmpwalk_cache_oid($device, "lldpLocalSystemData", [], "LLDP-MIB");
$lldp_local_array = snmpwalk_cache_oid($device, "lldpLocPortEntry", [], "LLDP-MIB");
foreach ($lldp_array as $index => $lldp) {
foreach ($lldp_array as $index => $lldp) {
if (str_contains_array($index, '.')) {
// This is correct RFC case:
// LLDP-MIB::lldpRemChassisIdSubtype.0.0.1 = INTEGER: macAddress(4)
list($lldpRemTimeMark, $lldpRemLocalPortNum, $lldpRemIndex) = explode('.', $index);
// This is correct RFC case:
// LLDP-MIB::lldpRemChassisIdSubtype.0.0.1 = INTEGER: macAddress(4)
[$lldpRemTimeMark, $lldpRemLocalPortNum, $lldpRemIndex] = explode('.', $index);
} else {
// Incorrect case (ie on old RouterOS):
// LLDP-MIB::lldpRemChassisIdSubtype.1495 = INTEGER: macAddress(4)
$lldpRemTimeMark = 0;
$lldpRemLocalPortNum = 0;
$lldpRemIndex = $index;
// Incorrect case (ie on old RouterOS):
// LLDP-MIB::lldpRemChassisIdSubtype.1495 = INTEGER: macAddress(4)
$lldpRemTimeMark = 0;
$lldpRemLocalPortNum = 0;
$lldpRemIndex = $index;
}
// Detect local device port
@ -147,80 +59,84 @@ if ($lldp_array) {
// Prefer by LLDP-MIB
if (!$port && !empty($lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortDesc'])) {
//lldpLocPortIdSubtype.15 = interfaceName
//lldpLocPortIdSubtype.16 = interfaceName
//lldpLocPortId.15 = "Te1/15"
//lldpLocPortId.16 = "Te1/16"
//lldpLocPortDesc.15 = TenGigabitEthernet1/15
//lldpLocPortDesc.16 = TenGigabitEthernet1/16
$ifName = $lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortDesc'];
if ($ifName === 'OOBM') {
// procurve:
// ifDescr.5481 = Out Of Band Management Port
// ifDescr.5492 = Out Of Band Management loopback Interface
// ifName.5481 = oobm0
// ifName.5492 = lo0
// lldpLocPortIdSubtype.4000 = local
// lldpLocPortId.4000 = "4000"
// lldpLocPortDesc.4000 = OOBM
$ifName .= '0';
}
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND (`ifName`= ? OR `ifDescr` = ? OR `port_label_short` = ?)", [ $device['device_id'], 0, $ifName, $ifName, $ifName ]);
//lldpLocPortIdSubtype.15 = interfaceName
//lldpLocPortIdSubtype.16 = interfaceName
//lldpLocPortId.15 = "Te1/15"
//lldpLocPortId.16 = "Te1/16"
//lldpLocPortDesc.15 = TenGigabitEthernet1/15
//lldpLocPortDesc.16 = TenGigabitEthernet1/16
$ifName = $lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortDesc'];
if ($ifName === 'OOBM') {
// procurve:
// ifDescr.5481 = Out Of Band Management Port
// ifDescr.5492 = Out Of Band Management loopback Interface
// ifName.5481 = oobm0
// ifName.5492 = lo0
// lldpLocPortIdSubtype.4000 = local
// lldpLocPortId.4000 = "4000"
// lldpLocPortDesc.4000 = OOBM
$ifName .= '0';
}
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND (`ifName`= ? OR `ifDescr` = ? OR `port_label_short` = ?)", [$device['device_id'], 0, $ifName, $ifName, $ifName]);
}
// By BRIDGE-MIB (Warning, seems as more hard on multiple platforms not correctly association with ifIndex for LLDP)
if (!$port && is_numeric($dot1d_array[$lldpRemLocalPortNum]['dot1dBasePortIfIndex']) &&
!in_array($device['os'], [ 'junos', 'dell-os10' ])) { // Incorrect association on this platforms
// Get the port using BRIDGE-MIB
$ifIndex = $dot1d_array[$lldpRemLocalPortNum]['dot1dBasePortIfIndex'];
!in_array($device['os'], [ 'junos', 'junos-evo', 'dell-os10' ])) { // Incorrect association on these platforms
// Gets the port using BRIDGE-MIB
$ifIndex = $dot1d_array[$lldpRemLocalPortNum]['dot1dBasePortIfIndex'];
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND `ifIndex` = ? AND `ifDescr` NOT LIKE 'Vlan%'", [ $device['device_id'], 0, $ifIndex ]);
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND `ifIndex` = ? AND `ifDescr` NOT LIKE 'Vlan%'", [$device['device_id'], 0, $ifIndex]);
}
// last try by lldpLocPortId, also see below for remote port
if (!$port) {
switch ($lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortIdSubtype']) {
case 'interfaceName':
$ifName = snmp_hexstring($lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortId']);
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?)", [ $device['device_id'], 0, $ifName, $ifName, $ifName ]);
break;
switch ($lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortIdSubtype']) {
case 'interfaceName':
$ifName = snmp_hexstring($lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortId']);
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?)", [$device['device_id'], 0, $ifName, $ifName, $ifName]);
break;
case 'interfaceAlias':
$ifAlias = snmp_hexstring($lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortId']);
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND `ifAlias` = ?", [ $device['device_id'], 0, $ifAlias ]);
break;
case 'interfaceAlias':
$ifAlias = snmp_hexstring($lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortId']);
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND `ifAlias` = ?", [$device['device_id'], 0, $ifAlias]);
break;
case 'macAddress':
$ifPhysAddress = strtolower(str_replace(' ', '', $lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortId']));
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND `ifPhysAddress` = ?", [ $device['device_id'], 0, $ifPhysAddress ]);
break;
case 'macAddress':
$ifPhysAddress = strtolower(str_replace(' ', '', $lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortId']));
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND `ifPhysAddress` = ?", [$device['device_id'], 0, $ifPhysAddress]);
break;
case 'networkAddress':
$ip = snmp_hexstring($lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortId']);
/*
$ip_version = get_ip_version($id);
if ($ip_version)
{
$ip = ($ip_version === 6 ? Net_IPv6::uncompress($id, TRUE) : $id);
$port = dbFetchRow("SELECT * FROM `ipv".$ip_version."_addresses` LEFT JOIN `ports` USING (`port_id`) WHERE `ipv".$ip_version."_address` = ? AND `device_id` = ?", array($ip, $device['device_id']));
}
unset($id, $ip);
*/
$peer_where = generate_query_values_and($device['device_id'], 'device_id'); // Additional filter for include self IPs
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $ip, $peer_where)) {
$port = get_port_by_id_cache($ids[0]);
}
case 'networkAddress':
$ip = snmp_hexstring($lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortId']);
/*
$ip_version = get_ip_version($id);
if ($ip_version)
{
$ip = ($ip_version === 6 ? Net_IPv6::uncompress($id, TRUE) : $id);
$port = dbFetchRow("SELECT * FROM `ipv".$ip_version."_addresses` LEFT JOIN `ports` USING (`port_id`) WHERE `ipv".$ip_version."_address` = ? AND `device_id` = ?", array($ip, $device['device_id']));
}
unset($id, $ip);
*/
$peer_where = generate_query_values_and($device['device_id'], 'device_id'); // Additional filter for include self IPs
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $ip, $peer_where)) {
$port = get_port_by_id_cache($ids[0]);
}
break;
}
break;
}
}
// Ohh still unknown port? this is not should happen, but this derp LLDP implementation on your device
if (!$port && is_numeric($lldpRemLocalPortNum)) {
print_debug('WARNING. Local port for neighbour not found, used incorrect lldpRemLocalPortNum as ifIndex.');
$ifIndex = $lldpRemLocalPortNum; // This is incorrect, not really ifIndex, but seems sometime this numbers same
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND `ifIndex` = ? AND `ifDescr` NOT LIKE 'Vlan%'", [ $device['device_id'], 0, $ifIndex ]);
print_debug('WARNING. Local port for neighbour not found, used incorrect lldpRemLocalPortNum as ifIndex.');
$ifIndex = $lldpRemLocalPortNum; // This is incorrect, not really ifIndex, but seems sometime this numbers same
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND `ifIndex` = ? AND `ifDescr` NOT LIKE 'Vlan%'", [$device['device_id'], 0, $ifIndex]);
if (!$port && $device['os'] === 'ciena-waveserveros') {
$ifName = 'PORT-' . snmp_hexstring($lldp_local_array[$lldpRemLocalPortNum]['lldpLocPortId']);
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?)", [$device['device_id'], 0, $ifName, $ifName, $ifName]);
}
}
$remote_device_id = FALSE;
@ -228,59 +144,28 @@ if ($lldp_array) {
// Sometime lldpRemPortDesc is not set
if (!isset($lldp['lldpRemPortDesc'])) {
$lldp['lldpRemPortDesc'] = '';
$lldp['lldpRemPortDesc'] = '';
}
$remote_mac = $lldp['lldpRemChassisIdSubtype'] === 'macAddress' ? $lldp['lldpRemChassisId'] : NULL;
// lldpRemPortId can be hex string
if ($lldp['lldpRemPortIdSubtype'] !== 'macAddress') {
// On Extreme platforms, they remove the leading 1: from ports. Put it back if there isn't a :.
if (preg_match ('/^ExtremeXOS.*$/', $lldp['lldpRemSysDesc'])) {
if (!preg_match ('/\:/',$lldp['lldpRemPortId'])) {
$lldp['lldpRemPortId'] = '1:'.$lldp['lldpRemPortId'];
// On Extreme platforms, they remove the leading 1: from ports. Put it back if there isn't a :.
if (preg_match('/^ExtremeXOS.*$/', $lldp['lldpRemSysDesc'])) {
if (!preg_match('/\:/', $lldp['lldpRemPortId'])) {
$lldp['lldpRemPortId'] = '1:' . $lldp['lldpRemPortId'];
}
} else {
//$lldp['lldpRemPortId'] = snmp_hexstring($lldp['lldpRemPortId']);
}
} else {
//$lldp['lldpRemPortId'] = snmp_hexstring($lldp['lldpRemPortId']);
}
} elseif (safe_empty($remote_mac)) {
$remote_mac = $lldp['lldpRemPortId'];
}
// Clean MAC & IP
if (isset($lldp['lldpRemMan']) && count($lldp['lldpRemMan']) > 1) {
// Multiple IP addresses.. detect best?
foreach (array_keys($lldp['lldpRemMan']) as $addr) {
$addr_version = get_ip_version($addr);
$addr_type = get_ip_type($addr);
if (in_array($addr_type, [ 'unspecified', 'loopback', 'reserved', 'multicast' ])) {
continue;
}
if ($addr_version == 6 && $addr_type === 'link-local') {
continue;
}
if ($addr_type === 'unicast') {
// Prefer IPv4/IPv6 unicast
$lldp['lldpRemManAddr'] = $addr;
break;
}
if ($addr_version == 4) {
// Than prefer IPv4
$lldp['lldpRemManAddr'] = $addr;
break;
}
$lldp['lldpRemManAddr'] = $addr;
}
print_debug("Multiple remote IP addresses detect, selected: $addr");
print_debug_vars($lldp);
}
if (isset($lldp['lldpRemManAddr'])) {
$lldp['lldpRemManAddr'] = hex2ip($lldp['lldpRemManAddr']);
$remote_mac = $lldp['lldpRemPortId'];
}
// Cumulus Linux have empty lldpRemSysDesc
if (!isset($lldp['lldpRemSysDesc']) && isset($lldp['lldpXMedRemModelName'])) {
$lldp['lldpRemSysDesc'] = trim($lldp['lldpXMedRemMfgName'] . ' ' . $lldp['lldpXMedRemModelName']);
$lldp['lldpRemSysDesc'] = trim($lldp['lldpXMedRemMfgName'] . ' ' . $lldp['lldpXMedRemModelName']);
}
$lldp['lldpRemSysVersion'] = safe_empty($lldp['lldpXMedRemSoftwareRev']) ? NULL : $lldp['lldpXMedRemSoftwareRev'];
@ -292,147 +177,138 @@ if ($lldp_array) {
// lldpRemSysName.0.16.1 = 40:e3:d6:ce:8a:9a
// lldpRemManAddrIfId.0.16.1.1.4.10.10.14.132 = 8
if (preg_match('/^[a-f\d]{2}([: ][a-f\d]{2}){5}$/', $lldp['lldpRemSysName']) && get_ip_version($lldp['lldpRemManAddr'])) {
// Replace by IP address for better discovery
print_debug("LLDP hostname replaced: ".$lldp['lldpRemSysName']." -> ".$lldp['lldpRemManAddr']);
$lldp['lldpRemSysName'] = $lldp['lldpRemManAddr'];
// Replace by IP address for better discovery
print_debug("LLDP hostname replaced: " . $lldp['lldpRemSysName'] . " -> " . $lldp['lldpRemManAddr']);
$lldp['lldpRemSysName'] = $lldp['lldpRemManAddr'];
} elseif (safe_empty($lldp['lldpRemSysName']) && !safe_empty($lldp['lldpRemSysDesc'])) {
if ($lldp['lldpRemChassisIdSubtype'] === 'macAddress') {
// use mac address instead empty hostname:
// lldpRemChassisIdSubtype.89.3.1 = macAddress
// lldpRemChassisId.89.3.1 = "6C B0 CE 12 A9 A8 "
// lldpRemPortIdSubtype.89.3.1 = local
// lldpRemPortId.89.3.1 = "g25"
// lldpRemPortDesc.89.3.1 = g25
// lldpRemSysName.89.3.1 =
// lldpRemSysDesc.89.3.1 = GS724Tv4 ProSafe 24-port Gigabit Ethernet Smart Switch, 6.3.1.4, B1.0.0.4
// lldpRemManAddrIfId.89.3.1.1.4.192.168.0.239 = 51
$lldp['lldpRemSysName'] = str_replace(array( ' ', '-' ), '', strtolower($lldp['lldpRemChassisId']));
} elseif ($lldp['lldpRemChassisIdSubtype'] === 'networkAddress' &&
preg_match('/^01 (?<ip>([A-F\d]{2}\s?){4})$/', $lldp['lldpRemChassisId'], $matches)) {
$lldp['lldpRemSysName'] = hex2ip($matches['ip']);
}
if ($lldp['lldpRemChassisIdSubtype'] === 'macAddress') {
// use mac address instead empty hostname:
// lldpRemChassisIdSubtype.89.3.1 = macAddress
// lldpRemChassisId.89.3.1 = "6C B0 CE 12 A9 A8 "
// lldpRemPortIdSubtype.89.3.1 = local
// lldpRemPortId.89.3.1 = "g25"
// lldpRemPortDesc.89.3.1 = g25
// lldpRemSysName.89.3.1 =
// lldpRemSysDesc.89.3.1 = GS724Tv4 ProSafe 24-port Gigabit Ethernet Smart Switch, 6.3.1.4, B1.0.0.4
// lldpRemManAddrIfId.89.3.1.1.4.192.168.0.239 = 51
$lldp['lldpRemSysName'] = str_replace([' ', '-'], '', strtolower($lldp['lldpRemChassisId']));
} elseif ($lldp['lldpRemChassisIdSubtype'] === 'networkAddress' &&
preg_match('/^01 (?<ip>([A-F\d]{2}\s?){4})$/', $lldp['lldpRemChassisId'], $matches)) {
$lldp['lldpRemSysName'] = hex2ip($matches['ip']);
}
}
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $lldp['lldpRemSysName'], $lldp['lldpRemManAddr'], $remote_mac);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($lldp['lldpRemSysName'], $lldp['lldpRemManAddr'])) // Check all previous autodiscovery rounds
{
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($lldp['lldpRemSysName'], $lldp['lldpRemManAddr'], 'LLDP', $lldp['lldpRemSysDesc'], $device, $port);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($lldp['lldpRemSysName'], $lldp['lldpRemManAddr'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($lldp['lldpRemSysName'], $lldp['lldpRemManAddr'], 'LLDP', $lldp['lldpRemSysDesc'], $device, $port);
}
if ($remote_device_id) {
$if = $lldp['lldpRemPortDesc'];
$id = trim($lldp['lldpRemPortId']);
$if = $lldp['lldpRemPortDesc'];
$id = trim($lldp['lldpRemPortId']);
// lldpPortIdSubtype -> lldpPortId
// interfaceAlias(1), -> ifAlias
// portComponent(2), -> entPhysicalAlias
// macAddress(3), -> ifPhysAddress
// networkAddress(4), -> IP address
// interfaceName(5), -> ifName
// agentCircuitId(6), -> agent-local identifier of the circuit (defined in RFC 3046) (FIXME, not know)
// local(7) -> ifIndex
switch ($lldp['lldpRemPortIdSubtype'])
{
case 'interfaceAlias':
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifAlias` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?", [ $id, $if, $if, $remote_device_id, 0 ]);
break;
// lldpPortIdSubtype -> lldpPortId
// interfaceAlias(1), -> ifAlias
// portComponent(2), -> entPhysicalAlias
// macAddress(3), -> ifPhysAddress
// networkAddress(4), -> IP address
// interfaceName(5), -> ifName
// agentCircuitId(6), -> agent-local identifier of the circuit (defined in RFC 3046) (FIXME, not know)
// local(7) -> ifIndex
switch ($lldp['lldpRemPortIdSubtype']) {
case 'interfaceAlias':
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifAlias` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?", [$id, $if, $if, $remote_device_id, 0]);
break;
case 'interfaceName':
// Try lldpRemPortId
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($id, $id, $id, $remote_device_id, 0));
if (!$remote_port_id && !safe_empty($if)) {
// Try same by lldpRemPortDesc
$remote_port_id = dbFetchCell($query, array($if, $if, $if, $remote_device_id, 0));
}
break;
case 'interfaceName':
// Try lldpRemPortId
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$id, $id, $id, $remote_device_id, 0]);
if (!$remote_port_id && !safe_empty($if)) {
// Try same by lldpRemPortDesc
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
}
break;
case 'macAddress':
$remote_port_id = get_port_id_by_mac($remote_device_id, $id);
if (!$remote_port_id && !safe_empty($if)) {
// Try same by lldpRemPortDesc
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [ $if, $if, $if, $remote_device_id, 0 ]);
}
break;
case 'macAddress':
$remote_port_id = get_port_id_by_mac($remote_device_id, $id);
if (!$remote_port_id && !safe_empty($if)) {
// Try same by lldpRemPortDesc
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
}
break;
case 'networkAddress':
$ip_version = get_ip_version($id);
if ($ip_version)
{
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $id, $peer_where))
{
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
}
break;
case 'networkAddress':
$ip_version = get_ip_version($id);
if ($ip_version) {
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $id, $peer_where)) {
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
}
break;
case 'local':
// local not always ifIndex or FIXME (see: http://jira.observium.org/browse/OBSERVIUM-1716)
if (!ctype_digit($id))
{
// Not sure what should be if $id ifName and it just numeric
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($id, $id, $id, $remote_device_id, 0));
if (!$remote_port_id)
{
// Try same by lldpRemPortDesc
$remote_port_id = dbFetchCell($query, array($if, $if, $if, $remote_device_id, 0));
}
}
case 'ifIndex':
// These cases are handled by the ifDescr/ifIndex combination fallback below
break;
case 'local':
// local not always ifIndex or FIXME (see: http://jira.observium.org/browse/OBSERVIUM-1716)
if (!ctype_digit($id)) {
// Not sure what should be if $id ifName and it just numeric
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$id, $id, $id, $remote_device_id, 0]);
if (!$remote_port_id) {
// Try same by lldpRemPortDesc
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
}
}
case 'ifIndex':
// These cases are handled by the ifDescr/ifIndex combination fallback below
break;
default:
break;
}
if (!$remote_port_id && is_numeric($id)) // Not found despite our attempts above - fall back to try matching with ifDescr/ifIndex
{
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifIndex`= ? OR `ifDescr` = ?) AND `device_id` = ? AND `deleted` = ?", array($id, $if, $remote_device_id, 0));
}
if (!$remote_port_id) // Still not found?
{
if ($lldp['lldpRemChassisIdSubtype'] === 'macAddress')
{
// Find the port by chassis MAC address, only use this if exactly 1 match is returned, otherwise we'd link wrongly - think switches with 1 global MAC on all ports.
$remote_port_id = get_port_id_by_mac($remote_device_id, $lldp['lldpRemChassisId']);
} else {
// Last chance
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` IN (?, ?) OR `ifDescr` IN (?, ?) OR `port_label_short` IN (?, ?)) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, array($id, $if, $id, $if, $id, $if, $remote_device_id, 0));
default:
break;
}
}
// Still not found? Seems as incorrect remote device :/
if (!$remote_port_id)
{
print_debug("WARNING. Remote device found in db, but remote port not found. Seems as incorrect remote device association.");
}
if (!$remote_port_id && is_numeric($id)) {
// Not found despite our attempts above - fall back to try matching with ifDescr/ifIndex
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifIndex`= ? OR `ifDescr` = ?) AND `device_id` = ? AND `deleted` = ?", [$id, $if, $remote_device_id, 0]);
}
if (!$remote_port_id) { // Still not found?
if ($lldp['lldpRemChassisIdSubtype'] === 'macAddress') {
// Find the port by chassis MAC address, only use this if exactly 1 match is returned, otherwise we'd link wrongly - think switches with 1 global MAC on all ports.
$remote_port_id = get_port_id_by_mac($remote_device_id, $lldp['lldpRemChassisId']);
} else {
// Last chance
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` IN (?, ?) OR `ifDescr` IN (?, ?) OR `port_label_short` IN (?, ?)) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$id, $if, $id, $if, $id, $if, $remote_device_id, 0]);
}
}
// Still not found? Seems as incorrect remote device :/
if (!$remote_port_id) {
print_debug("WARNING. Remote device found in db, but remote port not found. Seems as incorrect remote device association.");
}
}
// FIXME. We can use lldpRemSysCapEnabled as platform, but they use BITS textual conversion:
// LLDP-MIB::lldpRemSysCapEnabled.0.5.3 = BITS: 20 00 bridge(2)
// LLDP-MIB::lldpRemSysCapEnabled.0.5.3 = "20 00 "
$neighbour = [
'remote_port_id' => $remote_port_id,
'remote_hostname' => $lldp['lldpRemSysName'],
'remote_port' => $lldp['lldpRemPortId'],
'remote_platform' => $lldp['lldpRemSysDesc'],
'remote_version' => $lldp['lldpRemSysVersion'], //NULL,
'remote_address' => $lldp['lldpRemManAddr']
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $lldp['lldpRemSysName'],
'remote_port' => $lldp['lldpRemPortId'],
'remote_platform' => $lldp['lldpRemSysDesc'],
'remote_version' => $lldp['lldpRemSysVersion'], //NULL,
'remote_address' => $lldp['lldpRemManAddr']
];
discover_neighbour($port, 'lldp', $neighbour);
}
}
// EOF

View File

@ -0,0 +1,307 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
$lldp_array = snmpwalk_cache_oid($device, 'lldpV2RemChassisIdSubtype', [], "LLDP-V2-MIB");
if (empty($lldp_array)) {
return;
}
$lldp_array = snmpwalk_cache_oid($device, 'lldpV2RemChassisId', $lldp_array, "LLDP-V2-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'lldpV2RemPortIdSubtype', $lldp_array, "LLDP-V2-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'lldpV2RemPortId', $lldp_array, "LLDP-V2-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'lldpV2RemSysName', $lldp_array, "LLDP-V2-MIB");
// lldpV2RemSysDesc can be multiline
$lldp_array = snmpwalk_cache_oid($device, 'lldpV2RemPortDesc', $lldp_array, "LLDP-V2-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
$lldp_array = snmpwalk_cache_oid($device, 'lldpV2RemSysDesc', $lldp_array, "LLDP-V2-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
/*
if (is_device_mib($device, 'LLDP-EXT-MED-MIB')) {
// See Cumulus Linux
// not exist lldpRemSysName, lldpRemSysDesc
$lldp_array = snmpwalk_cache_oid($device, 'lldpXMedRemSoftwareRev', $lldp_array, "LLDP-EXT-MED-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
$lldp_array = snmpwalk_cache_oid($device, 'lldpXMedRemMfgName', $lldp_array, "LLDP-EXT-MED-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
$lldp_array = snmpwalk_cache_oid($device, 'lldpXMedRemModelNam', $lldp_array, "LLDP-EXT-MED-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
}
*/
// lldpV2RemManAddrTable
$lldp_addr = snmpwalk_cache_oid($device, 'lldpV2RemManAddrIfId', [], "LLDP-V2-MIB", NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
$lldp_addr = snmpwalk_cache_oid($device, 'lldpV2RemManAddrIfSubtype', $lldp_addr, "LLDP-V2-MIB", NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
print_debug_vars($lldp_addr);
foreach ($lldp_addr as $index => $entry) {
/*
if (isset($lldp_array[$index])) {
$lldp_array[$index] = array_merge($lldp_array[$index], $entry);
if (isset($entry['lldpRemManAddr'])) {
$addr = hex2ip($entry['lldpRemManAddr']);
$lldp_array[$index]['lldpRemMan'][$addr] = $entry; // For multiple entries
}
continue;
}
*/
$index_array = explode('.', $index, 7);
// LLDP index
[ $lldpV2RemTimeMark, $lldpV2RemLocalIfIndex, $lldpV2RemLocalDestMACAddress, $lldpV2RemIndex, // LLDP index
$lldpV2RemManAddrIndex, $len, $addr ] = $index_array; // Addr index
$lldp_index = "$lldpV2RemTimeMark.$lldpV2RemLocalIfIndex.$lldpV2RemLocalDestMACAddress.$lldpV2RemIndex";
if (!isset($lldp_array[$lldp_index])) {
continue;
}
//$lldp_array[$lldp_index] = array_merge($lldp_array[$lldp_index], $entry);
// Already exist Oid, just merge
// if (isset($entry['lldpRemManAddr']))
// {
// continue;
// }
// Convert from index part
$entry['lldpV2RemManAddrIndex'] = $lldpV2RemManAddrIndex;
switch ($len) {
case 4:
// IPv4, ie: 4.10.129.2.171
$lldp_array[$lldp_index]['lldpV2RemManAddr'] = $addr;
break;
case 16:
// IPv6, ie: 16.42.2.32.40.255.0.0.0.0.0.0.1.0.0.1.113
$addr = snmp2ipv6($addr);
$lldp_array[$lldp_index]['lldpV2RemManAddr'] = $addr;
break;
default:
// Unknown
}
$lldp_array[$lldp_index]['lldpV2RemMan'][$addr] = $entry; // For multiple entries
}
print_debug_vars($lldp_array, 1);
//$dot1d_array = snmp_cache_table($device, "dot1dBasePortIfIndex", [], "BRIDGE-MIB");
//$lldp_local_array = snmpwalk_cache_oid($device, "lldpLocalSystemData", array(), "LLDP-MIB");
// not used?
//$lldp_local_array = snmpwalk_cache_oid($device, "lldpV2LocPortEntry", [], "LLDP-V2-MIB");
foreach ($lldp_array as $index => $lldp) {
[ $lldpV2RemTimeMark, $lldpV2RemLocalIfIndex, $lldpV2RemLocalDestMACAddress, $lldpV2RemIndex ] = explode('.', $index);
// Detect local device port
$port = NULL;
// Prefer by LLDP-MIB
//if (!$port && isset($lldp_local_array[$lldpV2RemLocalIfIndex])) {
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND `ifIndex` = ? AND `ifDescr` NOT LIKE 'Vlan%'", [$device['device_id'], 0, $lldpV2RemLocalIfIndex]);
//}
// Detect remote device and port
$remote_device_id = FALSE;
$remote_port_id = NULL;
// Sometime lldpV2RemPortDesc is not set
if (!isset($lldp['lldpV2RemPortDesc'])) {
$lldp['lldpV2RemPortDesc'] = '';
}
$remote_mac = $lldp['lldpV2RemChassisIdSubtype'] === 'macAddress' ? $lldp['lldpV2RemChassisId'] : NULL;
// lldpV2RemPortId can be hex string
if ($lldp['lldpV2RemPortIdSubtype'] !== 'macAddress') {
if (str_contains($lldp['lldpV2RemPortId'], ':')) {
$tmp = str_replace(':', ' ', $lldp['lldpV2RemPortId']);
$rem_port_id = snmp_hexstring($tmp);
if ($tmp != $rem_port_id) {
$lldp['lldpV2RemPortId'] = $rem_port_id;
print_debug("lldpV2RemPortId decoded: '$tmp' -> '$rem_port_id'");
}
unset($tmp, $rem_port_id);
}
// On Extreme platforms, they remove the leading 1: from ports. Put it back if there isn't a :.
if (preg_match('/^ExtremeXOS.*$/', $lldp['lldpV2RemSysDesc'])) {
if (!preg_match('/\:/', $lldp['lldpV2RemPortId'])) {
$lldp['lldpV2RemPortId'] = '1:' . $lldp['lldpV2RemPortId'];
}
} else {
//$lldp['lldpV2RemPortId'] = snmp_hexstring($lldp['lldpV2RemPortId']);
}
} elseif (safe_empty($remote_mac)) {
$remote_mac = $lldp['lldpV2RemPortId'];
}
// Clean MAC & IP
if (safe_count($lldp['lldpV2RemMan']) > 1) {
// Multiple IP addresses.. detect best?
foreach (array_keys($lldp['lldpV2RemMan']) as $addr) {
$addr_version = get_ip_version($addr);
$addr_type = get_ip_type($addr);
if (in_array($addr_type, ['unspecified', 'loopback', 'reserved', 'multicast'])) {
continue;
}
if ($addr_version == 6 && $addr_type === 'link-local') {
continue;
}
if ($addr_type === 'unicast') {
// Prefer IPv4/IPv6 unicast
$lldp['lldpV2RemManAddr'] = $addr;
break;
}
if ($addr_version == 4) {
// Then prefer IPv4
$lldp['lldpV2RemManAddr'] = $addr;
break;
}
$lldp['lldpV2RemManAddr'] = $addr;
}
print_debug("Multiple remote IP addresses detect, selected: $addr");
print_debug_vars($lldp);
}
if (isset($lldp['lldpV2RemManAddr'])) {
$lldp['lldpV2RemManAddr'] = hex2ip($lldp['lldpV2RemManAddr']);
}
// Remote sysname is MAC in some cases
if (preg_match('/^[a-f\d]{2}([: ][a-f\d]{2}){5}$/', $lldp['lldpV2RemSysName']) && get_ip_version($lldp['lldpV2RemManAddr'])) {
// Replace by IP address for better discovery
print_debug("LLDP hostname replaced: " . $lldp['lldpV2RemSysName'] . " -> " . $lldp['lldpV2RemManAddr']);
$lldp['lldpV2RemSysName'] = $lldp['lldpV2RemManAddr'];
} elseif (safe_empty($lldp['lldpV2RemSysName']) && !safe_empty($lldp['lldpV2RemSysDesc'])) {
if ($lldp['lldpV2RemChassisIdSubtype'] === 'macAddress') {
// use mac address instead empty hostname:
$lldp['lldpV2RemSysName'] = str_replace([' ', '-'], '', strtolower($lldp['lldpV2RemChassisId']));
} elseif ($lldp['lldpV2RemChassisIdSubtype'] === 'networkAddress' &&
preg_match('/^01 (?<ip>([A-F\d]{2}\s?){4})$/', $lldp['lldpV2RemChassisId'], $matches)) {
$lldp['lldpV2RemSysName'] = hex2ip($matches['ip']);
}
}
// Try to find a remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $lldp['lldpV2RemSysName'], $lldp['lldpV2RemManAddr'], $remote_mac);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($lldp['lldpV2RemSysName'], $lldp['lldpV2RemManAddr'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($lldp['lldpV2RemSysName'], $lldp['lldpV2RemManAddr'], 'LLDP', $lldp['lldpV2RemSysDesc'], $device, $port);
}
if ($remote_device_id) {
$if = $lldp['lldpV2RemPortDesc'];
$id = trim($lldp['lldpV2RemPortId']);
// lldpPortIdSubtype -> lldpPortId
// interfaceAlias(1), -> ifAlias
// portComponent(2), -> entPhysicalAlias
// macAddress(3), -> ifPhysAddress
// networkAddress(4), -> IP address
// interfaceName(5), -> ifName
// agentCircuitId(6), -> agent-local identifier of the circuit (defined in RFC 3046) (FIXME, not know)
// local(7) -> ifIndex
switch ($lldp['lldpV2RemPortIdSubtype']) {
case 'interfaceAlias':
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifAlias` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?", [ $id, $if, $if, $remote_device_id, 0 ]);
break;
case 'interfaceName':
// Try lldpRemPortId
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [ $id, $id, $id, $remote_device_id, 0 ]);
if (!$remote_port_id && !safe_empty($if)) {
// Try the same by lldpRemPortDesc
$remote_port_id = dbFetchCell($query, [ $if, $if, $if, $remote_device_id, 0 ]);
}
break;
case 'macAddress':
$remote_port_id = get_port_id_by_mac($remote_device_id, $id);
if (!$remote_port_id && !safe_empty($if)) {
// Try the same by lldpRemPortDesc
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [ $if, $if, $if, $remote_device_id, 0 ]);
}
break;
case 'networkAddress':
$ip_version = get_ip_version($id);
if ($ip_version) {
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $id, $peer_where)) {
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
}
break;
case 'local':
// local not always ifIndex or FIXME (see: http://jira.observium.org/browse/OBSERVIUM-1716)
if (!ctype_digit($id)) {
// Not sure what should be if $id ifName and it just numeric
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [ $id, $id, $id, $remote_device_id, 0 ]);
if (!$remote_port_id) {
// Try the same by lldpRemPortDesc
$remote_port_id = dbFetchCell($query, [ $if, $if, $if, $remote_device_id, 0 ]);
}
}
case 'ifIndex':
// These cases are handled by the ifDescr/ifIndex combination fallback below
break;
default:
break;
}
if (!$remote_port_id && is_numeric($id)) { // Not found despite our attempts above - fall back to try matching with ifDescr/ifIndex
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifIndex`= ? OR `ifDescr` = ?) AND `device_id` = ? AND `deleted` = ?", [ $id, $if, $remote_device_id, 0 ]);
}
if (!$remote_port_id) { // Still not found?
if ($lldp['lldpV2RemChassisIdSubtype'] === 'macAddress') {
// Find the port by chassis MAC address, only use this if exactly 1 match is returned, otherwise we'd link wrongly - think switches with 1 global MAC on all ports.
$remote_port_id = get_port_id_by_mac($remote_device_id, $lldp['lldpV2RemChassisId']);
} else {
// Last chance
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` IN (?, ?) OR `ifDescr` IN (?, ?) OR `port_label_short` IN (?, ?)) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [ $id, $if, $id, $if, $id, $if, $remote_device_id, 0 ]);
}
}
// Still not found? Seems as an incorrect remote device :/
if (!$remote_port_id) {
print_debug("WARNING. Remote device found in db, but remote port not found. Seems as incorrect remote device association.");
}
}
$valid_host_key = $lldp['lldpV2RemSysName'];
if (strlen($lldp['lldpV2RemManAddr'])) {
$valid_host_key .= '-' . $lldp['lldpV2RemManAddr'];
}
if ($GLOBALS['valid']['neighbours'][$port['port_id']][$valid_host_key][$lldp['lldpV2RemPortId']]) {
print_warning("Neighbour already discovered by LLDP-MIB. Skip..");
continue;
}
// FIXME. We can use lldpRemSysCapEnabled as platform, but they use BITS textual conversion:
// LLDP-MIB::lldpRemSysCapEnabled.0.5.3 = BITS: 20 00 bridge(2)
// LLDP-MIB::lldpRemSysCapEnabled.0.5.3 = "20 00 "
$neighbour = [
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $lldp['lldpV2RemSysName'],
'remote_port' => $lldp['lldpV2RemPortId'],
'remote_platform' => $lldp['lldpV2RemSysDesc'],
'remote_version' => NULL,
'remote_address' => $lldp['lldpV2RemManAddr']
];
discover_neighbour($port, 'lldp', $neighbour);
}
// 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
*
*/
@ -44,34 +44,46 @@ LLDP-MIB:
[lldpRemSysDesc] => string(0) ""
)
*/
$mtxr_array = snmpwalk_cache_oid($device, "mtxrNeighbor", array(), "MIKROTIK-MIB", NULL, OBS_SNMP_ALL | OBS_SNMP_CONCAT);
$mtxr_array = snmpwalk_cache_oid($device, "mtxrNeighbor", [], "MIKROTIK-MIB", NULL, OBS_SNMP_ALL | OBS_SNMP_CONCAT);
if ($mtxr_array)
{
print_debug_vars($mtxr_array);
if (safe_empty($mtxr_array)) {
return;
}
// Extend remote port names by discovery in LLDP-MIB (but do not use this MIB self, mikrotik not reports local port there)
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemChassisId', [], "LLDP-MIB");
if (snmp_status())
{
// Extend remote port names by discovery in LLDP-MIB (but do not use this MIB self, mikrotik not reports local port there)
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemChassisId', [], "LLDP-MIB");
if (snmp_status()) {
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemPortIdSubtype', $lldp_array, "LLDP-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemPortId', $lldp_array, "LLDP-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'lldpRemSysDesc', $lldp_array, "LLDP-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
print_debug_vars($lldp_array);
}
foreach ($mtxr_array as $key => $entry)
{
if (isset($lldp_array[$key]))
{
// older fw versions
$entry = array_merge($entry, $lldp_array[$key]);
}
elseif (isset($lldp_array['0.0.'.$key]))
{
// latest fw versions
$entry = array_merge($entry, $lldp_array['0.0.'.$key]);
// lldpRemManAddrTable
fetch_oids_lldp_addr($device, $lldp_array);
print_debug_vars($lldp_array, 1);
// Merge LLDP to MNDP
foreach ($lldp_array as $lldp_key => $lldp) {
$mtxr_key = end(explode('.', $lldp_key));
if (isset($mtxr_array[$lldp_key])) {
// older fw versions
$mtxr_array[$lldp_key] = array_merge($mtxr_array[$lldp_key], $lldp);
print_debug("MNDP associated with LLDP: $lldp_key -> $lldp_key");
} elseif (isset($mtxr_array[$mtxr_key])) { // $lldp_key === '0.0.' . $mtxr_key) {
// latest fw versions
//$entry = array_merge($entry, $lldp_array['0.0.' . $key]);
$mtxr_array[$mtxr_key] = array_merge($mtxr_array[$mtxr_key], $lldp);
print_debug("MNDP associated with LLDP: $mtxr_key -> $lldp_key");
} elseif (str_ends_with($lldp_key, ".$mtxr_key")) {
print_debug("MNDP association with LLDP not found : $mtxr_key -> $lldp_key");
}
}
}
print_debug_vars($mtxr_array);
unset($lldp_array);
foreach ($mtxr_array as $key => $entry) {
// Need to straighten out the MAC first for use later. Mikrotik does not pad the numbers! (i.e. 0:12:23:3:5c:6b)
//$remote_mac = mac_zeropad($entry['mtxrNeighborMacAddress']);
@ -79,7 +91,7 @@ if ($mtxr_array)
// Note, mtxrNeighborInterfaceID really hex number, ie:
// mtxrNeighborInterfaceID.1 = a
$ifIndex = hexdec($entry['mtxrNeighborInterfaceID']);
$ifIndex = hexdec($entry['mtxrNeighborInterfaceID']);
$remote_platform = strlen($entry['mtxrNeighborPlatform']) ? $entry['mtxrNeighborPlatform'] : $entry['lldpRemSysDesc'];
$remote_port = strlen($entry['lldpRemPortId']) ? $entry['lldpRemPortId'] : format_mac($entry['mtxrNeighborMacAddress'], ' ');
@ -90,70 +102,87 @@ if ($mtxr_array)
$remote_device_id = NULL;
$remote_port_id = NULL;
// Try find remote device and check if already cached
// Try to find a remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $entry['mtxrNeighborIdentity'], $entry['mtxrNeighborIpAddress'], $entry['mtxrNeighborMacAddress']);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($entry['mtxrNeighborIdentity'], $entry['mtxrNeighborIpAddress'])) // Check all previous autodiscovery rounds
{
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($entry['mtxrNeighborIdentity'], $entry['mtxrNeighborIpAddress'], 'MNDP', $remote_platform, $device, $port);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($entry['mtxrNeighborIdentity'], $entry['mtxrNeighborIpAddress'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($entry['mtxrNeighborIdentity'], $entry['mtxrNeighborIpAddress'], 'MNDP', $remote_platform, $device, $port);
}
if ($remote_device_id)
{
// Detect remote port by LLDP
if (strlen($entry['lldpRemPortId']))
{
$id = $entry['lldpRemPortId'];
switch ($entry['lldpRemPortIdSubtype'])
{
case 'interfaceAlias':
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE `ifAlias` = ? AND `device_id` = ?", [ $id, $remote_device_id ]);
break;
case 'interfaceName':
// Try lldpRemPortId
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ?';
$remote_port_id = dbFetchCell($query, [ $id, $id, $id, $remote_device_id ]);
break;
case 'macAddress':
$remote_port_id = get_port_id_by_mac($remote_device_id, $id);
break;
case 'networkAddress':
$ip_version = get_ip_version($id);
if ($ip_version)
{
$ip = ip_uncompress($id);
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ipv" . $ip_version . "_addresses` LEFT JOIN `ports` USING (`port_id`) WHERE `ipv" . $ip_version . "_address` = ? AND `device_id` = ?",
[ $ip, $remote_device_id ]);
}
break;
case 'local':
// local not always ifIndex or FIXME (see: http://jira.observium.org/browse/OBSERVIUM-1716)
if (!ctype_digit($id))
{
// Not sure what should be if $id ifName and it just numeric
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ?';
$remote_port_id = dbFetchCell($query, [ $id, $id, $id, $remote_device_id ]);
}
break;
// Check by LLDP address (probably IPv6 only)
if (is_null($remote_device_id) && $entry['lldpRemManAddr'] &&
$entry['mtxrNeighborIpAddress'] != $entry['lldpRemManAddr']) {
$lldp_device_id = get_autodiscovery_device_id($device, $entry['mtxrNeighborIdentity'], $entry['lldpRemManAddr'], $entry['mtxrNeighborMacAddress']);
if (is_null($lldp_device_id) && // NULL - never cached in other rounds
check_autodiscovery($entry['mtxrNeighborIdentity'], $entry['lldpRemManAddr'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$lldp_device_id = autodiscovery_device($entry['mtxrNeighborIdentity'], $entry['lldpRemManAddr'], 'MNDP', $remote_platform, $device, $port);
}
if (!is_null($lldp_device_id)) {
$remote_device_id = $lldp_device_id;
$entry['mtxrNeighborIpAddress'] == $entry['lldpRemManAddr'];
}
}
if ($remote_device_id) {
// Detect remote port by LLDP
if (strlen($entry['lldpRemPortId'])) {
$id = $entry['lldpRemPortId'];
switch ($entry['lldpRemPortIdSubtype']) {
case 'interfaceAlias':
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE `ifAlias` = ? AND `device_id` = ?", [$id, $remote_device_id]);
break;
case 'interfaceName':
// Try lldpRemPortId
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ?';
$remote_port_id = dbFetchCell($query, [ $id, $id, $id, $remote_device_id]);
if (!$remote_port_id && str_contains($id, '/')) {
// bridge/ether1 -> ether1
// bridge/uplink-bond/sfp-sfpplus3 -> sfp-sfpplus3
// bridge/peerlink/sfp-sfpplus23 -> sfp-sfpplus23
// bridge/mlag-bond-20/sfp-sfpplus20 -> sfp-sfpplus20
$id = end(explode('/', $id));
$remote_port_id = dbFetchCell($query, [ $id, $id, $id, $remote_device_id ]);
}
break;
case 'macAddress':
$remote_port_id = get_port_id_by_mac($remote_device_id, $id);
break;
case 'networkAddress':
$ip_version = get_ip_version($id);
if ($ip_version) {
$ip = ip_uncompress($id);
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ipv" . $ip_version . "_addresses` LEFT JOIN `ports` USING (`port_id`) WHERE `ipv" . $ip_version . "_address` = ? AND `device_id` = ?",
[$ip, $remote_device_id]);
}
break;
case 'local':
// local not always ifIndex or FIXME (see: http://jira.observium.org/browse/OBSERVIUM-1716)
if (!ctype_digit($id)) {
// Not sure what should be if $id ifName and it just numeric
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ?';
$remote_port_id = dbFetchCell($query, [$id, $id, $id, $remote_device_id]);
}
break;
}
} else {
// No way to find a remote port other than by MAC address, with the data we're getting from Mikrotik. Only proceed when only one remote port matches...
$remote_port_id = get_port_id_by_mac($remote_device_id, $entry['mtxrNeighborMacAddress']);
}
} else {
// No way to find a remote port other than by MAC address, with the data we're getting from Mikrotik. Only proceed when only one remote port matches...
$remote_port_id = get_port_id_by_mac($remote_device_id, $entry['mtxrNeighborMacAddress']);
}
}
$neighbour = [
'remote_port_id' => $remote_port_id,
'remote_hostname' => $entry['mtxrNeighborIdentity'],
'remote_port' => $remote_port,
'remote_platform' => $remote_platform,
'remote_version' => $entry['mtxrNeighborVersion'],
'remote_address' => $entry['mtxrNeighborIpAddress']
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $entry['mtxrNeighborIdentity'],
'remote_port' => $remote_port,
'remote_platform' => $remote_platform,
'remote_version' => $entry['mtxrNeighborVersion'],
'remote_address' => $entry['mtxrNeighborIpAddress']
];
discover_neighbour($port, 'mndp', $neighbour);
}
}
// EOF

View File

@ -0,0 +1,26 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
// NETAPP-ISDP-MIB::agentIsdpCacheAddress.2.1 = STRING: "169.254.149.239"
// NETAPP-ISDP-MIB::agentIsdpCacheLocalIntf.2.1 = STRING: "0/2"
// NETAPP-ISDP-MIB::agentIsdpCacheVersion.2.1 = STRING: "NetApp Release 9.9.1P16: Wed May 24 21:09:01 EDT 2023"
// NETAPP-ISDP-MIB::agentIsdpCacheDeviceId.2.1 = STRING: "sc01-lyo03-04"
// NETAPP-ISDP-MIB::agentIsdpCacheDevicePort.2.1 = STRING: "e0a"
// NETAPP-ISDP-MIB::agentIsdpCachePlatform.2.1 = STRING: "AFF-A300"
// NETAPP-ISDP-MIB::agentIsdpCacheCapabilities.2.1 = STRING: "Host"
// NETAPP-ISDP-MIB::agentIsdpCacheLastChange.2.1 = Timeticks: (62828004) 7 days, 6:31:20.04
// NETAPP-ISDP-MIB::agentIsdpCacheProtocolVersion.2.1 = STRING: "1"
// NETAPP-ISDP-MIB::agentIsdpCacheHoldtime.2.1 = INTEGER: 138 seconds
include(__DIR__ . "/isdp-mib.inc.php");
// 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,15 +4,15 @@
*
* 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
*
*/
if (!$config['autodiscovery']['ospf']) {
print_debug("Autodiscovery for OSPF disabled.");
return;
print_debug("Autodiscovery for OSPF disabled.");
return;
}
// OSPF-MIB::ospfNbrIpAddr.103.52.56.3.0 = IpAddress: 103.52.56.3
@ -45,24 +45,28 @@ if (!$config['autodiscovery']['ospf']) {
$ospf_array = snmpwalk_cache_twopart_oid($device, 'ospfNbmaNbrStatus', [], 'OSPF-MIB', NULL, OBS_SNMP_ALL_TABLE);
if (snmp_status()) {
$ospf_array = snmpwalk_cache_twopart_oid($device, 'ospfNbrRtrId', $ospf_array, 'OSPF-MIB', NULL, OBS_SNMP_ALL_TABLE);
print_debug_vars($ospf_array);
$ospf_array = snmpwalk_cache_twopart_oid($device, 'ospfNbrRtrId', $ospf_array, 'OSPF-MIB', NULL, OBS_SNMP_ALL_TABLE);
print_debug_vars($ospf_array);
foreach ($ospf_array as $ip => $entry) {
if ($ip === '0.0.0.0') { continue; }
foreach ($ospf_array as $ip => $entry) {
if ($ip === '0.0.0.0') {
continue;
}
foreach ($entry as $if => $ospf) {
if ($ospf['ospfNbmaNbrStatus'] !== 'active' || $ospf['ospfNbrRtrId'] === '0.0.0.0') { continue; }
foreach ($entry as $if => $ospf) {
if ($ospf['ospfNbmaNbrStatus'] !== 'active' || $ospf['ospfNbrRtrId'] === '0.0.0.0') {
continue;
}
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $ospf['ospfNbrRtrId']);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($ospf['ospfNbrRtrId'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($ospf['ospfNbrRtrId'], NULL, 'OSPF', NULL, $device);
}
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $ospf['ospfNbrRtrId']);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($ospf['ospfNbrRtrId'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($ospf['ospfNbrRtrId'], NULL, 'OSPF', NULL, $device);
}
}
}
}
}
// EOF

View File

@ -4,15 +4,15 @@
*
* 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
*
*/
if (!$config['autodiscovery']['ospf']) {
print_debug("Autodiscovery for OSPF disabled.");
return;
print_debug("Autodiscovery for OSPF disabled.");
return;
}
// OSPFV3-MIB::ospfv3NbrAddressType.4.0.3110374402 = INTEGER: ipv6(2)
@ -36,24 +36,26 @@ if (!$config['autodiscovery']['ospf']) {
$ospf_array = snmpwalk_cache_oid($device, 'ospfv3NbrAddress', [], 'OSPFV3-MIB', NULL, OBS_SNMP_ALL_HEX);
if (snmp_status()) {
$ospf_array = snmpwalk_cache_oid($device, 'ospfv3NbrIfId', $ospf_array, 'OSPFV3-MIB');
print_debug_vars($ospf_array);
$ospf_array = snmpwalk_cache_oid($device, 'ospfv3NbrIfId', $ospf_array, 'OSPFV3-MIB');
print_debug_vars($ospf_array);
foreach ($ospf_array as $index => $entry) {
$ip = hex2ip($entry['ospfv3NbrAddress']);
$ip_compressed = ip_compress($ip);
if ($ip_compressed === '::') { continue; }
foreach ($ospf_array as $index => $entry) {
$ip = hex2ip($entry['ospfv3NbrAddress']);
$ip_compressed = ip_compress($ip);
if ($ip_compressed === '::') {
continue;
}
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $ip);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($ip)) { // Check all previous autodiscovery rounds
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $ip);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($ip)) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$port = get_port_by_index_cache($device, $entry['ospfv3NbrIfId']);
$remote_device_id = autodiscovery_device($ip, NULL, 'OSPF', NULL, $device, $port);
// Neighbour never checked, try autodiscovery
$port = get_port_by_index_cache($device, $entry['ospfv3NbrIfId']);
$remote_device_id = autodiscovery_device($ip, NULL, 'OSPF', NULL, $device, $port);
}
}
}
}
// EOF

View File

@ -0,0 +1,79 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
// SW-MIB::swNumNbs.0 = INTEGER: 8
// SW-MIB::swNbIndex.1 = INTEGER: 1
// SW-MIB::swNbIndex.2 = INTEGER: 2
// SW-MIB::swNbIndex.3 = INTEGER: 3
// SW-MIB::swNbIndex.4 = INTEGER: 4
// SW-MIB::swNbIndex.5 = INTEGER: 5
// SW-MIB::swNbIndex.6 = INTEGER: 6
// SW-MIB::swNbIndex.7 = INTEGER: 7
// SW-MIB::swNbIndex.8 = INTEGER: 8
// SW-MIB::swNbMyPort.1 = INTEGER: 107
// SW-MIB::swNbMyPort.2 = INTEGER: 108
// SW-MIB::swNbMyPort.3 = INTEGER: 109
// SW-MIB::swNbMyPort.4 = INTEGER: 110
// SW-MIB::swNbMyPort.5 = INTEGER: 111
// SW-MIB::swNbMyPort.6 = INTEGER: 112
// SW-MIB::swNbMyPort.7 = INTEGER: 113
// SW-MIB::swNbMyPort.8 = INTEGER: 114
// SW-MIB::swNbRemDomain.1 = INTEGER: 52
// SW-MIB::swNbRemDomain.2 = INTEGER: 53
// SW-MIB::swNbRemDomain.3 = INTEGER: 51
// SW-MIB::swNbRemDomain.4 = INTEGER: 51
// SW-MIB::swNbRemDomain.5 = INTEGER: 51
// SW-MIB::swNbRemDomain.6 = INTEGER: 51
// SW-MIB::swNbRemDomain.7 = INTEGER: 56
// SW-MIB::swNbRemDomain.8 = INTEGER: 54
// SW-MIB::swNbRemPort.1 = INTEGER: 111
// SW-MIB::swNbRemPort.2 = INTEGER: 111
// SW-MIB::swNbRemPort.3 = INTEGER: 109
// SW-MIB::swNbRemPort.4 = INTEGER: 110
// SW-MIB::swNbRemPort.5 = INTEGER: 111
// SW-MIB::swNbRemPort.6 = INTEGER: 112
// SW-MIB::swNbRemPort.7 = INTEGER: 113
// SW-MIB::swNbRemPort.8 = INTEGER: 113
// SW-MIB::swNbBaudRate.1 = INTEGER: decuple(256)
// SW-MIB::swNbBaudRate.2 = INTEGER: decuple(256)
// SW-MIB::swNbBaudRate.3 = INTEGER: decuple(256)
// SW-MIB::swNbBaudRate.4 = INTEGER: decuple(256)
// SW-MIB::swNbBaudRate.5 = INTEGER: decuple(256)
// SW-MIB::swNbBaudRate.6 = INTEGER: decuple(256)
// SW-MIB::swNbBaudRate.7 = INTEGER: decuple(256)
// SW-MIB::swNbBaudRate.8 = INTEGER: decuple(256)
// SW-MIB::swNbIslState.1 = INTEGER: sw-active(5)
// SW-MIB::swNbIslState.2 = INTEGER: sw-active(5)
// SW-MIB::swNbIslState.3 = INTEGER: sw-down(0)
// SW-MIB::swNbIslState.4 = INTEGER: sw-down(0)
// SW-MIB::swNbIslState.5 = INTEGER: sw-active(5)
// SW-MIB::swNbIslState.6 = INTEGER: sw-down(0)
// SW-MIB::swNbIslState.7 = INTEGER: sw-active(5)
// SW-MIB::swNbIslState.8 = INTEGER: sw-active(5)
// SW-MIB::swNbIslCost.1 = INTEGER: 500
// SW-MIB::swNbIslCost.2 = INTEGER: 500
// SW-MIB::swNbIslCost.3 = INTEGER: 500
// SW-MIB::swNbIslCost.4 = INTEGER: 500
// SW-MIB::swNbIslCost.5 = INTEGER: 500
// SW-MIB::swNbIslCost.6 = INTEGER: 500
// SW-MIB::swNbIslCost.7 = INTEGER: 500
// SW-MIB::swNbIslCost.8 = INTEGER: 500
// SW-MIB::swNbRemPortName.1 = Hex-STRING: 5C 4F 57 CE 84 21 30 6E
// SW-MIB::swNbRemPortName.2 = Hex-STRING: 5C 4F 57 C7 B0 9D 40 6E
// SW-MIB::swNbRemPortName.3 = Hex-STRING: 5B 42 D5 60 41 CE 30 6C
// SW-MIB::swNbRemPortName.4 = Hex-STRING: 5B 42 D5 60 41 CE 30 6D
// SW-MIB::swNbRemPortName.5 = Hex-STRING: 5B 42 D5 60 41 CE 30 6E
// SW-MIB::swNbRemPortName.6 = Hex-STRING: 5B 42 D5 60 41 CE 30 6F
// SW-MIB::swNbRemPortName.7 = Hex-STRING: 5C 4F 57 CE 7E 2A 10 70
// SW-MIB::swNbRemPortName.8 = Hex-STRING: 5F 46 E9 5A 8A 36 E0 70
// EOF

View File

@ -0,0 +1,298 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage discovery
* @copyright (C) Adam Armstrong
*
*/
$lldp_array = snmpwalk_cache_oid($device, 'tmnxLldpRemChassisIdSubtype', [], "TIMETRA-LLDP-MIB");
if (empty($lldp_array)) {
return;
}
$lldp_array = snmpwalk_cache_oid($device, 'tmnxLldpRemChassisId', $lldp_array, "TIMETRA-LLDP-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'tmnxLldpRemPortIdSubtype', $lldp_array, "TIMETRA-LLDP-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'tmnxLldpRemPortId', $lldp_array, "TIMETRA-LLDP-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'tmnxLldpRemPortDesc', $lldp_array, "TIMETRA-LLDP-MIB");
$lldp_array = snmpwalk_cache_oid($device, 'tmnxLldpRemSysName', $lldp_array, "TIMETRA-LLDP-MIB");
// tmnxLldpRemSysDesc can be multiline
// index: tmnxLldpRemTimeMark.ifIndex.tmnxLldpRemLocalDestMACAddress.tmnxLldpRemIndex
$lldp_array = snmpwalk_cache_oid($device, 'tmnxLldpRemSysDesc', $lldp_array, "TIMETRA-LLDP-MIB", NULL, OBS_SNMP_ALL_MULTILINE);
// tmnxLldpRemManAddrTable
// index: tmnxLldpRemTimeMark.ifIndex.tmnxLldpRemLocalDestMACAddress.tmnxLldpRemIndex.tmnxLldpRemManAddrSubtype.tmnxLldpRemManAddr
$lldp_addr = snmpwalk_cache_oid($device, 'tmnxLldpRemManAddrIfId', [], "TIMETRA-LLDP-MIB", NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
$lldp_addr = snmpwalk_cache_oid($device, 'tmnxLldpRemManAddrIfSubtype', $lldp_addr, "TIMETRA-LLDP-MIB", NULL, OBS_SNMP_ALL_NUMERIC_INDEX);
print_debug_vars($lldp_addr);
foreach ($lldp_addr as $index => $entry) {
/*
if (isset($lldp_array[$index])) {
$lldp_array[$index] = array_merge($lldp_array[$index], $entry);
if (isset($entry['lldpRemManAddr'])) {
$addr = hex2ip($entry['lldpRemManAddr']);
$lldp_array[$index]['lldpRemMan'][$addr] = $entry; // For multiple entries
}
continue;
}
*/
$index_array = explode('.', $index, 7);
// LLDP index
$tmnxLldpRemTimeMark = array_shift($index_array);
$tmnxLocalifIndex = array_shift($index_array);
$tmnxLldpRemLocalDestMACAddress = array_shift($index_array);
$tmnxLldpRemIndex = array_shift($index_array);
$lldp_index = "$tmnxLldpRemTimeMark.$tmnxLocalifIndex.$tmnxLldpRemLocalDestMACAddress.$tmnxLldpRemIndex";
if (!isset($lldp_array[$lldp_index])) {
continue;
}
//$lldp_array[$lldp_index] = array_merge($lldp_array[$lldp_index], $entry);
// Already exist Oid, just merge
// if (isset($entry['lldpRemManAddr']))
// {
// continue;
// }
// Convert from index part
$type = array_shift($index_array);
$len = array_shift($index_array);
$addr = array_shift($index_array);
switch ($type) {
case 4:
// IPv4, ie: 4.10.129.2.171
$lldp_array[$lldp_index]['tmnxLldpRemManAddr'] = $addr;
break;
case 6:
// IPv6, ie: 16.42.2.32.40.255.0.0.0.0.0.0.1.0.0.1.113
$addr = snmp2ipv6($addr);
$lldp_array[$lldp_index]['tmnxLldpRemManAddr'] = $addr;
break;
default:
// Unknown
}
$lldp_array[$lldp_index]['tmnxLldpRemMan'][$addr] = $entry; // For multiple entries
}
print_debug_vars($lldp_array, 1);
// index: ifIndex.tmnxLldpLocPortDestMACAddress
$lldp_local_array = snmpwalk_cache_oid($device, "tmnxLldpLocPortEntry", [], "TIMETRA-LLDP-MIB");
foreach ($lldp_array as $index => $lldp) {
[$tmnxLldpRemTimeMark, $tmnxLocalifIndex, $tmnxLldpRemLocalDestMACAddress, $tmnxLldpRemIndex] = explode('.', $index);
// Detect local device port
$port = NULL;
$tmnxLocalIndex = $tmnxLocalifIndex . '.' . $tmnxLldpRemLocalDestMACAddress;
// Prefer by LLDP-MIB
if (!$port && isset($lldp_local_array[$tmnxLocalIndex])) {
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND `ifIndex` = ? AND `ifDescr` NOT LIKE 'Vlan%'", [$device['device_id'], 0, $tmnxLocalifIndex]);
}
// Detect remote device and port
$remote_device_id = FALSE;
$remote_port_id = NULL;
// Sometime tmnxLldpRemPortDesc is not set
if (!isset($lldp['tmnxLldpRemPortDesc'])) {
$lldp['tmnxLldpRemPortDesc'] = '';
}
$remote_mac = $lldp['tmnxLldpRemChassisIdSubtype'] === 'macAddress' ? $lldp['tmnxLldpRemChassisId'] : NULL;
// tmnxLldpRemPortId can be hex string (not sure that this actual on timos platform)
if ($lldp['tmnxLldpRemPortIdSubtype'] !== 'macAddress') {
if (str_contains($lldp['tmnxLldpRemPortId'], ':')) {
$tmp = str_replace(':', ' ', $lldp['tmnxLldpRemPortId']);
$rem_port_id = snmp_hexstring($tmp);
if ($tmp != $rem_port_id) {
$lldp['tmnxLldpRemPortId'] = $rem_port_id;
print_debug("tmnxLldpRemPortId decoded: '$tmp' -> '$rem_port_id'");
}
unset($tmp, $rem_port_id);
}
// On Extreme platforms, they remove the leading 1: from ports. Put it back if there isn't a :.
if (preg_match('/^ExtremeXOS.*$/', $lldp['tmnxLldpRemSysDesc'])) {
if (!preg_match('/\:/', $lldp['tmnxLldpRemPortId'])) {
$lldp['tmnxLldpRemPortId'] = '1:' . $lldp['tmnxLldpRemPortId'];
}
} else {
//$lldp['tmnxLldpRemPortId'] = snmp_hexstring($lldp['tmnxLldpRemPortId']);
}
} elseif (safe_empty($remote_mac)) {
$remote_mac = $lldp['tmnxLldpRemPortId'];
}
// Clean MAC & IP
if (safe_count($lldp['tmnxLldpRemMan']) > 1) {
// Multiple IP addresses.. detect best?
foreach (array_keys($lldp['tmnxLldpRemMan']) as $addr) {
$addr_version = get_ip_version($addr);
$addr_type = get_ip_type($addr);
if (in_array($addr_type, ['unspecified', 'loopback', 'reserved', 'multicast'])) {
continue;
}
if ($addr_version == 6 && $addr_type === 'link-local') {
continue;
}
if ($addr_type === 'unicast') {
// Prefer IPv4/IPv6 unicast
$lldp['tmnxLldpRemManAddr'] = $addr;
break;
}
if ($addr_version == 4) {
// Than prefer IPv4
$lldp['tmnxLldpRemManAddr'] = $addr;
break;
}
$lldp['tmnxLldpRemManAddr'] = $addr;
}
print_debug("Multiple remote IP addresses detect, selected: $addr");
print_debug_vars($lldp);
}
if (isset($lldp['tmnxLldpRemManAddr'])) {
$lldp['tmnxLldpRemManAddr'] = hex2ip($lldp['tmnxLldpRemManAddr']);
}
// Remote sysname is MAC in some cases
if (preg_match('/^[a-f\d]{2}([: ][a-f\d]{2}){5}$/', $lldp['tmnxLldpRemSysName']) && get_ip_version($lldp['tmnxLldpRemManAddr'])) {
// Replace by IP address for better discovery
print_debug("LLDP hostname replaced: " . $lldp['tmnxLldpRemSysName'] . " -> " . $lldp['tmnxLldpRemManAddr']);
$lldp['tmnxLldpRemSysName'] = $lldp['tmnxLldpRemManAddr'];
} elseif (safe_empty($lldp['tmnxLldpRemSysName']) && !safe_empty($lldp['tmnxLldpRemSysDesc'])) {
if ($lldp['tmnxLldpRemChassisIdSubtype'] === 'macAddress') {
// use mac address instead empty hostname:
$lldp['tmnxLldpRemSysName'] = str_replace([' ', '-'], '', strtolower($lldp['tmnxLldpRemChassisId']));
} elseif ($lldp['tmnxLldpRemChassisIdSubtype'] === 'networkAddress' &&
preg_match('/^01 (?<ip>([A-F\d]{2}\s?){4})$/', $lldp['tmnxLldpRemChassisId'], $matches)) {
$lldp['tmnxLldpRemSysName'] = hex2ip($matches['ip']);
}
}
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $lldp['tmnxLldpRemSysName'], $lldp['tmnxLldpRemManAddr'], $remote_mac);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($lldp['tmnxLldpRemSysName'], $lldp['tmnxLldpRemManAddr'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($lldp['tmnxLldpRemSysName'], $lldp['tmnxLldpRemManAddr'], 'LLDP', $lldp['tmnxLldpRemSysDesc'], $device, $port);
}
if ($remote_device_id) {
$id = $lldp['tmnxLldpRemPortDesc'];
$if = trim($lldp['tmnxLldpRemPortId']);
// lldpPortIdSubtype -> lldpPortId
// interfaceAlias(1), -> ifAlias
// portComponent(2), -> entPhysicalAlias
// macAddress(3), -> ifPhysAddress
// networkAddress(4), -> IP address
// interfaceName(5), -> ifName
// agentCircuitId(6), -> agent-local identifier of the circuit (defined in RFC 3046) (FIXME, not know)
// local(7) -> ifIndex
switch ($lldp['tmnxLldpRemPortIdSubtype']) {
case 'interfaceAlias':
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifAlias` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?", [$id, $if, $if, $remote_device_id, 0]);
break;
case 'interfaceName':
// Try lldpRemPortId
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$id, $id, $id, $remote_device_id, 0]);
if (!$remote_port_id && !safe_empty($if)) {
// Try same by lldpRemPortDesc
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
}
break;
case 'macAddress':
$remote_port_id = get_port_id_by_mac($remote_device_id, $id);
if (!$remote_port_id && !safe_empty($if)) {
// Try same by lldpRemPortDesc
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
}
break;
case 'networkAddress':
$ip_version = get_ip_version($id);
if ($ip_version) {
// Try by IP
$peer_where = generate_query_values_and($remote_device_id, 'device_id'); // Additional filter for include self IPs
// Fetch all devices with peer IP and filter by UP
if ($ids = get_entity_ids_ip_by_network('port', $id, $peer_where)) {
$remote_port_id = $ids[0];
//$port = get_port_by_id_cache($ids[0]);
}
}
break;
case 'local':
// local not always ifIndex or FIXME (see: http://jira.observium.org/browse/OBSERVIUM-1716)
if (!ctype_digit($id)) {
// Not sure what should be if $id ifName and it just numeric
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$id, $id, $id, $remote_device_id, 0]);
if (!$remote_port_id) {
// Try same by lldpRemPortDesc
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
}
}
case 'ifIndex':
// These cases are handled by the ifDescr/ifIndex combination fallback below
break;
default:
break;
}
if (!$remote_port_id && is_numeric($id)) { // Not found despite our attempts above - fall back to try matching with ifDescr/ifIndex
$remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifIndex`= ? OR `ifDescr` = ?) AND `device_id` = ? AND `deleted` = ?", [$id, $if, $remote_device_id, 0]);
}
if (!$remote_port_id) { // Still not found?
if ($lldp['tmnxLldpRemChassisIdSubtype'] === 'macAddress') {
// Find the port by chassis MAC address, only use this if exactly 1 match is returned, otherwise we'd link wrongly - think switches with 1 global MAC on all ports.
$remote_port_id = get_port_id_by_mac($remote_device_id, $lldp['tmnxLldpRemChassisId']);
} else {
// Last chance
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` IN (?, ?) OR `ifDescr` IN (?, ?) OR `port_label_short` IN (?, ?)) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$id, $if, $id, $if, $id, $if, $remote_device_id, 0]);
}
}
// Still not found? Seems as incorrect remote device :/
if (!$remote_port_id) {
print_debug("WARNING. Remote device found in db, but remote port not found. Seems as incorrect remote device association.");
}
}
$valid_host_key = $lldp['tmnxLldpRemSysName'];
if (strlen($lldp['tmnxLldpRemManAddr'])) {
$valid_host_key .= '-' . $lldp['tmnxLldpRemManAddr'];
}
if ($GLOBALS['valid']['neighbours'][$port['port_id']][$valid_host_key][$lldp['tmnxLldpRemPortId']]) {
print_warning("Neighbour already discovered by LLDP-MIB. Skip..");
continue;
}
$neighbour = [
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $lldp['tmnxLldpRemSysName'],
'remote_port' => $lldp['tmnxLldpRemPortId'],
'remote_platform' => $lldp['tmnxLldpRemSysDesc'],
'remote_version' => NULL,
'remote_address' => $lldp['tmnxLldpRemManAddr']
];
discover_neighbour($port, 'lldp', $neighbour);
}
// EOF

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
*
*/
@ -47,48 +47,49 @@ print_debug_vars($lldp_array);
foreach ($lldp_array as $index => $lldp) {
// Local port
list($ifIndex, $lldpNeighborPortIndexId) = explode('.', $index, 2);
$ifName = $lldp['lldpNeighborPortId'];
$port = get_port_by_index_cache($device, $ifIndex);
if (!$port) {
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?)", [ $device['device_id'], 0, $ifName, $ifName, $ifName ]);
}
// Remote device & port
$remote_device_id = FALSE;
$remote_port_id = NULL;
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $lldp['lldpNeighborDeviceName'], $lldp['lldpNeighborManageIpAddr'], $lldp['lldpNeighborChassisId']);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($lldp['lldpNeighborDeviceName'], $lldp['lldpNeighborManageIpAddr'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($lldp['lldpNeighborDeviceName'], $lldp['lldpNeighborManageIpAddr'], 'LLDP', $lldp['lldpNeighborDeviceDescr'], $device, $port);
}
if ($remote_device_id) {
// Try lldpNeighborPortIdDescr
$if = $lldp['lldpNeighborPortIdDescr'];
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [ $if, $if, $if, $remote_device_id, 0 ]);
if (!$remote_port_id && $lldp['lldpNeighborPortDescr'] !== $if) {
$if = $lldp['lldpNeighborPortDescr'];
// Try same by lldpNeighborPortDescr
$remote_port_id = dbFetchCell($query, [ $if, $if, $if, $remote_device_id, 0 ]);
// Local port
[$ifIndex, $lldpNeighborPortIndexId] = explode('.', $index, 2);
$ifName = $lldp['lldpNeighborPortId'];
$port = get_port_by_index_cache($device, $ifIndex);
if (!$port) {
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = ? AND (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?)", [$device['device_id'], 0, $ifName, $ifName, $ifName]);
}
//$id = $lldp['lldpNeighborManageAddrInterfaceId'];
}
$neighbour = [
'remote_port_id' => $remote_port_id,
'remote_hostname' => $lldp['lldpNeighborDeviceName'],
'remote_port' => $lldp['lldpNeighborPortIdDescr'],
'remote_platform' => $lldp['lldpNeighborDeviceDescr'],
'remote_version' => NULL,
'remote_address' => $lldp['lldpNeighborManageIpAddr']
];
discover_neighbour($port, 'lldp', $neighbour);
// Remote device & port
$remote_device_id = FALSE;
$remote_port_id = NULL;
// Try find remote device and check if already cached
$remote_device_id = get_autodiscovery_device_id($device, $lldp['lldpNeighborDeviceName'], $lldp['lldpNeighborManageIpAddr'], $lldp['lldpNeighborChassisId']);
if (is_null($remote_device_id) && // NULL - never cached in other rounds
check_autodiscovery($lldp['lldpNeighborDeviceName'], $lldp['lldpNeighborManageIpAddr'])) { // Check all previous autodiscovery rounds
// Neighbour never checked, try autodiscovery
$remote_device_id = autodiscovery_device($lldp['lldpNeighborDeviceName'], $lldp['lldpNeighborManageIpAddr'], 'LLDP', $lldp['lldpNeighborDeviceDescr'], $device, $port);
}
if ($remote_device_id) {
// Try lldpNeighborPortIdDescr
$if = $lldp['lldpNeighborPortIdDescr'];
$query = 'SELECT `port_id` FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ? OR `port_label_short` = ?) AND `device_id` = ? AND `deleted` = ?';
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
if (!$remote_port_id && $lldp['lldpNeighborPortDescr'] !== $if) {
$if = $lldp['lldpNeighborPortDescr'];
// Try same by lldpNeighborPortDescr
$remote_port_id = dbFetchCell($query, [$if, $if, $if, $remote_device_id, 0]);
}
//$id = $lldp['lldpNeighborManageAddrInterfaceId'];
}
$neighbour = [
'remote_device_id' => $remote_device_id,
'remote_port_id' => $remote_port_id,
'remote_hostname' => $lldp['lldpNeighborDeviceName'],
'remote_port' => $lldp['lldpNeighborPortIdDescr'],
'remote_platform' => $lldp['lldpNeighborDeviceDescr'],
'remote_version' => NULL,
'remote_address' => $lldp['lldpNeighborManageIpAddr']
];
discover_neighbour($port, 'lldp', $neighbour);
}
// EOF