From 702b75c0b7b8f5c2738b788684d426ad3ff6a4cd Mon Sep 17 00:00:00 2001 From: laf Date: Wed, 3 Jun 2015 15:41:10 +0100 Subject: [PATCH] Updates --- includes/discovery/bgp-peers.inc.php | 4 +++- includes/functions.php | 19 +++++++++++++++++-- includes/polling/bgp-peers.inc.php | 21 ++++++++++++++------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index b3778e195f..af9b931f51 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -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") diff --git a/includes/functions.php b/includes/functions.php index 22b6dc91d8..ef4d92aa6f 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -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; +} diff --git a/includes/polling/bgp-peers.inc.php b/includes/polling/bgp-peers.inc.php index 3dc7524909..47a2776ac5 100644 --- a/includes/polling/bgp-peers.inc.php +++ b/includes/polling/bgp-peers.inc.php @@ -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 .