mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Update bgp-peers.inc.php
This commit is contained in:
@@ -4,13 +4,23 @@ if ($config['enable_bgp']) {
|
||||
// Discover BGP peers
|
||||
echo 'BGP Sessions : ';
|
||||
|
||||
if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){
|
||||
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
|
||||
}
|
||||
else{
|
||||
$vrfs_lite_cisco = array(array('context_name'=>null));
|
||||
}
|
||||
|
||||
$bgpLocalAs = trim(snmp_walk($device, '.1.3.6.1.2.1.15.2', '-Oqvn', 'BGP4-MIB', $config['mibdir']));
|
||||
|
||||
foreach ($vrfs_lite_cisco as $vrf) {
|
||||
$device['context_name'] = $vrf['context_name'];
|
||||
|
||||
if (is_numeric($bgpLocalAs)) {
|
||||
echo "AS$bgpLocalAs ";
|
||||
|
||||
if ($bgpLocalAs != $device['bgpLocalAs']) {
|
||||
dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id']));
|
||||
dbUpdate(array('bgpLocalAs' => $bgpLocalAs,'context_name' => $device['context_name']), 'devices', 'device_id=?', array($device['device_id']));
|
||||
echo 'Updated AS ';
|
||||
}
|
||||
|
||||
@@ -88,7 +98,7 @@ if ($config['enable_bgp']) {
|
||||
$astext = get_astext($peer['as']);
|
||||
|
||||
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') {
|
||||
$add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as']), 'bgpPeers');
|
||||
$add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'], 'context_name' => $device['context_name']), 'bgpPeers');
|
||||
if ($config['autodiscovery']['bgp'] === true) {
|
||||
$name = gethostbyaddr($peer['ip']);
|
||||
$remote_device_id = discover_new_device($name, $device, 'BGP');
|
||||
@@ -133,7 +143,7 @@ if ($config['enable_bgp']) {
|
||||
if ($afi && $safi && $bgp_ip == $peer['ip']) {
|
||||
$af_list[$bgp_ip][$afi][$safi] = 1;
|
||||
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp');
|
||||
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,4 +241,8 @@ if ($config['enable_bgp']) {
|
||||
unset($peerlist);
|
||||
|
||||
echo "\n";
|
||||
unset($device['context_name']);
|
||||
}
|
||||
unset($device['context_name']);
|
||||
unset($vrfs_c);
|
||||
}
|
||||
|
Reference in New Issue
Block a user