} else {
            // Try to find remote host by remote chassis mac address from DB
            $remote_mac = str_replace(':', '', strtolower($entry['mtxrNeighborMacAddress']));
            $remote_device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `deleted` = '0' AND `ifPhysAddress` = ? LIMIT 1;", array($remote_mac));
            if (!$remote_device_id) {
                // We can also use IP address from mtxrNeighborIpAddress to find remote device.
                $remote_device_id = dbFetchCell("SELECT `device_id` FROM `ports` LEFT JOIN `ipv4_addresses` on `ports`.`port_id`=`ipv4_addresses`.`port_id` WHERE `deleted` = '0' AND `ipv4_address` = ? LIMIT 1;", array($entry['mtxrNeighborIpAddress']));
            }
        }
        if ($remote_device_id) {
            $remote_device_hostname = device_by_id_cache($remote_device_id);
            // Overwrite remote hostname with the one we know, for devices that we identify by sysName
            if ($remote_device_hostname['hostname']) {
                $entry['mtxrNeighborIdentity'] = $remote_device_hostname['hostname'];
            }
        }
        if ($remote_device_id) {
            // 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_chassis_id = strtolower(str_replace(':', '', $entry['mtxrNeighborMacAddress']));
            $remote_port_ids = dbFetchRows("SELECT `port_id` FROM `ports` WHERE `ifPhysAddress` = ? AND `device_id` = ?", array($remote_chassis_id, $remote_device_id));
            if (count($remote_port_ids) == 1) {
                $remote_port_id = $remote_port_ids[0]['port_id'];
            }
        }
        if (!is_bad_xdp($entry['mtxrNeighborIdentity']) && is_numeric($port['port_id']) && !empty($entry['mtxrNeighborIdentity'])) {
            // We format the remote MAC just like lldpRemPortId macAddress (I think) (00 11 22 33 44 55) - we don't have an actual remote port name or ifIndex or anything in this MIB.
            discover_link($valid_link, $port['port_id'], 'mndp', $remote_port_id, $entry['mtxrNeighborIdentity'], strtoupper(str_replace(':', ' ', $entry['mtxrNeighborMacAddress'])), $entry['mtxrNeighborPlatform'], $entry['mtxrNeighborVersion']);
        }
    }
}
// EOF
Beispiel #2
0
                    }
                    if (!$remote_port_id) {
                        $remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifIndex`= ? OR `ifDescr` = ?) AND `device_id` = ?", array($id, $if, $remote_device_id));
                    }
                    if (!$remote_port_id) {
                        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_chassis_id = strtolower(str_replace(array(' ', '-'), '', $lldp['lldpRemChassisId']));
                            $remote_port_ids = dbFetchRows("SELECT `port_id` FROM `ports` WHERE `ifPhysAddress` = ? AND `device_id` = ?", array($remote_chassis_id, $remote_device_id));
                            if (count($remote_port_ids) == 1) {
                                $remote_port_id = $remote_port_ids[0]['port_id'];
                            }
                        }
                    }
                } else {
                    // FIXME why is this here?
                    if (empty($lldp['lldpRemSysName']) && $lldp['lldpRemChassisIdSubtype'] == 'macAddress') {
                        $lldp['lldpRemSysName'] = str_replace(array(' ', '-'), '', strtolower($lldp['lldpRemChassisId']));
                    }
                }
                if (!is_bad_xdp($lldp['lldpRemSysName']) && is_numeric($port['port_id']) && !empty($lldp['lldpRemSysName']) && isset($lldp['lldpRemPortId'])) {
                    // 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 "
                    discover_link($valid_link, $port['port_id'], 'lldp', $remote_port_id, $lldp['lldpRemSysName'], $lldp['lldpRemPortId'], NULL, $lldp['lldpRemSysDesc']);
                }
            }
        }
    }
}
// EOF
                    $remote_device_id = $GLOBALS['cache']['discovery-protocols'][$isdp_entry['agentIsdpCacheDeviceId']];
                } else {
                    $remote_device_id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?", array($isdp_entry['agentIsdpCacheDeviceId'], $isdp_entry['agentIsdpCacheDeviceId']));
                    // FIXME do LLDP-code-style hostname overwrite here as well? (see below)
                    if (!$remote_device_id && is_valid_hostname($isdp_entry['agentIsdpCacheDeviceId']) && !is_bad_xdp($isdp_entry['agentIsdpCacheDeviceId'], $isdp_entry['agentIsdpCachePlatform'])) {
                        // For now it's a Cisco so CDP discovery is ok
                        $remote_device_id = discover_new_device($isdp_entry['agentIsdpCacheDeviceId'], 'xdp', 'ISDP', $device, $port);
                    }
                    // Cache remote device ID for other protocols
                    $GLOBALS['cache']['discovery-protocols'][$isdp_entry['agentIsdpCacheDeviceId']] = $remote_device_id;
                }
                if ($remote_device_id) {
                    $if = $isdp_entry['agentIsdpCacheDevicePort'];
                    $remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ?", array($if, $if, $remote_device_id));
                } else {
                    $remote_port_id = "0";
                }
                if (!is_bad_xdp($isdp_entry['agentIsdpCacheDeviceId']) && $port['port_id'] && $isdp_entry['agentIsdpCacheDeviceId'] && $isdp_entry['agentIsdpCacheDevicePort']) {
                    $remote_address = $isdp_entry['agentIsdpCacheAddress'];
                    if (!get_ip_version($remote_address)) {
                        $remote_address = NULL;
                    }
                    discover_link($valid_link, $port['port_id'], 'isdp', $remote_port_id, $isdp_entry['agentIsdpCacheDeviceId'], $isdp_entry['agentIsdpCacheDevicePort'], $isdp_entry['agentIsdpCachePlatform'], $isdp_entry['agentIsdpCacheVersion'], $remote_address);
                }
            } else {
                echo "X";
            }
        }
    }
}
// EOF
if ($amap_array) {
    foreach (array_keys($amap_array) as $key) {
        $amap = array_shift(array_shift($amap_array[$key]));
        $port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $amap['aipAMAPLocalIfindex']));
        $remote_device_id = FALSE;
        if (is_valid_hostname($amap['aipAMAPRemHostname'])) {
            if (isset($GLOBALS['cache']['discovery-protocols'][$amap['aipAMAPRemHostname']])) {
                // This hostname already checked, skip discover
                $remote_device_id = $GLOBALS['cache']['discovery-protocols'][$amap['aipAMAPRemHostname']];
            } else {
                $remote_device = dbFetchRow("SELECT `device_id`, `hostname` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?", array($amap['aipAMAPRemHostname'], $amap['aipAMAPRemHostname']));
                $remote_device_id = $remote_device['device_id'];
                if (!$remote_device_id && !is_bad_xdp($amap['aipAMAPRemHostname'], $amap['aipAMAPRemDeviceType'])) {
                    $remote_device_id = discover_new_device($amap['aipAMAPRemHostname'], 'xdp', 'AMAP', $device, $port);
                }
                // Cache remote device ID for other protocols
                $GLOBALS['cache']['discovery-protocols'][$amap['aipAMAPRemHostname']] = $remote_device_id;
            }
        }
        if ($remote_device_id) {
            $if = $amap['aipAMAPRemSlot'] . "/" . $amap['aipAMAPRemPort'];
            $remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ?", array($if, $if, $remote_device_id));
        } else {
            $remote_port_id = "0";
        }
        if (!is_bad_xdp($amap['aipAMAPRemHostname']) && is_numeric($port['port_id']) && isset($amap['aipAMAPRemHostname'])) {
            discover_link($valid_link, $port['port_id'], 'amap', $remote_port_id, $amap['aipAMAPRemHostname'], $amap['aipAMAPRemSlot'] . "/" . $amap['aipAMAPRemPort'], $amap['aipAMAPRemDeviceType'], $amap['aipAMAPRemDevModelName']);
        }
    }
}
// EOF
            // Fix for Nexus CDP neighbors: <hostname>(serial number)
            $remote_device_id = FALSE;
            if (is_valid_hostname($cdp_entry['cdpCacheDeviceId'])) {
                if (isset($GLOBALS['cache']['discovery-protocols'][$cdp_entry['cdpCacheDeviceId']])) {
                    // This hostname already checked, skip discover
                    $remote_device_id = $GLOBALS['cache']['discovery-protocols'][$cdp_entry['cdpCacheDeviceId']];
                } else {
                    $remote_device_id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?", array($cdp_entry['cdpCacheDeviceId'], $cdp_entry['cdpCacheDeviceId']));
                    // FIXME do LLDP-code-style hostname overwrite here as well? (see below)
                    if (!$remote_device_id && is_valid_hostname($cdp_entry['cdpCacheDeviceId']) && !is_bad_xdp($cdp_entry['cdpCacheDeviceId'], $cdp_entry['cdpCachePlatform'])) {
                        $remote_device_id = discover_new_device($cdp_entry['cdpCacheDeviceId'], 'xdp', 'CDP', $device, $port);
                    }
                    // Cache remote device ID for other protocols
                    $GLOBALS['cache']['discovery-protocols'][$cdp_entry['cdpCacheDeviceId']] = $remote_device_id;
                }
                if ($remote_device_id) {
                    $if = $cdp_entry['cdpCacheDevicePort'];
                    $remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ?", array($if, $if, $remote_device_id));
                } else {
                    $remote_port_id = "0";
                }
                if (!is_bad_xdp($cdp_entry['cdpCacheDeviceId']) && $port['port_id'] && $cdp_entry['cdpCacheDeviceId'] && $cdp_entry['cdpCacheDevicePort']) {
                    discover_link($valid_link, $port['port_id'], 'cdp', $remote_port_id, $cdp_entry['cdpCacheDeviceId'], $cdp_entry['cdpCacheDevicePort'], $cdp_entry['cdpCachePlatform'], $cdp_entry['cdpCacheVersion']);
                }
            } else {
                echo "X";
            }
        }
    }
}
// EOF
        $fdp_if_array = $fdp_array[$key];
        foreach (array_keys($fdp_if_array) as $entry_key) {
            $fdp = $fdp_if_array[$entry_key];
            $remote_device_id = FALSE;
            if (is_valid_hostname($fdp['snFdpCacheDeviceId'])) {
                if (isset($GLOBALS['cache']['discovery-protocols'][$fdp['snFdpCacheDeviceId']])) {
                    // This hostname already checked, skip discover
                    $remote_device_id = $GLOBALS['cache']['discovery-protocols'][$fdp['snFdpCacheDeviceId']];
                } else {
                    $remote_device_id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?", array($fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDeviceId']));
                    if (!$remote_device_id && !is_bad_xdp($fdp['snFdpCacheDeviceId'], $fdp['snFdpCachePlatform'])) {
                        $remote_device_id = discover_new_device($fdp['snFdpCacheDeviceId'], 'xdp', 'FDP', $device, $port);
                    }
                    // Cache remote device ID for other protocols
                    $GLOBALS['cache']['discovery-protocols'][$fdp['snFdpCacheDeviceId']] = $remote_device_id;
                }
            }
            // FIXME do LLDP-code-style hostname overwrite here as well? (see below)
            if ($remote_device_id) {
                $if = $fdp['snFdpCacheDevicePort'];
                $remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ?", array($if, $if, $remote_device_id));
            } else {
                $remote_port_id = "0";
            }
            if (!is_bad_xdp($fdp['snFdpCacheDeviceId'])) {
                discover_link($valid_link, $port['port_id'], $fdp['snFdpCacheVendorId'], $remote_port_id, $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDevicePort'], $fdp['snFdpCachePlatform'], $fdp['snFdpCacheVersion']);
            }
        }
    }
}
// EOF