More updates for junos bgp polling

This commit is contained in:
laf
2016-08-03 16:49:41 +01:00
parent 502b650a67
commit d56ff8b87f
4 changed files with 73 additions and 54 deletions

View File

@@ -111,6 +111,7 @@ else {
echo ' | Prefixes: Unicast ('; echo ' | Prefixes: Unicast (';
if ($vars['graph'] == 'prefixes_ipv4unicast') { if ($vars['graph'] == 'prefixes_ipv4unicast') {
echo "<span class='pagemenu-selected'>"; echo "<span class='pagemenu-selected'>";
$extra_sql = " AND `bgpLocalAddr` NOT LIKE '%:%'";
} }
echo generate_link('IPv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4unicast')); echo generate_link('IPv4', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv4unicast'));
@@ -122,6 +123,7 @@ else {
if ($vars['graph'] == 'prefixes_ipv6unicast') { if ($vars['graph'] == 'prefixes_ipv6unicast') {
echo "<span class='pagemenu-selected'>"; echo "<span class='pagemenu-selected'>";
$extra_sql = " AND `bgpLocalAddr` LIKE '%:%'";
} }
echo generate_link('IPv6', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6unicast')); echo generate_link('IPv6', $vars, array('view' => 'graphs', 'graph' => 'prefixes_ipv6unicast'));
@@ -213,7 +215,7 @@ else {
$where .= " AND (B.bgpPeerState != 'established')"; $where .= " AND (B.bgpPeerState != 'established')";
} }
$peer_query = 'select * from bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id '.$where.' ORDER BY D.hostname, B.bgpPeerRemoteAs, B.bgpPeerIdentifier'; $peer_query = "SELECT * FROM `bgpPeers` AS `B`, `devices` AS `D` WHERE `B`.`device_id` = `D`.`device_id` $where $extra_sql ORDER BY `D`.`hostname`, `B`.`bgpPeerRemoteAs`, `B`.`bgpPeerIdentifier`";
foreach (dbFetchRows($peer_query) as $peer) { foreach (dbFetchRows($peer_query) as $peer) {
unset($alert, $bg_image); unset($alert, $bg_image);

View File

@@ -156,8 +156,8 @@ if ($config['enable_bgp']) {
$safis[2] = 'multicast'; $safis[2] = 'multicast';
if (!isset($j_peerIndexes)) { if (!isset($j_peerIndexes)) {
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerEntry', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
print_r($j_bgp);
foreach ($j_bgp as $index => $entry) { foreach ($j_bgp as $index => $entry) {
switch ($entry['jnxBgpM2PeerRemoteAddrType']) { switch ($entry['jnxBgpM2PeerRemoteAddrType']) {
case 'ipv4': case 'ipv4':

View File

@@ -7,8 +7,7 @@ if ($config['enable_bgp']) {
if (!empty($peers)) { 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 = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerIndex', '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.14', $peer_data_tmp, '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 { } else {
$peer_data_check = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', array(), 'CISCO-BGP4-MIB', $config['mibdir']); $peer_data_check = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', array(), 'CISCO-BGP4-MIB', $config['mibdir']);
} }
@@ -92,54 +91,46 @@ if ($config['enable_bgp']) {
// FIXME - needs moved to function // 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'];
foreach (explode("\n", $peer_data_check) as $tmp) { foreach ($peer_data_check as $hash => $index) {
list($peer_ip_snmp, $peer_index) = explode(' ', $tmp); $peer_ip_snmp = ltrim($index['orig'], '.');
$octets = count(explode(".", $peer_ip_snmp)); $octets = count(explode(".", $peer_ip_snmp));
if ($octets > 11) { if ($octets > 11) {
// ipv6 // ipv6
$peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); $tmp_peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16)))));
} else { } else {
// ipv4 // ipv4
$peer_ip = implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 4))); $tmp_peer_ip = implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 4)));
} }
$junos[$peer_ip]['oid'] = $peer_ip_snmp; $junos[$tmp_peer_ip]['hash'] = $hash;
$junos[$peer_ip]['index'] = $peer_index; $junos[$tmp_peer_ip]['index'] = $index['jnxBgpM2PeerIndex'];
} }
} }
$peer_data_tmp = snmp_get_multi( if (!isset($peer_data_tmp)) {
$device, $peer_data_tmp = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerState', '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
array( $peer_data_tmp = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerStatus', '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
'jnxBgpM2PeerState.'.$junos[$peer_ip]['oid'], $peer_data_tmp = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerInUpdates', '.1.3.6.1.4.1.2636.5.1.1.2.6.1.1.1', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
'jnxBgpM2PeerStatus.'.$junos[$peer_ip]['oid'], $peer_data_tmp = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerOutUpdates', '.1.3.6.1.4.1.2636.5.1.1.2.6.1.1.2', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
'jnxBgpM2PeerInUpdates.'.$junos[$peer_ip]['oid'], $peer_data_tmp = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerInTotalMessages', '.1.3.6.1.4.1.2636.5.1.1.2.6.1.1.3', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
'jnxBgpM2PeerOutUpdates.'.$junos[$peer_ip]['oid'], $peer_data_tmp = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerOutTotalMessages', '.1.3.6.1.4.1.2636.5.1.1.2.6.1.1.4', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
'jnxBgpM2PeerInTotalMessages.'.$junos[$peer_ip]['oid'], $peer_data_tmp = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerFsmEstablishedTime', '.1.3.6.1.4.1.2636.5.1.1.2.4.1.1.1', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
'jnxBgpM2PeerOutTotalMessages.'.$junos[$peer_ip]['oid'], $peer_data_tmp = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerInUpdatesElapsedTime', '.1.3.6.1.4.1.2636.5.1.1.2.4.1.1.2', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
'jnxBgpM2PeerFsmEstablishedTime.'.$junos[$peer_ip]['oid'], $peer_data_tmp = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerLocalAddr', '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.7', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
'jnxBgpM2PeerInUpdatesElapsedTime.'.$junos[$peer_ip]['oid'], $peer_data_tmp = snmpwalk_cache_long_oid($device, 'jnxBgpM2PeerRemoteAddrType', '.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.10', $peer_data_tmp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
'jnxBgpM2PeerLocalAddr.'.$junos[$peer_ip]['oid'], d_echo($peer_data_tmp);
'jnxBgpM2PeerRemoteAddrType.'.$junos[$peer_ip]['oid'], }
), $bgpPeerState = $peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerState'];
'-OQnUs', $bgpPeerAdminStatus = $peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerStatus'];
'BGP4-V2-MIB-JUNIPER', $bgpPeerInUpdates = $peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerInUpdates'];
$config['mibdir'].'/junos' $bgpPeerOutUpdates = $peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerOutUpdates'];
); $bgpPeerInTotalMessages = $peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerInTotalMessages'];
$peer_data_tmp = array_shift($peer_data_tmp); $bgpPeerOutTotalMessages = $peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerOutTotalMessages'];
d_echo($peer_data_tmp); $bgpPeerFsmEstablishedTime = $peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerFsmEstablishedTime'];
$bgpPeerInUpdateElapsedTime = $peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerInUpdatesElapsedTime'];
$bgpPeerState = $peer_data_tmp['jnxBgpM2PeerState']; if ($peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerRemoteAddrType'] == 'ipv4') {
$bgpPeerAdminStatus = $peer_data_tmp['jnxBgpM2PeerStatus']; $bgpLocalAddr = long2ip(hexdec($peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerLocalAddr']));
$bgpPeerInUpdates = $peer_data_tmp['jnxBgpM2PeerInUpdates']; } elseif ($peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerRemoteAddrType'] == 'ipv6') {
$bgpPeerOutUpdates = $peer_data_tmp['jnxBgpM2PeerOutUpdates']; $ip6 = trim(str_replace(' ', '', $peer_data_tmp[$junos[$peer_ip]['hash']]['jnxBgpM2PeerLocalAddr']), '"');
$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); $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); $bgpLocalAddr = Net_IPv6::compress($ip6);
} }
@@ -288,19 +279,22 @@ if ($config['enable_bgp']) {
}//end if }//end if
if ($device['os'] == 'junos') { if ($device['os'] == 'junos') {
// Missing: cbgpPeerAdminLimit cbgpPeerPrefixThreshold cbgpPeerPrefixClearThreshold cbgpPeerSuppressedPrefixes cbgpPeerWithdrawnPrefixes
$safis['unicast'] = 1; $safis['unicast'] = 1;
$safis['multicast'] = 2; $safis['multicast'] = 2;
$afis['ipv4'] = 1;
$afis['ipv6'] = 2;
if (!isset($j_prefixes)) { if (!isset($j_prefixes)) {
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixInPrefixesAccepted', $j_prefixes, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos', '-OQnU');
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixInPrefixesRejected', $j_prefixes, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos', '-OQnU');
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixOutPrefixes', $j_prefixes, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos', '-OQnU');
d_echo($j_prefixes);
} }
$cbgpPeerAcceptedPrefixes = $j_prefixes[$junos[$peer_ip]['index'].".$afi.".$safis[$safi]]['jnxBgpM2PrefixInPrefixesAccepted']; $cbgpPeerAcceptedPrefixes = array_shift($j_prefixes['1.3.6.1.4.1.2636.5.1.1.2.6.2.1.8.'.$junos[$peer_ip]['index'].".$afis[$afi].".$safis[$safi]]);
$cbgpPeerDeniedPrefixes = $j_prefixes[$junos[$peer_ip]['index'].".$afi.".$safis[$safi]]['jnxBgpM2PrefixInPrefixesRejected']; $cbgpPeerDeniedPrefixes = array_shift($j_prefixes['1.3.6.1.4.1.2636.5.1.1.2.6.2.1.9.'.$junos[$peer_ip]['index'].".$afis[$afi].".$safis[$safi]]);
$cbgpPeerAdvertisedPrefixes = $j_prefixes[$junos[$peer_ip]['index'].".$afi.".$safis[$safi]]['jnxBgpM2PrefixOutPrefixes']; $cbgpPeerAdvertisedPrefixes = array_shift($j_prefixes['1.3.6.1.4.1.2636.5.1.1.2.6.2.1.10.'.$junos[$peer_ip]['index'].".$afis[$afi].".$safis[$safi]]);
unset($j_prefixes);
}//end if }//end if
// FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE! // FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE!
@@ -357,3 +351,6 @@ if ($config['enable_bgp']) {
} //end foreach } //end foreach
} //end if } //end if
} //end if } //end if
unset($$peer_data_tmp);
unset($j_prefixes);

