mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
New corner cases for Huawei VRP BGP (#11663)
* vrp-improve * add bgp4 data, and get errors * Fix WRONG Type error on bgpPeerRemoteAs + handle ErrorSubCode in a generic way * fixing tests * clean * improve state backup to BGP4-MIB * tests with corrected data * tests * restore original tests/data/vrp_5720.json
This commit is contained in:
@@ -18,7 +18,7 @@ if (Config::get('enable_bgp')) {
|
||||
$vrfs_lite_cisco = array(array('context_name'=>''));
|
||||
}
|
||||
|
||||
$bgpLocalAs = snmp_getnext($device, 'bgpLocalAs', '-Oqvn', 'BGP4-MIB');
|
||||
$bgpLocalAs = snmp_getnext($device, 'bgpLocalAs', '-OQUsv', 'BGP4-MIB');
|
||||
|
||||
foreach ($vrfs_lite_cisco as $vrf) {
|
||||
$device['context_name'] = $vrf['context_name'];
|
||||
@@ -43,7 +43,7 @@ if (Config::get('enable_bgp')) {
|
||||
|
||||
if (empty($peers_data)) {
|
||||
$bgp4_mib = true;
|
||||
$peers_data = snmp_walk($device, 'bgpPeerRemoteAs', '-Oq', 'BGP4-MIB');
|
||||
$peers_data = preg_replace('/= /', '', snmp_walk($device, 'bgpPeerRemoteAs', '-OQ', 'BGP4-MIB'));
|
||||
}
|
||||
} else {
|
||||
echo 'No BGP on host';
|
||||
|
@@ -166,6 +166,6 @@ if (Config::get('enable_bgp')) {
|
||||
if ($vrp_bgp_peer_count > 0) {
|
||||
return; //Finish BGP discovery here, cause we collected data
|
||||
}
|
||||
// If not, we continue with standard BGP4 MIB
|
||||
}
|
||||
// If not, we continue with standard BGP4 MIB
|
||||
}
|
||||
|
@@ -93,8 +93,10 @@ if (\LibreNMS\Config::get('enable_bgp')) {
|
||||
} elseif ($device['os'] == 'vrp') {
|
||||
echo "\nCaching Oids VRP...";
|
||||
if (!isset($bgpPeers)) {
|
||||
//if not available, we timeout each time, to be fixed when split
|
||||
$bgpPeersCache = snmpwalk_cache_oid($device, 'hwBgpPeerEntry', [], 'HUAWEI-BGP-VPN-MIB', 'huawei');
|
||||
$bgpPeersStats = snmpwalk_cache_oid($device, 'hwBgpPeerStatisticTable', [], 'HUAWEI-BGP-VPN-MIB', 'huawei', '-OQUbs');
|
||||
$bgp4updates = snmpwalk_cache_oid($device, 'bgpPeerEntry', [], 'BGP4-MIB', 'huawei', '-OQUbs');
|
||||
foreach ($bgpPeersCache as $key => $value) {
|
||||
$oid = explode(".", $key, 5);
|
||||
$vrfInstance = $oid[0];
|
||||
@@ -137,9 +139,31 @@ if (\LibreNMS\Config::get('enable_bgp')) {
|
||||
$peer_data['bgpPeerInTotalMessages'] = $bgpPeers[$address][$vrfInstance]['hwBgpPeerInTotalMsgs'];
|
||||
$peer_data['bgpPeerOutTotalMessages'] = $bgpPeers[$address][$vrfInstance]['hwBgpPeerOutTotalMsgs'];
|
||||
$peer_data['bgpPeerFsmEstablishedTime'] = $bgpPeers[$address][$vrfInstance]['hwBgpPeerFsmEstablishedTime'];
|
||||
$peer_data['bgpPeerLastError'] = $bgpPeers[$address][$vrfInstance]['hwBgpPeerLastError'];
|
||||
}
|
||||
d_echo("VPN : $vrfInstance for $address :");
|
||||
d_echo("VPN : $vrfInstance for $address :\n");
|
||||
d_echo($peer_data);
|
||||
if (empty($peer_data['bgpPeerInUpdates']) || empty($peer_data['bgpPeerOutUpdates'])) {
|
||||
$peer_data['bgpPeerInUpdates'] = $bgp4updates[$address]['bgpPeerInUpdates'];
|
||||
$peer_data['bgpPeerOutUpdates'] = $bgp4updates[$address]['bgpPeerOutUpdates'];
|
||||
}
|
||||
if (empty($peer_data['bgpPeerInTotalMessages']) || empty($peer_data['bgpPeerOutTotalMessages'])) {
|
||||
$peer_data['bgpPeerInTotalMessages'] = $bgp4updates[$address]['bgpPeerInTotalMessages'];
|
||||
$peer_data['bgpPeerOutTotalMessages'] = $bgp4updates[$address]['bgpPeerOutTotalMessages'];
|
||||
}
|
||||
if (empty($peer_data['bgpPeerState'])) {
|
||||
$peer_data['bgpPeerState'] = $bgp4updates[$address]['bgpPeerState'];
|
||||
}
|
||||
if (empty($peer_data['bgpPeerAdminStatus'])) {
|
||||
$peer_data['bgpPeerAdminStatus'] = $bgp4updates[$address]['bgpPeerAdminStatus'];
|
||||
}
|
||||
if (empty($peer_data['bgpPeerLastError'])) {
|
||||
$peer_data['bgpPeerLastError'] = $bgp4updates[$address]['bgpPeerLastError'];
|
||||
}
|
||||
$error_data = explode(" ", $peer_data['bgpPeerLastError']);
|
||||
$peer_data['bgpPeerLastErrorCode'] = intval($error_data[0]);
|
||||
$peer_data['bgpPeerLastErrorSubCode'] = intval($error_data[1]);
|
||||
unset($peer_data['bgpPeerLastError']);
|
||||
} elseif ($device['os'] == 'timos') {
|
||||
if (!isset($bgpPeers)) {
|
||||
echo "\nCaching Oids...";
|
||||
@@ -248,16 +272,6 @@ if (\LibreNMS\Config::get('enable_bgp')) {
|
||||
|
||||
$peer_data = array();
|
||||
|
||||
if (strpos($peer_data_raw['cbgpPeer2LastError'], " ")) {
|
||||
// Some device return both Code and SubCode in the same snmp field, we need to split it
|
||||
$splitted_codes = explode(" ", $peer_data_raw['cbgpPeer2LastError']);
|
||||
$error_code = intval($splitted_codes[0]);
|
||||
$error_subcode = intval($splitted_codes[1]);
|
||||
$peer_data['bgpPeerLastErrorCode'] = $error_code;
|
||||
$peer_data['bgpPeerLastErrorSubCode'] = $error_subcode;
|
||||
unset($oid_map['cbgpPeer2LastError']);
|
||||
}
|
||||
|
||||
foreach ($oid_map as $source => $target) {
|
||||
$v = isset($peer_data_raw[$source]) ? $peer_data_raw[$source] : '';
|
||||
|
||||
@@ -270,6 +284,15 @@ if (\LibreNMS\Config::get('enable_bgp')) {
|
||||
}
|
||||
$peer_data[$target] = $v;
|
||||
}
|
||||
|
||||
if (strpos($peer_data['bgpPeerLastErrorCode'], " ")) {
|
||||
// Some device return both Code and SubCode in the same snmp field, we need to split it
|
||||
$splitted_codes = explode(" ", $peer_data['bgpPeerLastErrorCode']);
|
||||
$error_code = intval($splitted_codes[0]);
|
||||
$error_subcode = intval($splitted_codes[1]);
|
||||
$peer_data['bgpPeerLastErrorCode'] = $error_code;
|
||||
$peer_data['bgpPeerLastErrorSubCode'] = $error_subcode;
|
||||
}
|
||||
}
|
||||
|
||||
d_echo($peer_data);
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user