mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	Updated BGP polling for Cisco to support CISCO-BGP4-MIB better
This commit is contained in:
		@@ -1,7 +1,3 @@
 | 
			
		||||
<div style='padding: 10px; height: 20px; clear: both; display: block;'>
 | 
			
		||||
  <div style='float: left; font-size: 22px; font-weight: bold;'>Local AS : <?php echo($device['bgpLocalAs']); ?></div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
$link_array = array('page'    => 'device',
 | 
			
		||||
@@ -13,6 +9,8 @@ if(!isset($vars['view'])) { $vars['view'] = "basic"; }
 | 
			
		||||
 | 
			
		||||
print_optionbar_start();
 | 
			
		||||
 | 
			
		||||
echo "<strong>Local AS : " .$device['bgpLocalAs']."</strong> ";
 | 
			
		||||
 | 
			
		||||
echo("<span style='font-weight: bold;'>BGP</span> » ");
 | 
			
		||||
 | 
			
		||||
if ($vars['view'] == "basic") { echo("<span class='pagemenu-selected'>"); }
 | 
			
		||||
 
 | 
			
		||||
@@ -20,18 +20,26 @@ if ($config['enable_bgp'])
 | 
			
		||||
      echo("Updated AS ");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $peer2 = FALSE;
 | 
			
		||||
    $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']);
 | 
			
		||||
    } else {
 | 
			
		||||
        $peer2 = TRUE;
 | 
			
		||||
    }
 | 
			
		||||
    if ($debug) { echo("Peers : $peers_data \n"); }
 | 
			
		||||
    $peers = trim(str_replace("BGP4-MIB::bgpPeerRemoteAs.", "", $peers_data));
 | 
			
		||||
    $peers = trim(str_replace("CISCO-BGP4-MIB::cbgpPeer2RemoteAs.", "", $peers_data));
 | 
			
		||||
    $peers = trim(str_replace("BGP4-MIB::bgpPeerRemoteAs.", "", $peers));
 | 
			
		||||
 | 
			
		||||
    foreach (explode("\n", $peers) as $peer)
 | 
			
		||||
    {
 | 
			
		||||
      list($ver, $peer) = explode(".", $peer,2);
 | 
			
		||||
      list($peer_ip, $peer_as) = explode(" ",  $peer);
 | 
			
		||||
 | 
			
		||||
      if ($peer && $peer_ip != "0.0.0.0")
 | 
			
		||||
      {
 | 
			
		||||
        if ($debug) { echo("Found peer $peer_ip (AS$peer_as)\n"); }
 | 
			
		||||
        $peerlist[] = array('ip' => $peer_ip, 'as' => $peer_as);
 | 
			
		||||
        $peerlist[] = array('ip' => $peer_ip, 'as' => $peer_as, 'ver' => $ver);
 | 
			
		||||
      }
 | 
			
		||||
    } # Foreach
 | 
			
		||||
 | 
			
		||||