View File

@@ -367,6 +367,26 @@ function snmpwalk_cache_oid($device, $oid, $array, $mib=null, $mibdir=null, $snm
}//end snmpwalk_cache_oid() }//end snmpwalk_cache_oid()
function snmpwalk_cache_long_oid($device, $oid, $noid, $array, $mib=null, $mibdir=null, $snmpflags='-OQnU') {
$data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir);
foreach (explode("\n", $data) as $entry) {
list($tmp_oid,$value) = explode('=', $entry, 2);
$tmp_oid = trim($tmp_oid);
$value = trim($value);
$tmp_index = str_replace($noid, '', $tmp_oid);
$index = md5($tmp_index);
if (!empty($index) && !empty($oid)) {
$array[$index][$oid] = $value;
if (empty($array[$index]['orig'])) {
$array[$index]['orig'] = $tmp_index;
}
}
}
return $array;
}//end snmpwalk_cache_oid()
// just like snmpwalk_cache_oid except that it returns the numerical oid as the index // just like snmpwalk_cache_oid except that it returns the numerical oid as the index
// this is useful when the oid is indexed by the mac address and snmpwalk would // this is useful when the oid is indexed by the mac address and snmpwalk would
@@ -378,11 +398,11 @@ function snmpwalk_cache_oid_num($device, $oid, $array, $mib=null, $mibdir=null)
}//end snmpwalk_cache_oid_num() }//end snmpwalk_cache_oid_num()
function snmpwalk_cache_multi_oid($device, $oid, $array, $mib=null, $mibdir=null) { function snmpwalk_cache_multi_oid($device, $oid, $array, $mib=null, $mibdir=null, $snmpflags='-OQUs') {
global $cache; global $cache;
if (!(is_array($cache['snmp'][$device['device_id']]) && array_key_exists($oid, $cache['snmp'][$device['device_id']]))) { if (!(is_array($cache['snmp'][$device['device_id']]) && array_key_exists($oid, $cache['snmp'][$device['device_id']]))) {
$data = snmp_walk($device, $oid, '-OQUs', $mib, $mibdir); $data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir);
foreach (explode("\n", $data) as $entry) { foreach (explode("\n", $data) as $entry) {
list($r_oid,$value) = explode('=', $entry, 2); list($r_oid,$value) = explode('=', $entry, 2);
$r_oid = trim($r_oid); $r_oid = trim($r_oid);