discovery/bgp: use snmp_get(), bugfixed patch by Corentin Chary

git-svn-id: http://www.observium.org/svn/observer/trunk@1806 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-03-08 17:28:24 +00:00
parent 4d96296d1e
commit f66e5379cc
+22 -16
View File
@@ -6,10 +6,7 @@ if ($config['enable_bgp'])
echo("BGP Sessions : ");
# FIXME convert to internal
$as_cmd = $config['snmpwalk'] . " -M " . $config['mibdir'] . " -m BGP4-MIB -CI -Oqvn -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
$as_cmd .= ".1.3.6.1.2.1.15.2";
$bgpLocalAs = trim(shell_exec($as_cmd));
$bgpLocalAs = trim(snmp_walk($device, ".1.3.6.1.2.1.15.2", "-Oqvn", "BGP4-MIB", $config['mibdir']));
if (is_numeric($bgpLocalAs))
{
@@ -20,10 +17,8 @@ if ($config['enable_bgp'])
mysql_query("UPDATE devices SET bgpLocalAs = '$bgpLocalAs' WHERE device_id = '".$device['device_id']."'"); echo("Updated AS ");
}
$peers_cmd = $config['snmpwalk'] . " -M " . $config['mibdir'] . " -m BGP4-MIB -CI -Oq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
$peers_cmd .= "BGP4-MIB::bgpPeerRemoteAs";
$peers_data = shell_exec($peers_cmd);
if($debug) { echo("Peers : $peers_cmd --> \n$peers_data \n"); }
$peers_data = snmp_walk($device, "BGP4-MIB::bgpPeerRemoteAs", "-Oq", "BGP4-MIB", $config['mibdir']);
if ($debug) { echo("Peers : $peers_data \n"); }
$peers = trim(str_replace("BGP4-MIB::bgpPeerRemoteAs.", "", $peers_data));
foreach (explode("\n", $peers) as $peer)
@@ -43,9 +38,9 @@ if ($config['enable_bgp'])
## FIXME: needs a big cleanup! also see below.
$peers_cmd = $config['snmpwalk'] . " -M " . $config['mibdir'] . " -M ".$config['install_dir']."/mibs/junos -m BGP4-V2-MIB-JUNIPER -CI -Onq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
$peers_cmd .= "jnxBgpM2PeerRemoteAs.0.ipv6"; # FIXME: is .0 the only possible value here?
$peers = trim(str_replace(".1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.","", `$peers_cmd`));
# 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));
foreach (explode("\n", $peers) as $peer)
{
list($peer_ip_snmp, $peer_as) = split(" ", $peer);
@@ -91,10 +86,16 @@ if (isset($peerlist))
{
## Get afi/safi and populate cbgp on cisco ios (xe/xr)
unset($af_list);
# FIXME: this could be replaced by the following line:
# $af_data = snmp_walk($device, "cbgpPeerAddrFamilyName." . $peer['ip'], "-OsQ", "CISCO-BGP4-MIB", $config['mibdir']);
# but I am unable to test it for now.
$af_cmd = $config['snmpwalk'] . " -M " . $config['mibdir'] . " -CI -m CISCO-BGP4-MIB -OsQ -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
$af_cmd .= "cbgpPeerAddrFamilyName." . $peer['ip'];
$af_data = shell_exec($af_cmd);
if($debug) { echo("afi data :: $af_cmd --> \n $af_data \n"); }
# FIXME replace until here
if ($debug) { echo("afi data :: $af_data \n"); }
$afs = trim(str_replace("cbgpPeerAddrFamilyName.".$peer['ip'].".", "", $af_data));
foreach (explode("\n", $afs) as $af)
{
@@ -135,7 +136,7 @@ if (isset($peerlist))
$j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex'];
break;
default:
echo("PANIC: Don't know RemoteAddrType " . $entry['jnxBgpM2PeerRemoteAddrType'] . "!\n");
echo("HALP? Don't know RemoteAddrType " . $entry['jnxBgpM2PeerRemoteAddrType'] . "!\n");
break;
}
}
@@ -181,20 +182,24 @@ if (isset($peerlist))
unset($j_peerIndexes);
} # isset
## Delete removed peers
### Delete removed peers
$sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
$query = mysql_query($sql);
while ($entry = mysql_fetch_array($query)) {
while ($entry = mysql_fetch_array($query))
{
unset($exists);
$i = 0;
while ($i < count($peerlist) && !isset($exists))
{
if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { $exists = 1; }
$i++;
}
if(!isset($exists)) {
if (!isset($exists))
{
mysql_query("DELETE FROM bgpPeers WHERE bgpPeer_id = '" . $entry['bgpPeer_id'] . "'");
mysql_query("DELETE FROM bgpPeers_cbgp WHERE bgpPeer_id = '" . $entry['bgpPeer_id'] . "'");
echo("-");
@@ -207,3 +212,4 @@ echo("\n");
}
?>