mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 16:08:55 +02:00
fixed bgp consolidation code
git-svn-id: http://www.observium.org/svn/observer/trunk@651 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -60,52 +60,55 @@
|
|||||||
|
|
||||||
## Process disovered peers
|
## Process disovered peers
|
||||||
|
|
||||||
foreach ($peerlist as $peer)
|
if (isset($peerlist))
|
||||||
{
|
{
|
||||||
$astext = get_astext($peer['as']);
|
foreach ($peerlist as $peer)
|
||||||
|
{
|
||||||
|
$astext = get_astext($peer['as']);
|
||||||
|
|
||||||
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `bgpPeers` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"),0) < '1')
|
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `bgpPeers` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"),0) < '1')
|
||||||
{
|
|
||||||
$add = mysql_query("INSERT INTO bgpPeers (`device_id`, `bgpPeerIdentifier`, `bgpPeerRemoteAS`) VALUES ('".$device['device_id']."','".$peer['ip']."','".$peer['as']."')");
|
|
||||||
echo("+");
|
|
||||||
} else {
|
|
||||||
$update = mysql_query("UPDATE `bgpPeers` SET bgpPeerRemoteAs = " . $peer['as'] . ", astext = '" . mysql_escape_string($astext) . "' WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'");
|
|
||||||
echo(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
## Get afi/safi and populate cbgp on cisco ios (xe/xr)
|
|
||||||
if ($device['os'] == "ios")
|
|
||||||
{
|
|
||||||
unset($af_list);
|
|
||||||
$af_cmd = $config['snmpwalk'] . " -CI -m CISCO-BGP4-MIB -OsQ -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
|
|
||||||
$af_cmd .= "cbgpPeerAddrFamilyName." . $peer['ip'];
|
|
||||||
$afs = trim(str_replace("cbgpPeerAddrFamilyName.".$peer['ip'].".", "", `$af_cmd`));
|
|
||||||
foreach (explode("\n", $afs) as $af)
|
|
||||||
{
|
{
|
||||||
list($afisafi, $text) = explode(" = ", $af);
|
$add = mysql_query("INSERT INTO bgpPeers (`device_id`, `bgpPeerIdentifier`, `bgpPeerRemoteAS`) VALUES ('".$device['device_id']."','".$peer['ip']."','".$peer['as']."')");
|
||||||
list($afi, $safi) = explode(".", $afisafi);
|
echo("+");
|
||||||
if($afi && $safi)
|
} else {
|
||||||
|
$update = mysql_query("UPDATE `bgpPeers` SET bgpPeerRemoteAs = " . $peer['as'] . ", astext = '" . mysql_escape_string($astext) . "' WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'");
|
||||||
|
echo(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
## Get afi/safi and populate cbgp on cisco ios (xe/xr)
|
||||||
|
if ($device['os'] == "ios")
|
||||||
|
{
|
||||||
|
unset($af_list);
|
||||||
|
$af_cmd = $config['snmpwalk'] . " -CI -m CISCO-BGP4-MIB -OsQ -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'].":".$device['port'] . " ";
|
||||||
|
$af_cmd .= "cbgpPeerAddrFamilyName." . $peer['ip'];
|
||||||
|
$afs = trim(str_replace("cbgpPeerAddrFamilyName.".$peer['ip'].".", "", `$af_cmd`));
|
||||||
|
foreach (explode("\n", $afs) as $af)
|
||||||
{
|
{
|
||||||
$af_list['$afi']['$safi'] = 1;
|
list($afisafi, $text) = explode(" = ", $af);
|
||||||
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `bgpPeers_cbgp` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND afi = '$afi' AND safi = '$safi'"),0) == 0)
|
list($afi, $safi) = explode(".", $afisafi);
|
||||||
|
if($afi && $safi)
|
||||||
{
|
{
|
||||||
mysql_query("INSERT INTO `bgpPeers_cbgp` (device_id,bgpPeerIdentifier, afi, safi) VALUES ('".$device['device_id']."','".$peer['ip']."','$afi','$safi')");
|
$af_list['$afi']['$safi'] = 1;
|
||||||
|
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `bgpPeers_cbgp` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND afi = '$afi' AND safi = '$safi'"),0) == 0)
|
||||||
|
{
|
||||||
|
mysql_query("INSERT INTO `bgpPeers_cbgp` (device_id,bgpPeerIdentifier, afi, safi) VALUES ('".$device['device_id']."','".$peer['ip']."','$afi','$safi')");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$af_query = mysql_query("SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'");
|
$af_query = mysql_query("SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'");
|
||||||
while ($entry = mysql_fetch_array($af_query))
|
while ($entry = mysql_fetch_array($af_query))
|
||||||
{
|
|
||||||
$afi = $entry['afi'];
|
|
||||||
$afi = $entry['safi'];
|
|
||||||
if (!$af_list['$afi']['$safi'])
|
|
||||||
{
|
{
|
||||||
mysql_query("DELETE FROM `bgpPeers_cbgp` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND afi = '$afi' AND safi = '$safi'");
|
$afi = $entry['afi'];
|
||||||
}
|
$afi = $entry['safi'];
|
||||||
} # AF list
|
if (!$af_list['$afi']['$safi'])
|
||||||
} # if os = ios
|
{
|
||||||
} # Foreach
|
mysql_query("DELETE FROM `bgpPeers_cbgp` WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND afi = '$afi' AND safi = '$safi'");
|
||||||
|
}
|
||||||
|
} # AF list
|
||||||
|
} # if os = ios
|
||||||
|
} # Foreach
|
||||||
|
} # isset
|
||||||
|
|
||||||
## Delete removed peers
|
## Delete removed peers
|
||||||
|
|
||||||
@@ -127,6 +130,8 @@ while ($entry = mysql_fetch_array($query)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($peerlist);
|
||||||
|
|
||||||
echo("\n");
|
echo("\n");
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ if ($device['os'] == "junos")
|
|||||||
$peer_cmd .= " jnxBgpM2PeerFsmEstablishedTime.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 .= " jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6." . $junos_v6[$peer_ip];
|
||||||
$peer_cmd .= " jnxBgpM2PeerLocalAddr.0.ipv6." . $junos_v6[$peer_ip];
|
$peer_cmd .= " jnxBgpM2PeerLocalAddr.0.ipv6." . $junos_v6[$peer_ip];
|
||||||
$peer_data = trim(`$peer_cmd`);
|
$peer_data = trim(`$peer_cmd . '|grep -v "No Such Instance"'`);
|
||||||
if ($debug) echo "\n$peer_cmd\n";
|
if ($debug) echo "\n$peer_cmd\n";
|
||||||
list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data);
|
list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user