@@ -92,18 +100,28 @@ if ($config['enable_bgp'])
 | 
			
		||||
          // Get afi/safi and populate cbgp on cisco ios (xe/xr)
 | 
			
		||||
          unset($af_list);
 | 
			
		||||
 | 
			
		||||
          $af_data = snmp_walk($device, "cbgpPeerAddrFamilyName." . $peer['ip'], "-OsQ", "CISCO-BGP4-MIB", $config['mibdir']);
 | 
			
		||||
          if ($debug) { echo("afi data :: $af_data \n"); }
 | 
			
		||||
 | 
			
		||||
          $afs = trim(str_replace("cbgpPeerAddrFamilyName.".$peer['ip'].".", "", $af_data));
 | 
			
		||||
          foreach (explode("\n", $afs) as $af)
 | 
			
		||||
          if ($peer2 === TRUE) {
 | 
			
		||||
              $af_data = snmpwalk_cache_oid($device, "cbgpPeer2AddrFamilyEntry", $cbgp, "CISCO-BGP4-MIB", $config['mibdir']);
 | 
			
		||||
          } else {
 | 
			
		||||
              $af_data = snmpwalk_cache_oid($device, "cbgpPeerAddrFamilyEntry", $cbgp, "CISCO-BGP4-MIB", $config['mibdir']);
 | 
			
		||||
          }
 | 
			
		||||
          if ($debug) {
 | 
			
		||||
              echo("afi data :: ");
 | 
			
		||||
              print_r($af_data);
 | 
			
		||||
          }
 | 
			
		||||
          foreach ($af_data as $k => $v)
 | 
			
		||||
          {
 | 
			
		||||
            if ($debug) { echo("AFISAFI = $af\n"); }
 | 
			
		||||
            list($afisafi, $text) = explode(" = ", $af);
 | 
			
		||||
            list($afi, $safi) = explode(".", $afisafi);
 | 
			
		||||
            if ($afi && $safi)
 | 
			
		||||
            if ($peer2 === TRUE) {
 | 
			
		||||
                list(,$k) = explode('.',$k,2);
 | 
			
		||||
            }
 | 
			
		||||
            if ($debug) { echo("AFISAFI = $k\n"); }
 | 
			
		||||
            $afisafi_tmp = explode('.', $k);
 | 
			
		||||
            $safi = array_pop($afisafi_tmp);
 | 
			
		||||
            $afi = array_pop($afisafi_tmp);
 | 
			
		||||
            $bgp_ip = str_replace(".$afi.$safi", "", $k);
 | 
			
		||||
            if ($afi && $safi && $bgp_ip == $peer['ip'])
 | 
			
		||||
            {
 | 
			
		||||
              $af_list[$afi][$safi] = 1;
 | 
			
		||||
              $af_list[$bgp_ip][$afi][$safi] = 1;
 | 
			
		||||
              if (dbFetchCell("SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?",array($device['device_id'], $peer['ip'],$afi,$safi)) == 0)
 | 
			
		||||
              {
 | 
			
		||||
                dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp');
 | 
			
		||||
@@ -170,7 +188,7 @@ if ($config['enable_bgp'])
 | 
			
		||||
        {
 | 
			
		||||
          $afi = $entry['afi'];
 | 
			
		||||
          $safi = $entry['safi'];
 | 
			
		||||
          if (!$af_list[$afi][$safi])
 | 
			
		||||
          if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi])
 | 
			
		||||
          {
 | 
			
		||||
            dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'],$peer['ip'],$afi,$safi));
 | 
			
		||||
          }
 | 
			
		||||
 
 | 
			
		||||
@@ -1201,3 +1201,17 @@ function first_oid_match($device, $list) {
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function ip_to_hex($ip) {
 | 
			
		||||
 | 
			
		||||
    if (strstr($ip, ":")) {
 | 
			
		||||
        $ipv6 = explode(':', $ip);
 | 
			
		||||
        foreach ($ipv6 as $item) {
 | 
			
		||||
            $return .= hexdec($item).'.';
 | 
			
		||||
        }
 | 
			
		||||
        $return = substr($return, 0, -1);
 | 
			
		||||
    } else {
 | 
			
		||||
        $return = $ip;
 | 
			
		||||
    }
 | 
			
		||||
    return $return;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,17 +10,52 @@ if ($config['enable_bgp'])
 | 
			
		||||
  {
 | 
			
		||||
    // Poll BGP Peer
 | 
			
		||||
 | 
			
		||||
      $peer2 = FALSE;
 | 
			
		||||
    echo("Checking BGP peer ".$peer['bgpPeerIdentifier']." ");
 | 
			
		||||
 | 
			
		||||
    if (!strstr($peer['bgpPeerIdentifier'],':'))
 | 
			
		||||
    if (!empty($peer['bgpPeerIdentifier']) && $device['os'] != "junos")
 | 
			
		||||
    {
 | 
			
		||||
      # v4 BGP4 MIB
 | 
			
		||||
      // FIXME - needs moved to function
 | 
			
		||||
      $peer_cmd  = $config['snmpget'] . " -M ".$config['mibdir'] . " -m BGP4-MIB -OUvq " . snmp_gen_auth($device) . " " . $device['hostname'].":".$device['port'] . " ";
 | 
			
		||||
        $peer_data_check = snmpwalk_cache_oid($device, "cbgpPeer2RemoteAs", array(), "CISCO-BGP4-MIB", $config['mibdir']);
 | 
			
		||||
        if (count($peer_data_check) > 0) {
 | 
			
		||||
            $peer2 = TRUE;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ($peer2 === TRUE) {
 | 
			
		||||
            $bgp_peer_ip = ip_to_hex($peer['bgpPeerIdentifier']);
 | 
			
		||||
            if (strstr($peer['bgpPeerIdentifier'],":")) {
 | 
			
		||||
                $ip_type = 2;
 | 
			
		||||
                $ip_len = 16;
 | 
			
		||||
                $ip_ver = 'ipv6';
 | 
			
		||||
            } else {
 | 
			
		||||
                $ip_type = 1;
 | 
			
		||||
                $ip_len = 4;
 | 
			
		||||
                $ip_ver = 'ipv4';
 | 
			
		||||
            }
 | 
			
		||||
            $peer_identifier = $ip_type . '.' . $ip_len . '.' . $bgp_peer_ip;
 | 
			
		||||
            $peer_data_tmp = snmp_get_multi($device,
 | 
			
		||||
                " cbgpPeer2State.". $peer_identifier .
 | 
			
		||||
                " cbgpPeer2AdminStatus.". $peer_identifier .
 | 
			
		||||
                " cbgpPeer2InUpdates." . $peer_identifier .
 | 
			
		||||
                " cbgpPeer2OutUpdates." . $peer_identifier .
 | 
			
		||||
                " cbgpPeer2InTotalMessages." . $peer_identifier .
 | 
			
		||||
                " cbgpPeer2OutTotalMessages." . $peer_identifier .
 | 
			
		||||
                " cbgpPeer2FsmEstablishedTime." . $peer_identifier .
 | 
			
		||||
                " cbgpPeer2InUpdateElapsedTime." . $peer_identifier .
 | 
			
		||||
                " cbgpPeer2LocalAddr." . $peer_identifier, "-OQUs", "CISCO-BGP4-MIB",$config['mibdir']);
 | 
			
		||||
            $ident = "$ip_ver.\"".$peer['bgpPeerIdentifier'].'"';
 | 
			
		||||
            unset($peer_data);
 | 
			
		||||
            foreach ($peer_data_tmp[$ident] as $k => $v) {
 | 
			
		||||
                $peer_data .= "$v\n";
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            $peer_cmd = $config['snmpget'] . " -M " . $config['mibdir'] . " -m BGP4-MIB -OUvq " . snmp_gen_auth($device) . " " . $device['hostname'] . ":" . $device['port'] . " ";
 | 
			
		||||
            $peer_cmd .= "bgpPeerState." . $peer['bgpPeerIdentifier'] . " bgpPeerAdminStatus." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerOutUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerInTotalMessages." . $peer['bgpPeerIdentifier'] . " ";
 | 
			
		||||
            $peer_cmd .= "bgpPeerOutTotalMessages." . $peer['bgpPeerIdentifier'] . " bgpPeerFsmEstablishedTime." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdateElapsedTime." . $peer['bgpPeerIdentifier'] . " ";
 | 
			
		||||
            $peer_cmd .= "bgpPeerLocalAddr." . $peer['bgpPeerIdentifier'] . "";
 | 
			
		||||
            $peer_data = trim(`$peer_cmd`);
 | 
			
		||||
        }
 | 
			
		||||
      list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
@@ -134,10 +169,50 @@ if ($config['enable_bgp'])
 | 
			
		||||
        $safi = $peer_afi['safi'];
 | 
			
		||||
        if ($debug) { echo("$afi $safi\n"); }
 | 
			
		||||
 | 
			
		||||
        if ($device['os_group'] == "cisco")
 | 
			
		||||
        {
 | 
			
		||||
        if ($device['os_group'] == "cisco") {
 | 
			
		||||
 | 
			
		||||
            $bgp_peer_ip = ip_to_hex($peer['bgpPeerIdentifier']);
 | 
			
		||||
            if (strstr($peer['bgpPeerIdentifier'], ":")) {
 | 
			
		||||
                $ip_type = 2;
 | 
			
		||||
                $ip_len = 16;
 | 
			
		||||
                $ip_ver = 'ipv6';
 | 
			
		||||
            } else {
 | 
			
		||||
                $ip_type = 1;
 | 
			
		||||
                $ip_len = 4;
 | 
			
		||||
                $ip_ver = 'ipv4';
 | 
			
		||||
            }
 | 
			
		||||
            $ip_cast = 1;
 | 
			
		||||
            if ($peer_afi['safi'] == "multicast") {
 | 
			
		||||
                $ip_cast = 2;
 | 
			
		||||
            } elseif ($peer_afi['safi'] == "unicastAndMulticast") {
 | 
			
		||||
                $ip_cast = 3;
 | 
			
		||||
            } 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']);
 | 
			
		||||
 | 
			
		||||
            if(!empty($check)) {
 | 
			
		||||
 | 
			
		||||
                $cgp_peer_identifier = $ip_type . '.' . $ip_len . '.' . $bgp_peer_ip . '.' . $ip_type . '.' . $ip_cast;
 | 
			
		||||
                $cbgp_data_tmp = snmp_get_multi($device,
 | 
			
		||||
                    " cbgpPeer2AcceptedPrefixes.". $cgp_peer_identifier .
 | 
			
		||||
                    " cbgpPeer2DeniedPrefixes.". $cgp_peer_identifier .
 | 
			
		||||
                    " cbgpPeer2PrefixAdminLimit." . $cgp_peer_identifier .
 | 
			
		||||
                    " cbgpPeer2PrefixThreshold." . $cgp_peer_identifier .
 | 
			
		||||
                    " cbgpPeer2PrefixClearThreshold." . $cgp_peer_identifier .
 | 
			
		||||
                    " cbgpPeer2AdvertisedPrefixes." . $cgp_peer_identifier .
 | 
			
		||||
                    " cbgpPeer2SuppressedPrefixes." . $cgp_peer_identifier .
 | 
			
		||||
                    " cbgpPeer2WithdrawnPrefixes." . $cgp_peer_identifier, "-OQUs", "CISCO-BGP4-MIB",$config['mibdir']);
 | 
			
		||||
                $ident = "$ip_ver.\"".$peer['bgpPeerIdentifier'].'"'. '.' . $ip_type . '.' . $ip_cast;
 | 
			
		||||
                unset($cbgp_data);
 | 
			
		||||
                foreach ($cbgp_data_tmp[$ident] as $k => $v) {
 | 
			
		||||
                    $cbgp_data .= "$v\n";
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            } else {
 | 
			
		||||
 | 
			
		||||
                // FIXME - move to function
 | 
			
		||||
          $cbgp_cmd  = $config['snmpget'] . " -M ".$config['mibdir'] . " -m CISCO-BGP4-MIB -Ovq " . snmp_gen_auth($device) . " " . $device['hostname'].":".$device['port'];
 | 
			
		||||
                $cbgp_cmd = $config['snmpget'] . " -M " . $config['mibdir'] . " -m CISCO-BGP4-MIB -Ovq " . snmp_gen_auth($device) . " " . $device['hostname'] . ":" . $device['port'];
 | 
			
		||||
                $cbgp_cmd .= " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
 | 
			
		||||
                $cbgp_cmd .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
 | 
			
		||||
                $cbgp_cmd .= " cbgpPeerPrefixAdminLimit." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
 | 
			
		||||
@@ -147,10 +222,15 @@ if ($config['enable_bgp'])
 | 
			
		||||
                $cbgp_cmd .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
 | 
			
		||||
                $cbgp_cmd .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
 | 
			
		||||
 | 
			
		||||
          if ($debug) { echo("$cbgp_cmd\n"); }
 | 
			
		||||
                if ($debug) {
 | 
			
		||||
                    echo("$cbgp_cmd\n");
 | 
			
		||||
                }
 | 
			
		||||
                $cbgp_data = preg_replace("/^OID.*$/", "", trim(`$cbgp_cmd`));
 | 
			
		||||
                $cbgp_data = preg_replace("/No Such Instance currently exists at this OID/", "0", $cbgp_data);
 | 
			
		||||
          if ($debug) { echo("$cbgp_data\n"); }
 | 
			
		||||
                if ($debug) {
 | 
			
		||||
                    echo("$cbgp_data\n");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
          list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1405
									
								
								mibs/CISCO-BGP4-MIB
									
									
									
									
									
								
							
							
						
						
									
										1405
									
								
								mibs/CISCO-BGP4-MIB
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user