mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Cleanup enable bgp setting (#14931)
* remove logic in module * remove enable_bgp logic * remove enable_bgp logic * remove enable_bgp logic * remove enable_bgp logic * remove enable_bgp definition * remove enable_bgp logic * Remove enable_bgp documentation * StyleCI * StyleCI * StyleCI * StyleCI * StyleCI * StyleCI * StyleCI * StyleCI * StyleCI * StyleCI
This commit is contained in:
@@ -63,13 +63,11 @@ class OverviewController extends Controller
|
||||
->get();
|
||||
|
||||
// TODO: is inAlarm() equal to: bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' ?
|
||||
if (Config::get('enable_bgp')) {
|
||||
$bgp_down = BgpPeer::hasAccess(Auth::user())
|
||||
->inAlarm()
|
||||
->limit(Config::get('front_page_down_box_limit'))
|
||||
->with('device')
|
||||
->get();
|
||||
}
|
||||
$bgp_down = BgpPeer::hasAccess(Auth::user())
|
||||
->inAlarm()
|
||||
->limit(Config::get('front_page_down_box_limit'))
|
||||
->with('device')
|
||||
->get();
|
||||
|
||||
if (filter_var(Config::get('uptime_warning'), FILTER_VALIDATE_FLOAT) !== false
|
||||
&& Config::get('uptime_warning') > 0
|
||||
|
@@ -657,7 +657,6 @@ Please refer to [Billing](../Extensions/Billing-Module.md)
|
||||
## Global module support
|
||||
|
||||
```bash
|
||||
lnms config:set enable_bgp true # Enable BGP session collection and display
|
||||
lnms config:set enable_syslog false # Enable Syslog
|
||||
lnms config:set enable_inventory true # Enable Inventory
|
||||
lnms config:set enable_pseudowires true # Enable Pseudowires
|
||||
|
@@ -4,197 +4,195 @@ use LibreNMS\Config;
|
||||
use LibreNMS\Exceptions\InvalidIpException;
|
||||
use LibreNMS\Util\IP;
|
||||
|
||||
if (Config::get('enable_bgp')) {
|
||||
//
|
||||
// Load OS specific file
|
||||
//
|
||||
if (file_exists(Config::get('install_dir') . "/includes/discovery/bgp-peers/{$device['os']}.inc.php")) {
|
||||
include Config::get('install_dir') . "/includes/discovery/bgp-peers/{$device['os']}.inc.php";
|
||||
}
|
||||
//
|
||||
// Load OS specific file
|
||||
//
|
||||
if (file_exists(Config::get('install_dir') . "/includes/discovery/bgp-peers/{$device['os']}.inc.php")) {
|
||||
include Config::get('install_dir') . "/includes/discovery/bgp-peers/{$device['os']}.inc.php";
|
||||
}
|
||||
|
||||
if (empty($bgpLocalAs)) {
|
||||
$bgpLocalAs = snmp_getnext($device, 'bgpLocalAs', '-OQUsv', 'BGP4-MIB');
|
||||
}
|
||||
if (empty($bgpLocalAs)) {
|
||||
$bgpLocalAs = snmp_getnext($device, 'bgpLocalAs', '-OQUsv', 'BGP4-MIB');
|
||||
}
|
||||
|
||||
foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) {
|
||||
$device['context_name'] = $context_name;
|
||||
$peer2 = false;
|
||||
$peers_data = '';
|
||||
$bgp4_mib = false;
|
||||
foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) {
|
||||
$device['context_name'] = $context_name;
|
||||
$peer2 = false;
|
||||
$peers_data = '';
|
||||
$bgp4_mib = false;
|
||||
|
||||
if (is_numeric($bgpLocalAs)) {
|
||||
echo "AS$bgpLocalAs ";
|
||||
if ($bgpLocalAs != $device['bgpLocalAs']) {
|
||||
dbUpdate(['bgpLocalAs' => $bgpLocalAs], 'devices', 'device_id=?', [$device['device_id']]);
|
||||
echo 'Updated AS ';
|
||||
}
|
||||
|
||||
if ($device['os_group'] === 'arista') {
|
||||
$peers_data = snmp_walk($device, 'aristaBgp4V2PeerRemoteAs', '-Oq', 'ARISTA-BGP4V2-MIB');
|
||||
$peer2 = true;
|
||||
} elseif ($device['os'] == 'junos') {
|
||||
$peers_data = snmp_walk($device, 'jnxBgpM2PeerRemoteAs', '-Onq', 'BGP4-V2-MIB-JUNIPER', 'junos');
|
||||
} elseif ($device['os_group'] === 'cisco') {
|
||||
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB');
|
||||
$peer2 = ! empty($peers_data);
|
||||
} elseif ($device['os'] === 'cumulus') {
|
||||
$peers_data = snmp_walk($device, 'bgpPeerRemoteAs', '-Oq', 'CUMULUS-BGPUN-MIB');
|
||||
$peer2 = ! empty($peers_data);
|
||||
}
|
||||
|
||||
if (empty($peers_data)) {
|
||||
$bgp4_mib = true;
|
||||
$peers_data = preg_replace('/= /', '', snmp_walk($device, 'bgpPeerRemoteAs', '-OQ', 'BGP4-MIB'));
|
||||
}
|
||||
} else {
|
||||
echo 'No BGP on host';
|
||||
if ($device['bgpLocalAs']) {
|
||||
dbUpdate(['bgpLocalAs' => ['NULL']], 'devices', 'device_id=?', [$device['device_id']]);
|
||||
echo ' (Removed ASN) ';
|
||||
}
|
||||
if (is_numeric($bgpLocalAs)) {
|
||||
echo "AS$bgpLocalAs ";
|
||||
if ($bgpLocalAs != $device['bgpLocalAs']) {
|
||||
dbUpdate(['bgpLocalAs' => $bgpLocalAs], 'devices', 'device_id=?', [$device['device_id']]);
|
||||
echo 'Updated AS ';
|
||||
}
|
||||
|
||||
$peerlist = build_bgp_peers($device, $peers_data, $peer2);
|
||||
if ($device['os_group'] === 'arista') {
|
||||
$peers_data = snmp_walk($device, 'aristaBgp4V2PeerRemoteAs', '-Oq', 'ARISTA-BGP4V2-MIB');
|
||||
$peer2 = true;
|
||||
} elseif ($device['os'] == 'junos') {
|
||||
$peers_data = snmp_walk($device, 'jnxBgpM2PeerRemoteAs', '-Onq', 'BGP4-V2-MIB-JUNIPER', 'junos');
|
||||
} elseif ($device['os_group'] === 'cisco') {
|
||||
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB');
|
||||
$peer2 = ! empty($peers_data);
|
||||
} elseif ($device['os'] === 'cumulus') {
|
||||
$peers_data = snmp_walk($device, 'bgpPeerRemoteAs', '-Oq', 'CUMULUS-BGPUN-MIB');
|
||||
$peer2 = ! empty($peers_data);
|
||||
}
|
||||
|
||||
// Process discovered peers
|
||||
if (! empty($peerlist)) {
|
||||
$af_data = [];
|
||||
$af_list = [];
|
||||
if (empty($peers_data)) {
|
||||
$bgp4_mib = true;
|
||||
$peers_data = preg_replace('/= /', '', snmp_walk($device, 'bgpPeerRemoteAs', '-OQ', 'BGP4-MIB'));
|
||||
}
|
||||
} else {
|
||||
echo 'No BGP on host';
|
||||
if ($device['bgpLocalAs']) {
|
||||
dbUpdate(['bgpLocalAs' => ['NULL']], 'devices', 'device_id=?', [$device['device_id']]);
|
||||
echo ' (Removed ASN) ';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($peerlist as $peer) {
|
||||
$peer['astext'] = get_astext($peer['as']);
|
||||
$peerlist = build_bgp_peers($device, $peers_data, $peer2);
|
||||
|
||||
add_bgp_peer($device, $peer);
|
||||
// Process discovered peers
|
||||
if (! empty($peerlist)) {
|
||||
$af_data = [];
|
||||
$af_list = [];
|
||||
|
||||
if (empty($af_data)) {
|
||||
if ($device['os_group'] == 'cisco') {
|
||||
if ($peer2 === true) {
|
||||
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', [], 'CISCO-BGP4-MIB');
|
||||
foreach ($peerlist as $peer) {
|
||||
$peer['astext'] = get_astext($peer['as']);
|
||||
|
||||
add_bgp_peer($device, $peer);
|
||||
|
||||
if (empty($af_data)) {
|
||||
if ($device['os_group'] == 'cisco') {
|
||||
if ($peer2 === true) {
|
||||
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', [], 'CISCO-BGP4-MIB');
|
||||
}
|
||||
if (empty($af_data)) {
|
||||
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', [], 'CISCO-BGP4-MIB');
|
||||
$peer2 = false;
|
||||
}
|
||||
} elseif ($device['os_group'] === 'arista') {
|
||||
$af_data = snmpwalk_cache_oid($device, 'aristaBgp4V2PrefixInPrefixes', $af_data, 'ARISTA-BGP4V2-MIB');
|
||||
} elseif ($device['os'] === 'aos7') {
|
||||
$af_data = snmpwalk_cache_oid($device, 'alaBgpPeerRcvdPrefixes', $af_data, 'ALCATEL-IND1-BGP-MIB');
|
||||
}
|
||||
}
|
||||
|
||||
// build the list
|
||||
if (! empty($af_data)) {
|
||||
$af_list = build_cbgp_peers($device, $peer, $af_data, $peer2);
|
||||
}
|
||||
|
||||
if (! $bgp4_mib && $device['os'] == 'junos') {
|
||||
$afis['ipv4'] = 'ipv4';
|
||||
$afis['ipv6'] = 'ipv6';
|
||||
$afis[25] = 'l2vpn';
|
||||
$safis[1] = 'unicast';
|
||||
$safis[2] = 'multicast';
|
||||
$safis[3] = 'unicastAndMulticast';
|
||||
$safis[4] = 'labeledUnicast';
|
||||
$safis[5] = 'mvpn';
|
||||
$safis[65] = 'vpls';
|
||||
$safis[70] = 'evpn';
|
||||
$safis[128] = 'vpn';
|
||||
$safis[132] = 'rtfilter';
|
||||
$safis[133] = 'flow';
|
||||
|
||||
if (! isset($j_peerIndexes)) {
|
||||
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', [], 'BGP4-V2-MIB-JUNIPER', 'junos');
|
||||
d_echo($j_bgp);
|
||||
$j_peerIndexes = [];
|
||||
foreach ($j_bgp as $index => $entry) {
|
||||
$peer_index = $entry['jnxBgpM2PeerIndex'];
|
||||
try {
|
||||
$ip = IP::fromHexString($entry['jnxBgpM2PeerRemoteAddr']);
|
||||
d_echo('peerindex for ' . $ip->getFamily() . " $ip is $peer_index\n");
|
||||
$j_peerIndexes[(string) $ip] = $peer_index;
|
||||
} catch (InvalidIpException $e) {
|
||||
d_echo("Unable to parse IP for peer $peer_index: " . $entry['jnxBgpM2PeerRemoteAddr'] . PHP_EOL);
|
||||
}
|
||||
if (empty($af_data)) {
|
||||
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', [], 'CISCO-BGP4-MIB');
|
||||
$peer2 = false;
|
||||
}
|
||||
} elseif ($device['os_group'] === 'arista') {
|
||||
$af_data = snmpwalk_cache_oid($device, 'aristaBgp4V2PrefixInPrefixes', $af_data, 'ARISTA-BGP4V2-MIB');
|
||||
} elseif ($device['os'] === 'aos7') {
|
||||
$af_data = snmpwalk_cache_oid($device, 'alaBgpPeerRcvdPrefixes', $af_data, 'ALCATEL-IND1-BGP-MIB');
|
||||
}
|
||||
}
|
||||
|
||||
// build the list
|
||||
if (! empty($af_data)) {
|
||||
$af_list = build_cbgp_peers($device, $peer, $af_data, $peer2);
|
||||
}
|
||||
|
||||
if (! $bgp4_mib && $device['os'] == 'junos') {
|
||||
$afis['ipv4'] = 'ipv4';
|
||||
$afis['ipv6'] = 'ipv6';
|
||||
$afis[25] = 'l2vpn';
|
||||
$safis[1] = 'unicast';
|
||||
$safis[2] = 'multicast';
|
||||
$safis[3] = 'unicastAndMulticast';
|
||||
$safis[4] = 'labeledUnicast';
|
||||
$safis[5] = 'mvpn';
|
||||
$safis[65] = 'vpls';
|
||||
$safis[70] = 'evpn';
|
||||
$safis[128] = 'vpn';
|
||||
$safis[132] = 'rtfilter';
|
||||
$safis[133] = 'flow';
|
||||
|
||||
if (! isset($j_peerIndexes)) {
|
||||
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', [], 'BGP4-V2-MIB-JUNIPER', 'junos');
|
||||
d_echo($j_bgp);
|
||||
$j_peerIndexes = [];
|
||||
foreach ($j_bgp as $index => $entry) {
|
||||
$peer_index = $entry['jnxBgpM2PeerIndex'];
|
||||
try {
|
||||
$ip = IP::fromHexString($entry['jnxBgpM2PeerRemoteAddr']);
|
||||
d_echo('peerindex for ' . $ip->getFamily() . " $ip is $peer_index\n");
|
||||
$j_peerIndexes[(string) $ip] = $peer_index;
|
||||
} catch (InvalidIpException $e) {
|
||||
d_echo("Unable to parse IP for peer $peer_index: " . $entry['jnxBgpM2PeerRemoteAddr'] . PHP_EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! isset($j_afisafi)) {
|
||||
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', [], 'BGP4-V2-MIB-JUNIPER', 'junos');
|
||||
$j_afisafi = [];
|
||||
foreach (array_keys($j_prefixes) as $key) {
|
||||
[$index,$afisafi] = explode('.', $key, 2);
|
||||
$j_afisafi[$index][] = $afisafi;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] ?? [] as $afisafi) {
|
||||
[$afi,$safi] = explode('.', $afisafi);
|
||||
$afi = $afis[$afi];
|
||||
$safi = $safis[$safi];
|
||||
$af_list[$peer['ip']][$afi][$safi] = 1;
|
||||
add_cbgp_peer($device, $peer, $afi, $safi);
|
||||
if (! isset($j_afisafi)) {
|
||||
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', [], 'BGP4-V2-MIB-JUNIPER', 'junos');
|
||||
$j_afisafi = [];
|
||||
foreach (array_keys($j_prefixes) as $key) {
|
||||
[$index,$afisafi] = explode('.', $key, 2);
|
||||
$j_afisafi[$index][] = $afisafi;
|
||||
}
|
||||
}
|
||||
|
||||
$af_query = 'SELECT bgpPeerIdentifier, afi, safi FROM bgpPeers_cbgp WHERE `device_id`=? AND bgpPeerIdentifier=? AND context_name=?';
|
||||
foreach (dbFetchRows($af_query, [$device['device_id'], $peer['ip'], $device['context_name']]) as $entry) {
|
||||
$afi = $entry['afi'];
|
||||
$safi = $entry['safi'];
|
||||
if (! $af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
|
||||
dbDelete(
|
||||
'bgpPeers_cbgp',
|
||||
'`device_id`=? AND `bgpPeerIdentifier`=? AND context_name=? AND afi=? AND safi=?',
|
||||
[$device['device_id'], $peer['ip'], $device['context_name'], $afi, $safi]
|
||||
);
|
||||
}
|
||||
foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] ?? [] as $afisafi) {
|
||||
[$afi,$safi] = explode('.', $afisafi);
|
||||
$afi = $afis[$afi];
|
||||
$safi = $safis[$safi];
|
||||
$af_list[$peer['ip']][$afi][$safi] = 1;
|
||||
add_cbgp_peer($device, $peer, $afi, $safi);
|
||||
}
|
||||
}
|
||||
|
||||
$af_query = 'SELECT bgpPeerIdentifier, afi, safi FROM bgpPeers_cbgp WHERE `device_id`=? AND bgpPeerIdentifier=? AND context_name=?';
|
||||
foreach (dbFetchRows($af_query, [$device['device_id'], $peer['ip'], $device['context_name']]) as $entry) {
|
||||
$afi = $entry['afi'];
|
||||
$safi = $entry['safi'];
|
||||
if (! $af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
|
||||
dbDelete(
|
||||
'bgpPeers_cbgp',
|
||||
'`device_id`=? AND `bgpPeerIdentifier`=? AND context_name=? AND afi=? AND safi=?',
|
||||
[$device['device_id'], $peer['ip'], $device['context_name'], $afi, $safi]
|
||||
);
|
||||
}
|
||||
}
|
||||
unset($j_afisafi);
|
||||
unset($j_prefixes);
|
||||
unset($j_bgp);
|
||||
unset($j_peerIndexes);
|
||||
}
|
||||
|
||||
// clean up peers
|
||||
$params = [$device['device_id'], $device['context_name']];
|
||||
$query = 'device_id=? AND context_name=?';
|
||||
if (! empty($peerlist)) {
|
||||
$query .= ' AND bgpPeerIdentifier NOT IN ' . dbGenPlaceholders(count($peerlist));
|
||||
$params = array_merge($params, array_column($peerlist, 'ip'));
|
||||
}
|
||||
|
||||
$deleted = dbDelete('bgpPeers', $query, $params);
|
||||
dbDelete('bgpPeers_cbgp', $query, $params);
|
||||
|
||||
echo str_repeat('-', $deleted);
|
||||
echo PHP_EOL;
|
||||
|
||||
unset(
|
||||
$device['context_name'],
|
||||
$peerlist,
|
||||
$af_data
|
||||
);
|
||||
unset($j_afisafi);
|
||||
unset($j_prefixes);
|
||||
unset($j_bgp);
|
||||
unset($j_peerIndexes);
|
||||
}
|
||||
|
||||
// delete unknown contexts
|
||||
$contexts = dbFetchColumn(
|
||||
'SELECT DISTINCT context_name FROM bgpPeers WHERE device_id=?',
|
||||
[$device['device_id']]
|
||||
);
|
||||
|
||||
$existing_contexts = DeviceCache::getPrimary()->getVrfContexts();
|
||||
foreach ($contexts as $context) {
|
||||
if (! in_array($context, $existing_contexts)) {
|
||||
dbDelete('bgpPeers', 'device_id=? and context_name=?', [$device['device_id'], $context]);
|
||||
dbDelete('bgpPeers_cbgp', 'device_id=? and context_name=?', [$device['device_id'], $context]);
|
||||
echo '-';
|
||||
}
|
||||
// clean up peers
|
||||
$params = [$device['device_id'], $device['context_name']];
|
||||
$query = 'device_id=? AND context_name=?';
|
||||
if (! empty($peerlist)) {
|
||||
$query .= ' AND bgpPeerIdentifier NOT IN ' . dbGenPlaceholders(count($peerlist));
|
||||
$params = array_merge($params, array_column($peerlist, 'ip'));
|
||||
}
|
||||
|
||||
$deleted = dbDelete('bgpPeers', $query, $params);
|
||||
dbDelete('bgpPeers_cbgp', $query, $params);
|
||||
|
||||
echo str_repeat('-', $deleted);
|
||||
echo PHP_EOL;
|
||||
|
||||
unset(
|
||||
$device['context_name'],
|
||||
$peers_data,
|
||||
$af_data,
|
||||
$contexts
|
||||
$peerlist,
|
||||
$af_data
|
||||
);
|
||||
}
|
||||
|
||||
// delete unknown contexts
|
||||
$contexts = dbFetchColumn(
|
||||
'SELECT DISTINCT context_name FROM bgpPeers WHERE device_id=?',
|
||||
[$device['device_id']]
|
||||
);
|
||||
|
||||
$existing_contexts = DeviceCache::getPrimary()->getVrfContexts();
|
||||
foreach ($contexts as $context) {
|
||||
if (! in_array($context, $existing_contexts)) {
|
||||
dbDelete('bgpPeers', 'device_id=? and context_name=?', [$device['device_id'], $context]);
|
||||
dbDelete('bgpPeers_cbgp', 'device_id=? and context_name=?', [$device['device_id'], $context]);
|
||||
echo '-';
|
||||
}
|
||||
}
|
||||
|
||||
unset(
|
||||
$device['context_name'],
|
||||
$peers_data,
|
||||
$af_data,
|
||||
$contexts
|
||||
);
|
||||
|
@@ -29,92 +29,90 @@ use App\Models\Vrf;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\IP;
|
||||
|
||||
if (Config::get('enable_bgp')) {
|
||||
if ($device['os'] == 'dell-os10') {
|
||||
$bgpPeersCache = snmpwalk_cache_multi_oid($device, 'os10bgp4V2PeerTable', [], 'DELLEMC-OS10-BGP4V2-MIB', 'dell');
|
||||
foreach ($bgpPeersCache as $key => $value) {
|
||||
$oid = explode('.', $key);
|
||||
$vrfInstance = array_shift($oid); // os10bgp4V2PeerInstance
|
||||
$remoteAddressType = array_shift($oid); // os10bgp4V2PeerRemoteAddrType
|
||||
$address = IP::fromSnmpString(implode(' ', $oid))->compressed(); // os10bgp4V2PeerRemoteAddr
|
||||
$bgpPeers[$vrfInstance][$address] = $value;
|
||||
}
|
||||
unset($bgpPeersCache);
|
||||
|
||||
$vrfs = DeviceCache::getPrimary()->vrfs->pluck('vrf_id', 'vrf_oid');
|
||||
|
||||
foreach ($bgpPeers as $vrfInstance => $peer) {
|
||||
$vrfId = $vrfs->get($vrfInstance, 1); // According to the MIB
|
||||
|
||||
foreach ($peer as $address => $value) {
|
||||
// resolve AS number by DNS_TXT record
|
||||
$astext = get_astext($value['os10bgp4V2PeerRemoteAs']);
|
||||
|
||||
// FIXME - the `devices` table gets updated in the main bgp-peers.inc.php
|
||||
// Setting it here avoids the code that resets it to null if not found in BGP4-MIB.
|
||||
$bgpLocalAs = $value['os10bgp4V2PeerLocalAs'];
|
||||
|
||||
if (! DeviceCache::getPrimary()->bgppeers()->where('bgpPeerIdentifier', $address)->where('vrf_id', $vrfId)->exists()) {
|
||||
$row = [
|
||||
'vrf_id' => $vrfId,
|
||||
'bgpPeerIdentifier' => $address,
|
||||
'bgpPeerRemoteAs' => $value['os10bgp4V2PeerRemoteAs'],
|
||||
'bgpPeerState' => 'idle',
|
||||
'bgpPeerAdminStatus' => 'stop',
|
||||
'bgpLocalAddr' => '0.0.0.0',
|
||||
'bgpPeerRemoteAddr' => '0.0.0.0',
|
||||
'bgpPeerInUpdates' => 0,
|
||||
'bgpPeerOutUpdates' => 0,
|
||||
'bgpPeerInTotalMessages' => 0,
|
||||
'bgpPeerOutTotalMessages' => 0,
|
||||
'bgpPeerFsmEstablishedTime' => 0,
|
||||
'bgpPeerInUpdateElapsedTime' => 0,
|
||||
'astext' => $astext,
|
||||
];
|
||||
DeviceCache::getPrimary()->bgppeers()->create($row);
|
||||
|
||||
if (Config::get('autodiscovery.bgp')) {
|
||||
$name = gethostbyaddr($address);
|
||||
discover_new_device($name, $device, 'BGP');
|
||||
}
|
||||
echo '+';
|
||||
} else {
|
||||
BgpPeer::where('bgpPeerRemoteAs', $value['os10bgp4V2PeerRemoteAs'])->where('astext', $astext)->update(['bgpPeerIdentifier' => $address, 'device_id' => $device['device_id'], 'vrf_id' => $vrfId]);
|
||||
echo '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$af_data = snmpwalk_cache_oid($device, 'os10bgp4V2PrefixInPrefixes', [], 'DELLEMC-OS10-BGP4V2-MIB', 'dell');
|
||||
foreach ($af_data as $key => $value) {
|
||||
$oid = explode('.', $key);
|
||||
$vrfInstance = array_shift($oid); // os10bgp4V2PeerInstance
|
||||
$remoteAddressType = array_shift($oid); // os10bgp4V2PeerRemoteAddrType
|
||||
$safi = array_pop($oid); // os10bgp4V2PrefixGaugesSafi
|
||||
$afi = array_pop($oid); // os10bgp4V2PrefixGaugesAfi
|
||||
$address = IP::fromSnmpString(implode(' ', $oid))->compressed(); // os10bgp4V2PeerRemoteAddr
|
||||
// add to `bgpPeers_cbgp` table
|
||||
add_cbgp_peer($device, ['ip' => $address], $afi, $safi);
|
||||
}
|
||||
|
||||
// clean up peers
|
||||
if (Vrf::where('device_id', $device['device_id'])->count() == 0) {
|
||||
$peers = BgpPeer::select('vrf_id', 'bgpPeerIdentifier')->where('device_id', $device['device_id']);
|
||||
} else {
|
||||
$peers = dbFetchRows('SELECT `B`.`vrf_id` AS `vrf_id`, `bgpPeerIdentifier` FROM `bgpPeers` AS B LEFT JOIN `vrfs` AS V ON `B`.`vrf_id` = `V`.`vrf_id` WHERE `B`.`device_id` = ?', [$device['device_id']]);
|
||||
}
|
||||
foreach ($peers as $peer) {
|
||||
$vrfId = $peer['vrf_id'];
|
||||
$address = $peer['bgpPeerIdentifier'];
|
||||
|
||||
if (empty($bgpPeers[$vrfInstance][$address])) {
|
||||
$deleted = BgpPeer::where('device_id', $device['device_id'])->where('bgpPeerIdentifier', $address)->where('vrf_id', $vrfId)->delete();
|
||||
|
||||
echo str_repeat('-', $deleted);
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
unset($bgpPeers);
|
||||
// No return statement here, so standard BGP mib will still be polled after this file is executed.
|
||||
if ($device['os'] == 'dell-os10') {
|
||||
$bgpPeersCache = snmpwalk_cache_multi_oid($device, 'os10bgp4V2PeerTable', [], 'DELLEMC-OS10-BGP4V2-MIB', 'dell');
|
||||
foreach ($bgpPeersCache as $key => $value) {
|
||||
$oid = explode('.', $key);
|
||||
$vrfInstance = array_shift($oid); // os10bgp4V2PeerInstance
|
||||
$remoteAddressType = array_shift($oid); // os10bgp4V2PeerRemoteAddrType
|
||||
$address = IP::fromSnmpString(implode(' ', $oid))->compressed(); // os10bgp4V2PeerRemoteAddr
|
||||
$bgpPeers[$vrfInstance][$address] = $value;
|
||||
}
|
||||
unset($bgpPeersCache);
|
||||
|
||||
$vrfs = DeviceCache::getPrimary()->vrfs->pluck('vrf_id', 'vrf_oid');
|
||||
|
||||
foreach ($bgpPeers as $vrfInstance => $peer) {
|
||||
$vrfId = $vrfs->get($vrfInstance, 1); // According to the MIB
|
||||
|
||||
foreach ($peer as $address => $value) {
|
||||
// resolve AS number by DNS_TXT record
|
||||
$astext = get_astext($value['os10bgp4V2PeerRemoteAs']);
|
||||
|
||||
// FIXME - the `devices` table gets updated in the main bgp-peers.inc.php
|
||||
// Setting it here avoids the code that resets it to null if not found in BGP4-MIB.
|
||||
$bgpLocalAs = $value['os10bgp4V2PeerLocalAs'];
|
||||
|
||||
if (! DeviceCache::getPrimary()->bgppeers()->where('bgpPeerIdentifier', $address)->where('vrf_id', $vrfId)->exists()) {
|
||||
$row = [
|
||||
'vrf_id' => $vrfId,
|
||||
'bgpPeerIdentifier' => $address,
|
||||
'bgpPeerRemoteAs' => $value['os10bgp4V2PeerRemoteAs'],
|
||||
'bgpPeerState' => 'idle',
|
||||
'bgpPeerAdminStatus' => 'stop',
|
||||
'bgpLocalAddr' => '0.0.0.0',
|
||||
'bgpPeerRemoteAddr' => '0.0.0.0',
|
||||
'bgpPeerInUpdates' => 0,
|
||||
'bgpPeerOutUpdates' => 0,
|
||||
'bgpPeerInTotalMessages' => 0,
|
||||
'bgpPeerOutTotalMessages' => 0,
|
||||
'bgpPeerFsmEstablishedTime' => 0,
|
||||
'bgpPeerInUpdateElapsedTime' => 0,
|
||||
'astext' => $astext,
|
||||
];
|
||||
DeviceCache::getPrimary()->bgppeers()->create($row);
|
||||
|
||||
if (Config::get('autodiscovery.bgp')) {
|
||||
$name = gethostbyaddr($address);
|
||||
discover_new_device($name, $device, 'BGP');
|
||||
}
|
||||
echo '+';
|
||||
} else {
|
||||
BgpPeer::where('bgpPeerRemoteAs', $value['os10bgp4V2PeerRemoteAs'])->where('astext', $astext)->update(['bgpPeerIdentifier' => $address, 'device_id' => $device['device_id'], 'vrf_id' => $vrfId]);
|
||||
echo '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$af_data = snmpwalk_cache_oid($device, 'os10bgp4V2PrefixInPrefixes', [], 'DELLEMC-OS10-BGP4V2-MIB', 'dell');
|
||||
foreach ($af_data as $key => $value) {
|
||||
$oid = explode('.', $key);
|
||||
$vrfInstance = array_shift($oid); // os10bgp4V2PeerInstance
|
||||
$remoteAddressType = array_shift($oid); // os10bgp4V2PeerRemoteAddrType
|
||||
$safi = array_pop($oid); // os10bgp4V2PrefixGaugesSafi
|
||||
$afi = array_pop($oid); // os10bgp4V2PrefixGaugesAfi
|
||||
$address = IP::fromSnmpString(implode(' ', $oid))->compressed(); // os10bgp4V2PeerRemoteAddr
|
||||
// add to `bgpPeers_cbgp` table
|
||||
add_cbgp_peer($device, ['ip' => $address], $afi, $safi);
|
||||
}
|
||||
|
||||
// clean up peers
|
||||
if (Vrf::where('device_id', $device['device_id'])->count() == 0) {
|
||||
$peers = BgpPeer::select('vrf_id', 'bgpPeerIdentifier')->where('device_id', $device['device_id']);
|
||||
} else {
|
||||
$peers = dbFetchRows('SELECT `B`.`vrf_id` AS `vrf_id`, `bgpPeerIdentifier` FROM `bgpPeers` AS B LEFT JOIN `vrfs` AS V ON `B`.`vrf_id` = `V`.`vrf_id` WHERE `B`.`device_id` = ?', [$device['device_id']]);
|
||||
}
|
||||
foreach ($peers as $peer) {
|
||||
$vrfId = $peer['vrf_id'];
|
||||
$address = $peer['bgpPeerIdentifier'];
|
||||
|
||||
if (empty($bgpPeers[$vrfInstance][$address])) {
|
||||
$deleted = BgpPeer::where('device_id', $device['device_id'])->where('bgpPeerIdentifier', $address)->where('vrf_id', $vrfId)->delete();
|
||||
|
||||
echo str_repeat('-', $deleted);
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
unset($bgpPeers);
|
||||
// No return statement here, so standard BGP mib will still be polled after this file is executed.
|
||||
}
|
||||
|
@@ -27,75 +27,73 @@
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\IP;
|
||||
|
||||
if (Config::get('enable_bgp')) {
|
||||
if ($device['os'] == 'timos') {
|
||||
$bgpPeersCache = snmpwalk_cache_multi_oid($device, 'tBgpPeerNgTable', [], 'TIMETRA-BGP-MIB', 'nokia');
|
||||
foreach ($bgpPeersCache as $key => $value) {
|
||||
$oid = explode('.', $key);
|
||||
$vrfInstance = $oid[0];
|
||||
$address = str_replace($oid[0] . '.' . $oid[1] . '.', '', $key);
|
||||
if (strlen($address) > 15) {
|
||||
$address = IP::fromHexString($address)->compressed();
|
||||
}
|
||||
$bgpPeers[$vrfInstance][$address] = $value;
|
||||
if ($device['os'] == 'timos') {
|
||||
$bgpPeersCache = snmpwalk_cache_multi_oid($device, 'tBgpPeerNgTable', [], 'TIMETRA-BGP-MIB', 'nokia');
|
||||
foreach ($bgpPeersCache as $key => $value) {
|
||||
$oid = explode('.', $key);
|
||||
$vrfInstance = $oid[0];
|
||||
$address = str_replace($oid[0] . '.' . $oid[1] . '.', '', $key);
|
||||
if (strlen($address) > 15) {
|
||||
$address = IP::fromHexString($address)->compressed();
|
||||
}
|
||||
unset($bgpPeersCache);
|
||||
|
||||
foreach ($bgpPeers as $vrfOid => $vrf) {
|
||||
$vrfId = dbFetchCell('SELECT vrf_id from `vrfs` WHERE vrf_oid = ?', [$vrfOid]);
|
||||
d_echo($vrfId);
|
||||
foreach ($vrf as $address => $value) {
|
||||
$astext = get_astext($value['tBgpPeerNgPeerAS4Byte']);
|
||||
|
||||
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ? AND vrf_id = ?', [$device['device_id'], $address, $vrfId]) < '1') {
|
||||
$peers = [
|
||||
'device_id' => $device['device_id'],
|
||||
'vrf_id' => $vrfId,
|
||||
'bgpPeerIdentifier' => $address,
|
||||
'bgpPeerRemoteAs' => $value['tBgpPeerNgPeerAS4Byte'],
|
||||
'bgpPeerState' => 'idle',
|
||||
'bgpPeerAdminStatus' => 'stop',
|
||||
'bgpLocalAddr' => '0.0.0.0',
|
||||
'bgpPeerRemoteAddr' => '0.0.0.0',
|
||||
'bgpPeerInUpdates' => 0,
|
||||
'bgpPeerOutUpdates' => 0,
|
||||
'bgpPeerInTotalMessages' => 0,
|
||||
'bgpPeerOutTotalMessages' => 0,
|
||||
'bgpPeerFsmEstablishedTime' => 0,
|
||||
'bgpPeerInUpdateElapsedTime' => 0,
|
||||
'astext' => $astext,
|
||||
];
|
||||
dbInsert($peers, 'bgpPeers');
|
||||
if (Config::get('autodiscovery.bgp')) {
|
||||
$name = gethostbyaddr($address);
|
||||
discover_new_device($name, $device, 'BGP');
|
||||
}
|
||||
echo '+';
|
||||
} else {
|
||||
dbUpdate(['bgpPeerRemoteAs' => $value['tBgpPeerNgPeerAS4Byte'], 'astext' => $astext], 'bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? AND vrf_id = ?', [$device['device_id'], $address, $vrfId]);
|
||||
echo '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean up peers
|
||||
$peers = dbFetchRows('SELECT `B`.`vrf_id` AS `vrf_id`, `bgpPeerIdentifier`, `vrf_oid` FROM `bgpPeers` AS B LEFT JOIN `vrfs` AS V ON `B`.`vrf_id` = `V`.`vrf_id` WHERE `B`.`device_id` = ?', [$device['device_id']]);
|
||||
foreach ($peers as $value) {
|
||||
$vrfId = $value['vrf_id'];
|
||||
$checkVrf = ' AND vrf_id = ? ';
|
||||
if (empty($vrfId)) {
|
||||
$checkVrf = ' AND `vrf_id` IS NULL ';
|
||||
}
|
||||
$vrfOid = $value['vrf_oid'];
|
||||
$address = $value['bgpPeerIdentifier'];
|
||||
|
||||
if (empty($bgpPeers[$vrfOid][$address])) {
|
||||
$deleted = dbDelete('bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? ' . $checkVrf, [$device['device_id'], $address, $vrfId]);
|
||||
|
||||
echo str_repeat('-', $deleted);
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
unset($bgpPeers);
|
||||
// No return statement here, so standard BGP mib will still be polled after this file is executed.
|
||||
$bgpPeers[$vrfInstance][$address] = $value;
|
||||
}
|
||||
unset($bgpPeersCache);
|
||||
|
||||
foreach ($bgpPeers as $vrfOid => $vrf) {
|
||||
$vrfId = dbFetchCell('SELECT vrf_id from `vrfs` WHERE vrf_oid = ?', [$vrfOid]);
|
||||
d_echo($vrfId);
|
||||
foreach ($vrf as $address => $value) {
|
||||
$astext = get_astext($value['tBgpPeerNgPeerAS4Byte']);
|
||||
|
||||
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ? AND vrf_id = ?', [$device['device_id'], $address, $vrfId]) < '1') {
|
||||
$peers = [
|
||||
'device_id' => $device['device_id'],
|
||||
'vrf_id' => $vrfId,
|
||||
'bgpPeerIdentifier' => $address,
|
||||
'bgpPeerRemoteAs' => $value['tBgpPeerNgPeerAS4Byte'],
|
||||
'bgpPeerState' => 'idle',
|
||||
'bgpPeerAdminStatus' => 'stop',
|
||||
'bgpLocalAddr' => '0.0.0.0',
|
||||
'bgpPeerRemoteAddr' => '0.0.0.0',
|
||||
'bgpPeerInUpdates' => 0,
|
||||
'bgpPeerOutUpdates' => 0,
|
||||
'bgpPeerInTotalMessages' => 0,
|
||||
'bgpPeerOutTotalMessages' => 0,
|
||||
'bgpPeerFsmEstablishedTime' => 0,
|
||||
'bgpPeerInUpdateElapsedTime' => 0,
|
||||
'astext' => $astext,
|
||||
];
|
||||
dbInsert($peers, 'bgpPeers');
|
||||
if (Config::get('autodiscovery.bgp')) {
|
||||
$name = gethostbyaddr($address);
|
||||
discover_new_device($name, $device, 'BGP');
|
||||
}
|
||||
echo '+';
|
||||
} else {
|
||||
dbUpdate(['bgpPeerRemoteAs' => $value['tBgpPeerNgPeerAS4Byte'], 'astext' => $astext], 'bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? AND vrf_id = ?', [$device['device_id'], $address, $vrfId]);
|
||||
echo '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean up peers
|
||||
$peers = dbFetchRows('SELECT `B`.`vrf_id` AS `vrf_id`, `bgpPeerIdentifier`, `vrf_oid` FROM `bgpPeers` AS B LEFT JOIN `vrfs` AS V ON `B`.`vrf_id` = `V`.`vrf_id` WHERE `B`.`device_id` = ?', [$device['device_id']]);
|
||||
foreach ($peers as $value) {
|
||||
$vrfId = $value['vrf_id'];
|
||||
$checkVrf = ' AND vrf_id = ? ';
|
||||
if (empty($vrfId)) {
|
||||
$checkVrf = ' AND `vrf_id` IS NULL ';
|
||||
}
|
||||
$vrfOid = $value['vrf_oid'];
|
||||
$address = $value['bgpPeerIdentifier'];
|
||||
|
||||
if (empty($bgpPeers[$vrfOid][$address])) {
|
||||
$deleted = dbDelete('bgpPeers', 'device_id = ? AND bgpPeerIdentifier = ? ' . $checkVrf, [$device['device_id'], $address, $vrfId]);
|
||||
|
||||
echo str_repeat('-', $deleted);
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
unset($bgpPeers);
|
||||
// No return statement here, so standard BGP mib will still be polled after this file is executed.
|
||||
}
|
||||
|
@@ -27,146 +27,144 @@
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\IP;
|
||||
|
||||
if (Config::get('enable_bgp')) {
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerRemoteAs', [], 'HUAWEI-BGP-VPN-MIB');
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerRemoteAs', [], 'HUAWEI-BGP-VPN-MIB');
|
||||
|
||||
if (count($bgpPeersCache) == 0) {
|
||||
//Either we have no BGP peer, or this VRP device does not support Huawei's own BGP MIB
|
||||
//Let's compare with standard BGP4-MIB.
|
||||
$bgpPeersCache_ietf = snmpwalk_cache_oid($device, 'bgpPeerRemoteAs', [], 'BGP4-MIB');
|
||||
}
|
||||
|
||||
// So if we have HUAWEI BGP entries or if we don't have anything from HUAWEI nor BGP4-MIB
|
||||
if (count($bgpPeersCache) > 0 || count($bgpPeersCache_ietf) == 0) {
|
||||
$vrfs = DeviceCache::getPrimary()->vrfs()->select('vrf_id', 'vrf_name')->get();
|
||||
foreach ($vrfs as $vrf) {
|
||||
$map_vrf['byId'][$vrf['vrf_id']]['vrf_name'] = $vrf['vrf_name'];
|
||||
$map_vrf['byName'][$vrf['vrf_name']]['vrf_id'] = $vrf['vrf_id'];
|
||||
}
|
||||
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerAddrFamilyTable', $bgpPeersCache, 'HUAWEI-BGP-VPN-MIB');
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerTable', $bgpPeersCache, 'HUAWEI-BGP-VPN-MIB');
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerRouteTable', $bgpPeersCache, 'HUAWEI-BGP-VPN-MIB');
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerSessionTable', $bgpPeersCache, 'HUAWEI-BGP-VPN-MIB');
|
||||
|
||||
$bgpPeersDesc = snmpwalk_cache_oid($device, 'hwBgpPeerSessionExtDescription', [], 'HUAWEI-BGP-VPN-MIB');
|
||||
|
||||
foreach ($bgpPeersCache as $key => $value) {
|
||||
$oid = explode('.', $key);
|
||||
$vrfInstance = $value['hwBgpPeerVrfName'];
|
||||
if ($oid[0] == 0) {
|
||||
$vrfInstance = '';
|
||||
$value['hwBgpPeerVrfName'] = '';
|
||||
}
|
||||
$oid_address = str_replace($oid[0] . '.' . $oid[1] . '.' . $oid[2] . '.' . $oid[3] . '.', '', $key);
|
||||
if ($oid[3] == 'ipv4') {
|
||||
$address = $oid_address;
|
||||
} elseif ($oid[3] == 'ipv6') {
|
||||
$address = IP::fromHexString($oid_address)->compressed();
|
||||
} else {
|
||||
// we have a malformed OID reply, let's skip it
|
||||
continue;
|
||||
}
|
||||
|
||||
$bgpPeers[$vrfInstance][$address] = $value;
|
||||
$bgpPeers[$vrfInstance][$address]['vrf_id'] = $map_vrf['byName'][$vrfInstance]['vrf_id'] ?? null;
|
||||
$bgpPeers[$vrfInstance][$address]['afi'] = $oid[1];
|
||||
$bgpPeers[$vrfInstance][$address]['safi'] = $oid[2];
|
||||
$bgpPeers[$vrfInstance][$address]['typePeer'] = $oid[3];
|
||||
$bgpPeers[$vrfInstance][$address]['bgpPeerDescr'] = '';
|
||||
if (array_key_exists('0.' . $oid[3] . '.' . $oid_address, $bgpPeersDesc)) {
|
||||
// We may have a description
|
||||
$bgpPeers[$vrfInstance][$address]['bgpPeerDescr'] = $bgpPeersDesc['0.' . $oid[3] . '.' . $oid_address]['hwBgpPeerSessionExtDescription'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($bgpPeers as $vrfName => $vrf) {
|
||||
$vrfId = $map_vrf['byName'][$vrfName]['vrf_id'];
|
||||
|
||||
foreach ($vrf as $address => $value) {
|
||||
$astext = get_astext($value['hwBgpPeerRemoteAs']);
|
||||
if (! DeviceCache::getPrimary()->bgppeers()->where('bgpPeerIdentifier', $address)->where('vrf_id', $vrfId)->exists()) {
|
||||
$peers = [
|
||||
'device_id' => $device['device_id'],
|
||||
'vrf_id' => $vrfId,
|
||||
'bgpPeerIdentifier' => $address,
|
||||
'bgpPeerRemoteAs' => $value['hwBgpPeerRemoteAs'] ?? '',
|
||||
'bgpPeerState' => $value['hwBgpPeerState'] ?? '',
|
||||
'bgpPeerAdminStatus' => $value['hwBgpPeerAdminStatus'] ?? '',
|
||||
'bgpLocalAddr' => '0.0.0.0',
|
||||
'bgpPeerRemoteAddr' => $value['hwBgpPeerRemoteAddr'],
|
||||
'bgpPeerInUpdates' => 0,
|
||||
'bgpPeerOutUpdates' => 0,
|
||||
'bgpPeerInTotalMessages' => 0,
|
||||
'bgpPeerOutTotalMessages' => 0,
|
||||
'bgpPeerFsmEstablishedTime' => $value['hwBgpPeerFsmEstablishedTime'],
|
||||
'bgpPeerInUpdateElapsedTime' => 0,
|
||||
'bgpPeerDescr' => $value['bgpPeerDescr'] ?? '',
|
||||
'astext' => $astext,
|
||||
];
|
||||
if (empty($vrfId)) {
|
||||
unset($peers['vrf_id']);
|
||||
}
|
||||
$seenPeerID[] = DeviceCache::getPrimary()->bgppeers()->create($peers)->bgpPeer_id;
|
||||
|
||||
if (Config::get('autodiscovery.bgp')) {
|
||||
$name = gethostbyaddr($address);
|
||||
discover_new_device($name, $device, 'BGP');
|
||||
}
|
||||
echo '+';
|
||||
$vrp_bgp_peer_count++;
|
||||
} else {
|
||||
$peers = [
|
||||
'bgpPeerRemoteAs' => $value['hwBgpPeerRemoteAs'],
|
||||
'astext' => $astext,
|
||||
'bgpPeerDescr' => $value['bgpPeerDescr'] ?? '',
|
||||
];
|
||||
$affected = DeviceCache::getPrimary()->bgppeers()->where('bgpPeerIdentifier', $address)->where('vrf_id', $vrfId)->update($peers);
|
||||
$seenPeerID[] = DeviceCache::getPrimary()->bgppeers()->where('bgpPeerIdentifier', $address)->where('vrf_id', $vrfId)->select('bgpPeer_id')->orderBy('bgpPeer_id', 'ASC')->first()->bgpPeer_id;
|
||||
|
||||
echo str_repeat('.', $affected);
|
||||
$vrp_bgp_peer_count += $affected;
|
||||
}
|
||||
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', [$device['device_id'], $value['hwBgpPeerRemoteAddr'], $value['afi'], $value['safi']]) < 1) {
|
||||
if ($vrfName != '') {
|
||||
$device['context_name'] = $vrfName;
|
||||
}
|
||||
add_cbgp_peer($device, ['ip' => $value['hwBgpPeerRemoteAddr']], $value['afi'], $value['safi']);
|
||||
unset($device['context_name']);
|
||||
} else {
|
||||
//nothing to update
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean up peers
|
||||
|
||||
if (! is_null($seenPeerID)) {
|
||||
$deleted = DeviceCache::getPrimary()->bgppeers()->whereNotIn('bgpPeer_id', $seenPeerID)->delete();
|
||||
echo str_repeat('-', $deleted);
|
||||
}
|
||||
|
||||
$af_query = 'SELECT bgpPeerIdentifier, afi, safi FROM bgpPeers_cbgp WHERE `device_id`=? AND bgpPeerIdentifier=?';
|
||||
foreach (dbFetchRows($af_query, [$device['device_id'], $peer['ip']]) as $entry) {
|
||||
$afi = $entry['afi'];
|
||||
$safi = $entry['safi'];
|
||||
$vrfName = $entry['context_name'];
|
||||
if (! isset($bgpPeersCache[$vrfName]) ||
|
||||
! isset($bgpPeersCache[$vrfName][$entry['bgpPeerIdentifier']]) ||
|
||||
$bgpPeersCache[$vrfName][$entry['bgpPeerIdentifier']][$entry['afi']] != $afi ||
|
||||
$bgpPeersCache[$vrfName][$entry['bgpPeerIdentifier']][$entry['safi']] != $safi) {
|
||||
dbDelete(
|
||||
'bgpPeers_cbgp',
|
||||
'`device_id`=? AND `bgpPeerIdentifier`=? AND context_name=? AND afi=? AND safi=?',
|
||||
[$device['device_id'], $address, $vrfName, $afi, $safi]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
unset($bgpPeersCache);
|
||||
unset($bgpPeers);
|
||||
if ($vrp_bgp_peer_count > 0) {
|
||||
return; //Finish BGP discovery here, cause we already collected data with Huawei MIBs
|
||||
}
|
||||
}
|
||||
// If not, we continue with standard BGP4 MIB
|
||||
if (count($bgpPeersCache) == 0) {
|
||||
//Either we have no BGP peer, or this VRP device does not support Huawei's own BGP MIB
|
||||
//Let's compare with standard BGP4-MIB.
|
||||
$bgpPeersCache_ietf = snmpwalk_cache_oid($device, 'bgpPeerRemoteAs', [], 'BGP4-MIB');
|
||||
}
|
||||
|
||||
// So if we have HUAWEI BGP entries or if we don't have anything from HUAWEI nor BGP4-MIB
|
||||
if (count($bgpPeersCache) > 0 || count($bgpPeersCache_ietf) == 0) {
|
||||
$vrfs = DeviceCache::getPrimary()->vrfs()->select('vrf_id', 'vrf_name')->get();
|
||||
foreach ($vrfs as $vrf) {
|
||||
$map_vrf['byId'][$vrf['vrf_id']]['vrf_name'] = $vrf['vrf_name'];
|
||||
$map_vrf['byName'][$vrf['vrf_name']]['vrf_id'] = $vrf['vrf_id'];
|
||||
}
|
||||
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerAddrFamilyTable', $bgpPeersCache, 'HUAWEI-BGP-VPN-MIB');
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerTable', $bgpPeersCache, 'HUAWEI-BGP-VPN-MIB');
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerRouteTable', $bgpPeersCache, 'HUAWEI-BGP-VPN-MIB');
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerSessionTable', $bgpPeersCache, 'HUAWEI-BGP-VPN-MIB');
|
||||
|
||||
$bgpPeersDesc = snmpwalk_cache_oid($device, 'hwBgpPeerSessionExtDescription', [], 'HUAWEI-BGP-VPN-MIB');
|
||||
|
||||
foreach ($bgpPeersCache as $key => $value) {
|
||||
$oid = explode('.', $key);
|
||||
$vrfInstance = $value['hwBgpPeerVrfName'];
|
||||
if ($oid[0] == 0) {
|
||||
$vrfInstance = '';
|
||||
$value['hwBgpPeerVrfName'] = '';
|
||||
}
|
||||
$oid_address = str_replace($oid[0] . '.' . $oid[1] . '.' . $oid[2] . '.' . $oid[3] . '.', '', $key);
|
||||
if ($oid[3] == 'ipv4') {
|
||||
$address = $oid_address;
|
||||
} elseif ($oid[3] == 'ipv6') {
|
||||
$address = IP::fromHexString($oid_address)->compressed();
|
||||
} else {
|
||||
// we have a malformed OID reply, let's skip it
|
||||
continue;
|
||||
}
|
||||
|
||||
$bgpPeers[$vrfInstance][$address] = $value;
|
||||
$bgpPeers[$vrfInstance][$address]['vrf_id'] = $map_vrf['byName'][$vrfInstance]['vrf_id'] ?? null;
|
||||
$bgpPeers[$vrfInstance][$address]['afi'] = $oid[1];
|
||||
$bgpPeers[$vrfInstance][$address]['safi'] = $oid[2];
|
||||
$bgpPeers[$vrfInstance][$address]['typePeer'] = $oid[3];
|
||||
$bgpPeers[$vrfInstance][$address]['bgpPeerDescr'] = '';
|
||||
if (array_key_exists('0.' . $oid[3] . '.' . $oid_address, $bgpPeersDesc)) {
|
||||
// We may have a description
|
||||
$bgpPeers[$vrfInstance][$address]['bgpPeerDescr'] = $bgpPeersDesc['0.' . $oid[3] . '.' . $oid_address]['hwBgpPeerSessionExtDescription'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($bgpPeers as $vrfName => $vrf) {
|
||||
$vrfId = $map_vrf['byName'][$vrfName]['vrf_id'];
|
||||
|
||||
foreach ($vrf as $address => $value) {
|
||||
$astext = get_astext($value['hwBgpPeerRemoteAs']);
|
||||
if (! DeviceCache::getPrimary()->bgppeers()->where('bgpPeerIdentifier', $address)->where('vrf_id', $vrfId)->exists()) {
|
||||
$peers = [
|
||||
'device_id' => $device['device_id'],
|
||||
'vrf_id' => $vrfId,
|
||||
'bgpPeerIdentifier' => $address,
|
||||
'bgpPeerRemoteAs' => $value['hwBgpPeerRemoteAs'] ?? '',
|
||||
'bgpPeerState' => $value['hwBgpPeerState'] ?? '',
|
||||
'bgpPeerAdminStatus' => $value['hwBgpPeerAdminStatus'] ?? '',
|
||||
'bgpLocalAddr' => '0.0.0.0',
|
||||
'bgpPeerRemoteAddr' => $value['hwBgpPeerRemoteAddr'],
|
||||
'bgpPeerInUpdates' => 0,
|
||||
'bgpPeerOutUpdates' => 0,
|
||||
'bgpPeerInTotalMessages' => 0,
|
||||
'bgpPeerOutTotalMessages' => 0,
|
||||
'bgpPeerFsmEstablishedTime' => $value['hwBgpPeerFsmEstablishedTime'],
|
||||
'bgpPeerInUpdateElapsedTime' => 0,
|
||||
'bgpPeerDescr' => $value['bgpPeerDescr'] ?? '',
|
||||
'astext' => $astext,
|
||||
];
|
||||
if (empty($vrfId)) {
|
||||
unset($peers['vrf_id']);
|
||||
}
|
||||
$seenPeerID[] = DeviceCache::getPrimary()->bgppeers()->create($peers)->bgpPeer_id;
|
||||
|
||||
if (Config::get('autodiscovery.bgp')) {
|
||||
$name = gethostbyaddr($address);
|
||||
discover_new_device($name, $device, 'BGP');
|
||||
}
|
||||
echo '+';
|
||||
$vrp_bgp_peer_count++;
|
||||
} else {
|
||||
$peers = [
|
||||
'bgpPeerRemoteAs' => $value['hwBgpPeerRemoteAs'],
|
||||
'astext' => $astext,
|
||||
'bgpPeerDescr' => $value['bgpPeerDescr'] ?? '',
|
||||
];
|
||||
$affected = DeviceCache::getPrimary()->bgppeers()->where('bgpPeerIdentifier', $address)->where('vrf_id', $vrfId)->update($peers);
|
||||
$seenPeerID[] = DeviceCache::getPrimary()->bgppeers()->where('bgpPeerIdentifier', $address)->where('vrf_id', $vrfId)->select('bgpPeer_id')->orderBy('bgpPeer_id', 'ASC')->first()->bgpPeer_id;
|
||||
|
||||
echo str_repeat('.', $affected);
|
||||
$vrp_bgp_peer_count += $affected;
|
||||
}
|
||||
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', [$device['device_id'], $value['hwBgpPeerRemoteAddr'], $value['afi'], $value['safi']]) < 1) {
|
||||
if ($vrfName != '') {
|
||||
$device['context_name'] = $vrfName;
|
||||
}
|
||||
add_cbgp_peer($device, ['ip' => $value['hwBgpPeerRemoteAddr']], $value['afi'], $value['safi']);
|
||||
unset($device['context_name']);
|
||||
} else {
|
||||
//nothing to update
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean up peers
|
||||
|
||||
if (! is_null($seenPeerID)) {
|
||||
$deleted = DeviceCache::getPrimary()->bgppeers()->whereNotIn('bgpPeer_id', $seenPeerID)->delete();
|
||||
echo str_repeat('-', $deleted);
|
||||
}
|
||||
|
||||
$af_query = 'SELECT bgpPeerIdentifier, afi, safi FROM bgpPeers_cbgp WHERE `device_id`=? AND bgpPeerIdentifier=?';
|
||||
foreach (dbFetchRows($af_query, [$device['device_id'], $peer['ip']]) as $entry) {
|
||||
$afi = $entry['afi'];
|
||||
$safi = $entry['safi'];
|
||||
$vrfName = $entry['context_name'];
|
||||
if (! isset($bgpPeersCache[$vrfName]) ||
|
||||
! isset($bgpPeersCache[$vrfName][$entry['bgpPeerIdentifier']]) ||
|
||||
$bgpPeersCache[$vrfName][$entry['bgpPeerIdentifier']][$entry['afi']] != $afi ||
|
||||
$bgpPeersCache[$vrfName][$entry['bgpPeerIdentifier']][$entry['safi']] != $safi) {
|
||||
dbDelete(
|
||||
'bgpPeers_cbgp',
|
||||
'`device_id`=? AND `bgpPeerIdentifier`=? AND context_name=? AND afi=? AND safi=?',
|
||||
[$device['device_id'], $address, $vrfName, $afi, $safi]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
unset($bgpPeersCache);
|
||||
unset($bgpPeers);
|
||||
if ($vrp_bgp_peer_count > 0) {
|
||||
return; //Finish BGP discovery here, cause we already collected data with Huawei MIBs
|
||||
}
|
||||
}
|
||||
// If not, we continue with standard BGP4 MIB
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1584,10 +1584,6 @@
|
||||
"order": 1,
|
||||
"type": "text"
|
||||
},
|
||||
"enable_bgp": {
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"enable_billing": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
|
Reference in New Issue
Block a user