mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Improved junos BGP code + WebUI
This commit is contained in:
@@ -41,6 +41,7 @@ echo ' | Prefixes: ';
|
||||
|
||||
if ($vars['view'] == 'prefixes_ipv4unicast') {
|
||||
echo "<span class='pagemenu-selected'>";
|
||||
$sql = " AND `bgpLocalAddr` NOT LIKE '%:%'";
|
||||
}
|
||||
|
||||
echo generate_link('IPv4', $link_array, array('view' => 'prefixes_ipv4unicast'));
|
||||
@@ -63,6 +64,7 @@ echo ' | ';
|
||||
|
||||
if ($vars['view'] == 'prefixes_ipv6unicast') {
|
||||
echo "<span class='pagemenu-selected'>";
|
||||
$sql = " AND `bgpLocalAddr` LIKE '%:%'";
|
||||
}
|
||||
|
||||
echo generate_link('IPv6', $link_array, array('view' => 'prefixes_ipv6unicast'));
|
||||
@@ -98,7 +100,7 @@ echo '<tr style="height: 30px"><td width=1></td><th></th><th>Peer address</th><t
|
||||
|
||||
$i = '1';
|
||||
|
||||
foreach (dbFetchRows('SELECT * FROM `bgpPeers` WHERE `device_id` = ? ORDER BY `bgpPEerRemoteAs`, `bgpPeerIdentifier`', array($device['device_id'])) as $peer) {
|
||||
foreach (dbFetchRows("SELECT * FROM `bgpPeers` WHERE `device_id` = ? $sql ORDER BY `bgpPeerRemoteAs`, `bgpPeerIdentifier`", array($device['device_id'])) as $peer) {
|
||||
$has_macaccounting = dbFetchCell('SELECT COUNT(*) FROM `ipv4_mac` AS I, mac_accounting AS M WHERE I.ipv4_address = ? AND M.mac = I.mac_address', array($peer['bgpPeerIdentifier']));
|
||||
unset($bg_image);
|
||||
if (!is_integer($i / 2)) {
|
||||
|
@@ -21,6 +21,7 @@ if ($config['enable_bgp']) {
|
||||
}
|
||||
|
||||
$peer2 = false;
|
||||
if ($device['os'] !== 'junos') {
|
||||
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']);
|
||||
if (empty($peers_data)) {
|
||||
$peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']);
|
||||
@@ -56,18 +57,23 @@ if ($config['enable_bgp']) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($device['os'] == 'junos') {
|
||||
} elseif ($device['os'] == 'junos') {
|
||||
// Juniper BGP4-V2 MIB
|
||||
// FIXME: needs a big cleanup! also see below.
|
||||
// FIXME: is .0.ipv6 the only possible value here?
|
||||
$result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
|
||||
$peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result));
|
||||
$result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
|
||||
$peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.', '', $result));
|
||||
foreach (explode("\n", $peers) as $peer) {
|
||||
list($peer_ip_snmp, $peer_as) = explode(' ', $peer);
|
||||
|
||||
// Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs.
|
||||
$octets = count(explode(".", $peer_ip_snmp));
|
||||
if ($octets > 11) {
|
||||
// ipv6
|
||||
$peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16)))));
|
||||
} else {
|
||||
// ipv4
|
||||
$peer_ip = implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 4)));
|
||||
}
|
||||
|
||||
if ($peer) {
|
||||
d_echo("Found peer $peer_ip (AS$peer_as)\n");
|
||||
|
@@ -6,26 +6,29 @@ if ($config['enable_bgp']) {
|
||||
|
||||
if (!empty($peers)) {
|
||||
|
||||
if ($device['os'] != 'junos') {
|
||||
if ($device['os'] == 'junos') {
|
||||
$peer_data_check = snmp_walk($device, 'jnxBgpM2PeerIndex', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
|
||||
$peer_data_check = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.14.', '', $peer_data_check));
|
||||
} else {
|
||||
$peer_data_check = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', array(), 'CISCO-BGP4-MIB', $config['mibdir']);
|
||||
}
|
||||
|
||||
foreach ($peers as $peer) {
|
||||
//add context if exist
|
||||
$device['context_name']= $peer['context_name'];
|
||||
if (strstr(":", $peer['bgpPeerIdentifier'])) {
|
||||
$peer_ip = ipv62snmp($peer['bgpPeerIdentifier']);
|
||||
} else {
|
||||
$peer_ip = $peer['bgpPeerIdentifier'];
|
||||
}
|
||||
|
||||
// Poll BGP Peer
|
||||
$peer2 = false;
|
||||
echo 'Checking BGP peer '.$peer['bgpPeerIdentifier'].' ';
|
||||
|
||||
if (!empty($peer['bgpPeerIdentifier'])) {
|
||||
if (!strstr($peer['bgpPeerIdentifier'], ':') || $device['os'] != 'junos') {
|
||||
if ($device['os'] != 'junos') {
|
||||
// v4 BGP4 MIB
|
||||
if (count($peer_data_check) > 0) {
|
||||
$peer2 = true;
|
||||
}
|
||||
|
||||
if ($peer2 === true) {
|
||||
if (strstr($peer['bgpPeerIdentifier'], ':')) {
|
||||
$bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']);
|
||||
}
|
||||
@@ -83,57 +86,68 @@ if ($config['enable_bgp']) {
|
||||
$bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr));
|
||||
}
|
||||
elseif ($device['os'] == 'junos') {
|
||||
// v6 for JunOS via Juniper MIB
|
||||
$peer_ip = ipv62snmp($peer['bgpPeerIdentifier']);
|
||||
|
||||
if (!isset($junos_v6)) {
|
||||
if (!isset($junos)) {
|
||||
echo "\nCaching Oids...";
|
||||
// FIXME - needs moved to function
|
||||
//$peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'];
|
||||
|
||||
$peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'];
|
||||
$peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6';
|
||||
foreach (explode("\n", trim(`$peer_cmd`)) as $oid) {
|
||||
list($peer_oid) = explode(' ', $oid);
|
||||
$peer_id = explode('.', $peer_oid);
|
||||
$junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18));
|
||||
foreach (explode("\n", $peer_data_check) as $tmp) {
|
||||
list($peer_ip_snmp, $peer_index) = explode(' ', $tmp);
|
||||
$octets = count(explode(".", $peer_ip_snmp));
|
||||
if ($octets > 11) {
|
||||
// ipv6
|
||||
$peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16)))));
|
||||
} else {
|
||||
// ipv4
|
||||
$peer_ip = implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 4)));
|
||||
}
|
||||
$junos[$peer_ip]['oid'] = $peer_ip_snmp;
|
||||
$junos[$peer_ip]['index'] = $peer_index;
|
||||
}
|
||||
}
|
||||
|
||||
$peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device);
|
||||
$peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"';
|
||||
$peer_cmd .= ' '.$device['hostname'].':'.$device['port'];
|
||||
$peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
// Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented?
|
||||
$peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= '|grep -v "No Such Instance"';
|
||||
d_echo("\n$peer_cmd\n");
|
||||
$peer_data = trim(`$peer_cmd`);
|
||||
list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data);
|
||||
$peer_data_tmp = array_shift(snmp_get_multi(
|
||||
$device,
|
||||
array(
|
||||
'jnxBgpM2PeerState.'.$junos[$peer_ip]['oid'],
|
||||
'jnxBgpM2PeerStatus.'.$junos[$peer_ip]['oid'],
|
||||
'jnxBgpM2PeerInUpdates.'.$junos[$peer_ip]['oid'],
|
||||
'jnxBgpM2PeerOutUpdates.'.$junos[$peer_ip]['oid'],
|
||||
'jnxBgpM2PeerInTotalMessages.'.$junos[$peer_ip]['oid'],
|
||||
'jnxBgpM2PeerOutTotalMessages.'.$junos[$peer_ip]['oid'],
|
||||
'jnxBgpM2PeerFsmEstablishedTime.'.$junos[$peer_ip]['oid'],
|
||||
'jnxBgpM2PeerInUpdatesElapsedTime.'.$junos[$peer_ip]['oid'],
|
||||
'jnxBgpM2PeerLocalAddr.'.$junos[$peer_ip]['oid'],
|
||||
'jnxBgpM2PeerRemoteAddrType.'.$junos[$peer_ip]['oid'],
|
||||
),
|
||||
'-OQnUs',
|
||||
'BGP4-V2-MIB-JUNIPER',
|
||||
$config['mibdir'].'/junos'
|
||||
));
|
||||
d_echo($peer_data_tmp);
|
||||
|
||||
$bgpPeerState = $peer_data_tmp['jnxBgpM2PeerState'];
|
||||
$bgpPeerAdminStatus = $peer_data_tmp['jnxBgpM2PeerStatus'];
|
||||
$bgpPeerInUpdates = $peer_data_tmp['jnxBgpM2PeerInUpdates'];
|
||||
$bgpPeerOutUpdates = $peer_data_tmp['jnxBgpM2PeerOutUpdates'];
|
||||
$bgpPeerInTotalMessages = $peer_data_tmp['jnxBgpM2PeerInTotalMessages'];
|
||||
$bgpPeerOutTotalMessages = $peer_data_tmp['jnxBgpM2PeerOutTotalMessages'];
|
||||
$bgpPeerFsmEstablishedTime = $peer_data_tmp['jnxBgpM2PeerFsmEstablishedTime'];
|
||||
$bgpPeerInUpdateElapsedTime = $peer_data_tmp['jnxBgpM2PeerInUpdatesElapsedTime'];
|
||||
if ($peer_data_tmp['jnxBgpM2PeerRemoteAddrType'] == 'ipv4') {
|
||||
$bgpLocalAddr = long2ip(hexdec($peer_data_tmp['jnxBgpM2PeerLocalAddr']));
|
||||
} elseif ($peer_data_tmp['jnxBgpM2PeerRemoteAddrType'] == 'ipv6') {
|
||||
$ip6 = trim(str_replace(' ', '', $peer_data_tmp['jnxBgpM2PeerLocalAddr']), '"');
|
||||
$ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4);
|
||||
$bgpLocalAddr = Net_IPv6::compress($ip6);
|
||||
}
|
||||
d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n");
|
||||
|
||||
$bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr));
|
||||
if ($bgpLocalAddr == '00000000000000000000000000000000') {
|
||||
$bgpLocalAddr = '';
|
||||
// Unknown?
|
||||
}
|
||||
else {
|
||||
$bgpLocalAddr = strtolower($bgpLocalAddr);
|
||||
for ($i = 0; $i < 32; $i += 4) {
|
||||
$bgpLocalAddr6[] = substr($bgpLocalAddr, $i, 4);
|
||||
}
|
||||
|
||||
$bgpLocalAddr = Net_IPv6::compress(implode(':', $bgpLocalAddr6));
|
||||
unset($bgpLocalAddr6);
|
||||
}
|
||||
}//end if
|
||||
}//end if
|
||||
|
||||
@@ -186,7 +200,6 @@ if ($config['enable_bgp']) {
|
||||
if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') {
|
||||
// Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB)
|
||||
$peer_afis = dbFetchRows('SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier']));
|
||||
print_r($peer_afis);
|
||||
foreach ($peer_afis as $peer_afi) {
|
||||
$afi = $peer_afi['afi'];
|
||||
$safi = $peer_afi['safi'];
|
||||
@@ -278,38 +291,15 @@ print_r($peer_afis);
|
||||
$safis['unicast'] = 1;
|
||||
$safis['multicast'] = 2;
|
||||
|
||||
if (!isset($peerIndexes)) {
|
||||
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
|
||||
foreach ($j_bgp as $index => $entry) {
|
||||
switch ($entry['jnxBgpM2PeerRemoteAddrType']) {
|
||||
case 'ipv4':
|
||||
$ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr']));
|
||||
$j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex'];
|
||||
break;
|
||||
|
||||
case 'ipv6':
|
||||
$ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"');
|
||||
$ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4);
|
||||
$ip6 = Net_IPv6::compress($ip6);
|
||||
$j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex'];
|
||||
break;
|
||||
|
||||
default:
|
||||
echo "PANIC: Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
|
||||
if (!isset($j_prefixes)) {
|
||||
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
|
||||
}
|
||||
|
||||
$cbgpPeerAcceptedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi.".$safis[$safi]]['jnxBgpM2PrefixInPrefixesAccepted'];
|
||||
$cbgpPeerDeniedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi.".$safis[$safi]]['jnxBgpM2PrefixInPrefixesRejected'];
|
||||
$cbgpPeerAdvertisedPrefixes = $j_prefixes[$j_peerIndexes[$peer['bgpPeerIdentifier']].".$afi.".$safis[$safi]]['jnxBgpM2PrefixOutPrefixes'];
|
||||
$cbgpPeerAcceptedPrefixes = $j_prefixes[$junos[$peer_ip]['index'].".$afi.".$safis[$safi]]['jnxBgpM2PrefixInPrefixesAccepted'];
|
||||
$cbgpPeerDeniedPrefixes = $j_prefixes[$junos[$peer_ip]['index'].".$afi.".$safis[$safi]]['jnxBgpM2PrefixInPrefixesRejected'];
|
||||
$cbgpPeerAdvertisedPrefixes = $j_prefixes[$junos[$peer_ip]['index'].".$afi.".$safis[$safi]]['jnxBgpM2PrefixOutPrefixes'];
|
||||
|
||||
unset($j_prefixes);
|
||||
unset($j_bgp);
|
||||
unset($j_peerIndexes);
|
||||
}//end if
|
||||
|
||||
// FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE!
|
||||
@@ -323,7 +313,6 @@ print_r($peer_afis);
|
||||
$peer['c_update']['SuppressedPrefixes'] = $cbgpPeerSuppressedPrefixes;
|
||||
$peer['c_update']['WithdrawnPrefixes'] = $cbgpPeerWithdrawnPrefixes;
|
||||
|
||||
|
||||
$oids = array(
|
||||
'AcceptedPrefixes',
|
||||
'DeniedPrefixes',
|
||||
|
@@ -74,6 +74,9 @@ function snmp_get_multi($device, $oids, $options='-OQUs', $mib=null, $mibdir=nul
|
||||
$cmd .= isset($retries) ? ' -r '.$retries : '';
|
||||
|
||||
$cmd .= ' '.$device['transport'].':'.$device['hostname'].':'.$device['port'];
|
||||
if (is_array($oids)) {
|
||||
$oids = implode(' ', $oids);
|
||||
}
|
||||
$cmd .= ' '.$oids;
|
||||
|
||||
if (!$debug) {
|
||||
|
Reference in New Issue
Block a user