This commit is contained in:
laf
2015-06-03 15:41:10 +01:00
parent 1ca02fb3c5
commit 702b75c0b7
3 changed files with 34 additions and 10 deletions

View File

@ -33,7 +33,9 @@ if ($config['enable_bgp'])
foreach (explode("\n", $peers) as $peer)
{
list($ver, $peer) = explode(".", $peer,2);
if ($peer2 === TRUE) {
list($ver, $peer) = explode(".", $peer,2);
}
list($peer_ip, $peer_as) = explode(" ", $peer);
if ($peer && $peer_ip != "0.0.0.0")

View File

@ -1202,8 +1202,7 @@ function first_oid_match($device, $list) {
}
}
function ip_to_hex($ip) {
function ip_to_dec($ip) {
$return = '';
if (strstr($ip, ":")) {
$ipv6 = explode(':', $ip);
@ -1216,3 +1215,19 @@ function ip_to_hex($ip) {
}
return $return;
}
function hex_to_ip($hex) {
$return = "";
if (filter_var($hex, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE && filter_var($hex, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE) {
$hex_exp = explode(' ', $hex);
foreach ($hex_exp as $item) {
if (!empty($item) && $item != "\"") {
$return .= hexdec($item).'.';
}
}
$return = substr($return, 0, -1);
} else {
$return = $ip;
}
return $return;
}

View File

@ -23,7 +23,7 @@ if ($config['enable_bgp'])
}
if ($peer2 === TRUE) {
$bgp_peer_ip = ip_to_hex($peer['bgpPeerIdentifier']);
$bgp_peer_ident = ip_to_dec($peer['bgpPeerIdentifier']);
if (strstr($peer['bgpPeerIdentifier'],":")) {
$ip_type = 2;
$ip_len = 16;
@ -33,7 +33,7 @@ if ($config['enable_bgp'])
$ip_len = 4;
$ip_ver = 'ipv4';
}
$peer_identifier = $ip_type . '.' . $ip_len . '.' . $bgp_peer_ip;
$peer_identifier = $ip_type . '.' . $ip_len . '.' . $bgp_peer_ident;
$peer_data_tmp = snmp_get_multi($device,
" cbgpPeer2State.". $peer_identifier .
" cbgpPeer2AdminStatus.". $peer_identifier .
@ -47,6 +47,15 @@ if ($config['enable_bgp'])
$ident = "$ip_ver.\"".$peer['bgpPeerIdentifier'].'"';
unset($peer_data);
foreach ($peer_data_tmp[$ident] as $k => $v) {
if (strstr($k, "cbgpPeer2LocalAddr")) {
if ($ip_ver == 'ipv6') {
$v = preg_replace("/ /", ":", $v);
$v = strtolower($v);
rtrim($v,":");
} else {
$v = hex_to_ip($v);
}
}
$peer_data .= "$v\n";
}
} else {
@ -170,8 +179,7 @@ if ($config['enable_bgp'])
if ($debug) { echo("$afi $safi\n"); }
if ($device['os_group'] == "cisco") {
$bgp_peer_ip = ip_to_hex($peer['bgpPeerIdentifier']);
$bgp_peer_ident = ip_to_dec($peer['bgpPeerIdentifier']);
if (strstr($peer['bgpPeerIdentifier'], ":")) {
$ip_type = 2;
$ip_len = 16;
@ -189,11 +197,10 @@ if ($config['enable_bgp'])
} elseif ($peer_afi['safi'] == "vpn") {
$ip_cast = 128;
}
$check = snmp_get($device,"cbgpPeer2AcceptedPrefixes.".$ip_type.'.'.$ip_len.'.'.$bgp_peer_ip.'.'.$ip_type.'.'.$ip_cast,"","CISCO-BGP4-MIB", $config['mibdir']);
$check = snmp_get($device,"cbgpPeer2AcceptedPrefixes.".$ip_type.'.'.$ip_len.'.'.$bgp_peer_ident.'.'.$ip_type.'.'.$ip_cast,"","CISCO-BGP4-MIB", $config['mibdir']);
if(!empty($check)) {
$cgp_peer_identifier = $ip_type . '.' . $ip_len . '.' . $bgp_peer_ip . '.' . $ip_type . '.' . $ip_cast;
$cgp_peer_identifier = $ip_type . '.' . $ip_len . '.' . $bgp_peer_ident . '.' . $ip_type . '.' . $ip_cast;
$cbgp_data_tmp = snmp_get_multi($device,
" cbgpPeer2AcceptedPrefixes.". $cgp_peer_identifier .
" cbgpPeer2DeniedPrefixes.". $cgp_peer_identifier .