mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
cdp/lldp rewrite and addition of brocade FDP discovery. now records neighbours even if it doesn't monitor that neighbour
git-svn-id: http://www.observium.org/svn/observer/trunk@862 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
10
cleanup.php
10
cleanup.php
@@ -58,8 +58,8 @@ while($row = mysql_fetch_array($data)) {
|
||||
if($response != $index) {
|
||||
mysql_query("DELETE from interfaces where interface_id = '" . $row['interface_id'] . "'");
|
||||
mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '" . $row['interface_id'] . "'");
|
||||
mysql_query("DELETE from `links` WHERE `src_if` = '" . $row['interface_id'] . "'");
|
||||
mysql_query("DELETE from `links` WHERE `dst_if` = '" . $row['interface_id'] . "'");
|
||||
mysql_query("DELETE from `links` WHERE `local_interface_id` = '" . $row['interface_id'] . "'");
|
||||
mysql_query("DELETE from `links` WHERE `remote_interface_id` = '" . $row['interface_id'] . "'");
|
||||
mysql_query("DELETE from `ipaddr` WHERE `interface_id` = '" . $row['interface_id'] . "'");
|
||||
echo("Removed interface " . $row['ifDescr'] . " from " . $row['hostname'] . "<br />");
|
||||
}
|
||||
@@ -78,11 +78,11 @@ while ($interface = mysql_fetch_array($interface_query)) {
|
||||
echo(mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces`"), 0) . " interfaces at end\n");
|
||||
|
||||
echo(mysql_result(mysql_query("SELECT COUNT(id) FROM `links`"), 0) . " links at start\n");
|
||||
$link_query = mysql_query("SELECT id,src_if,dst_if FROM `links`");
|
||||
$link_query = mysql_query("SELECT id,local_interface_id,remote_interface_id FROM `links`");
|
||||
while ($link = mysql_fetch_array($link_query)) {
|
||||
$id = $link['id'];
|
||||
$src = $link['src_if'];
|
||||
$dst = $link['dst_if'];
|
||||
$src = $link['local_interface_id'];
|
||||
$dst = $link['remote_interface_id'];
|
||||
if(mysql_result(mysql_query("SELECT COUNT(interface_id) FROM `interfaces` WHERE `interface_id` = '$src'"), 0) == '0' || mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` WHERE `interface_id` = '$dst'"), 0) == '0') {
|
||||
mysql_query("delete from links where `id` = '$id'");
|
||||
echo("Deleting link $id \n");
|
||||
|
||||
@@ -95,3 +95,7 @@ ALTER TABLE `processors` CHANGE `processor_description` `processor_descr` varch
|
||||
ALTER TABLE `fanspeed` CHANGE `fan_mibtype` `fan_type` varchar(64) NOT NULL ;
|
||||
ALTER TABLE `voltage` ADD `volt_index` VARCHAR( 8 ) NOT NULL AFTER `volt_oid`,ADD `volt_type` VARCHAR( 32 ) NOT NULL AFTER `volt_index` ;
|
||||
ALTER TABLE `processors` ADD `processor_precision` INT( 11 ) NOT NULL DEFAULT '1';
|
||||
ALTER TABLE `links` CHANGE `cdp` `vendor` VARCHAR( 11 ) NULL DEFAULT NULL;
|
||||
ALTER TABLE `links` ADD `remote_hostname` VARCHAR( 128 ) NOT NULL ,ADD `remote_port` VARCHAR( 128 ) NOT NULL ,ADD `remote_platform` VARCHAR( 128 ) NOT NULL ,ADD `remote_version` VARCHAR( 256 ) NOT NULL ;
|
||||
ALTER TABLE `links` CHANGE `src_if` `local_interface_id` INT( 11 ) NULL DEFAULT NULL ,CHANGE `dst_if` `remote_interface_id` INT( 11 ) NULL DEFAULT NULL ;
|
||||
ALTER TABLE `links` CHANGE `vendor` `protocol` VARCHAR( 11 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL;
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
echo("</td>");
|
||||
echo("<td width=375 valign=top class=interface-desc>");
|
||||
if ( strpos($interface['label'], "oopback") === false && !$graph_type) {
|
||||
$link_query = mysql_query("select * from links AS L, interfaces AS I, devices AS D WHERE L.src_if = '$if_id' AND L.dst_if = I.interface_id AND I.device_id = D.device_id");
|
||||
$link_query = mysql_query("select * from links AS L, interfaces AS I, devices AS D WHERE L.local_interface_id = '$if_id' AND L.remote_interface_id = I.interface_id AND I.device_id = D.device_id");
|
||||
while($link = mysql_fetch_array($link_query)) {
|
||||
# echo("<img src='images/16/connect.png' align=absmiddle alt='Directly Connected' /> " . generateiflink($link, makeshortif($link['label'])) . " on " . generatedevicelink($link, shorthost($link['hostname'])) . "</a><br />");
|
||||
# $br = "<br />";
|
||||
|
||||
24
html/map.php
24
html/map.php
@@ -25,7 +25,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
|
||||
{
|
||||
if($device)
|
||||
{
|
||||
$sql = "SELECT * from interfaces AS I, links AS L WHERE I.device_id = ".$device['device_id']." AND L.src_if = I.interface_id";
|
||||
$sql = "SELECT * from interfaces AS I, links AS L WHERE I.device_id = ".$device['device_id']." AND L.local_interface_id = I.interface_id";
|
||||
$links = mysql_query($sql);
|
||||
|
||||
if (mysql_num_rows($links))
|
||||
@@ -35,20 +35,20 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
|
||||
|
||||
while($link = mysql_fetch_array($links))
|
||||
{
|
||||
$src_if = $link['src_if'];
|
||||
$dst_if = $link['dst_if'];
|
||||
$local_interface_id = $link['local_interface_id'];
|
||||
$remote_interface_id = $link['remote_interface_id'];
|
||||
|
||||
$i = 0; $done = 0;
|
||||
while (isset($linkdone) && $i < count($linkdone))
|
||||
{
|
||||
$thislink = "$dst_if $src_if";
|
||||
$thislink = "$remote_interface_id $local_interface_id";
|
||||
if ($linkdone[$i] == $thislink) { $done = 1; }
|
||||
$i++;
|
||||
}
|
||||
|
||||
if(!$done)
|
||||
{
|
||||
$linkdone[] = "$src_if $dst_if";
|
||||
$linkdone[] = "$local_interface_id $remote_interface_id";
|
||||
|
||||
if($link['ifSpeed'] >= "10000000000")
|
||||
{
|
||||
@@ -64,13 +64,13 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
|
||||
}
|
||||
|
||||
$src = $device['hostname'];
|
||||
$dst = mysql_result(mysql_query("SELECT `hostname` FROM `devices` AS D, `interfaces` AS I WHERE I.interface_id = '$dst_if' AND D.device_id = I.device_id"),0);
|
||||
$dst_host = mysql_result(mysql_query("SELECT D.device_id FROM `devices` AS D, `interfaces` AS I WHERE I.interface_id = '$dst_if' AND D.device_id = I.device_id"),0);
|
||||
$dst = mysql_result(mysql_query("SELECT `hostname` FROM `devices` AS D, `interfaces` AS I WHERE I.interface_id = '$remote_interface_id' AND D.device_id = I.device_id"),0);
|
||||
$dst_host = mysql_result(mysql_query("SELECT D.device_id FROM `devices` AS D, `interfaces` AS I WHERE I.interface_id = '$remote_interface_id' AND D.device_id = I.device_id"),0);
|
||||
|
||||
$sif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM interfaces WHERE `interface_id`=" . $link['src_if'])),$device);
|
||||
$dif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM interfaces WHERE `interface_id`=" . $link['dst_if'])));
|
||||
$sif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM interfaces WHERE `interface_id`=" . $link['local_interface_id'])),$device);
|
||||
$dif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM interfaces WHERE `interface_id`=" . $link['remote_interface_id'])));
|
||||
|
||||
$map .= "\"" . $sif['interface_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue URL=\"/device/".$device['device_id']."/interface/$src_if/\"]\n";
|
||||
$map .= "\"" . $sif['interface_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue URL=\"/device/".$device['device_id']."/interface/$local_interface_id/\"]\n";
|
||||
if (!$ifdone[$src][$sif['interface_id']])
|
||||
{
|
||||
$map .= "\"$src\" -> \"" . $sif['interface_id'] . "\" [weight=500000, arrowsize=0, len=0];\n";
|
||||
@@ -80,9 +80,9 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
|
||||
$map .= "\"$dst\" [URL=\"/device/$dst_host/map/\" fontsize=20 shape=box3d]\n";
|
||||
|
||||
if($dst_host == $device['device_id']) {
|
||||
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"/device/$dst_host/interface/$dst_if/\"]\n";
|
||||
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"/device/$dst_host/interface/$remote_interface_id/\"]\n";
|
||||
} else {
|
||||
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . " \", fontsize=12, fillcolor=lightgray, URL=\"/device/$dst_host/interface/$dst_if/\"]\n";
|
||||
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . " \", fontsize=12, fillcolor=lightgray, URL=\"/device/$dst_host/interface/$remote_interface_id/\"]\n";
|
||||
}
|
||||
|
||||
if (!$ifdone[$dst][$dif['interface_id']])
|
||||
|
||||
@@ -113,7 +113,7 @@ if($config['enable_bgp'] && $device['bgpLocalAs']) {
|
||||
#}
|
||||
|
||||
|
||||
if($_SESSION['userlevel'] >= "5" && mysql_result(mysql_query("SELECT count(*) FROM links AS L, interfaces AS I WHERE I.device_id = '".$device['device_id']."' AND I.interface_id = L.src_if"),0)) {
|
||||
if($_SESSION['userlevel'] >= "5" && mysql_result(mysql_query("SELECT count(*) FROM links AS L, interfaces AS I WHERE I.device_id = '".$device['device_id']."' AND I.interface_id = L.local_interface_id"),0)) {
|
||||
echo('<li class="' . $select['map'] . '">
|
||||
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/map/">
|
||||
<img src="images/16/chart_organisation.png" align="absmiddle" border="0" /> Map
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
mysql_query("DELETE FROM `pseudowires` WHERE `interface_id` = '$interface_id'");
|
||||
mysql_query("DELETE FROM `mac_accounting` WHERE `interface_id` = '$interface_id'");
|
||||
mysql_query("DELETE FROM `links` WHERE `src_if` = '$interface_id'");
|
||||
mysql_query("DELETE FROM `links` WHERE `dst_if` = '$interface_id'");
|
||||
mysql_query("DELETE FROM `links` WHERE `local_interface_id` = '$interface_id'");
|
||||
mysql_query("DELETE FROM `links` WHERE `remote_interface_id` = '$interface_id'");
|
||||
mysql_query("DELETE FROM `interfaces_perms` WHERE `interface_id` = '$interface_id'");
|
||||
mysql_query("DELETE FROM `interfaces` WHERE `interface_id` = '$interface_id'");
|
||||
}
|
||||
|
||||
@@ -2,6 +2,35 @@
|
||||
|
||||
$community = $device['community'];
|
||||
|
||||
echo("Brocade FDP: ");
|
||||
|
||||
$fdp_array = snmpwalk_cache_twopart_oid("snFdpCacheEntry", $device, array(), "FOUNDRY-SN-SWITCH-GROUP-MIB");
|
||||
$fdp_array = $fdp_array[$device['device_id']];
|
||||
if($fdp_array) {
|
||||
unset($fdp_links);
|
||||
foreach( array_keys($fdp_array) as $key)
|
||||
{
|
||||
$interface = mysql_fetch_array(mysql_query("SELECT * FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '".$key."'"));
|
||||
$fdp_if_array = $fdp_array[$key];
|
||||
foreach( array_keys($fdp_if_array) as $entry_key)
|
||||
{
|
||||
$fdp = $fdp_if_array[$entry_key];
|
||||
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$fdp['snFdpCacheDeviceId']."' OR `hostname`='".$fdp['snFdpCacheDeviceId']."'"), 0);
|
||||
if($remote_device_id) {
|
||||
$if = $fdp['snFdpCacheDevicePort'];
|
||||
$remote_interface_id = @mysql_result(mysql_query("SELECT interface_id FROM `interfaces` WHERE (`ifDescr` = '$if' OR `ifName`='$if') AND `device_id` = '".$remote_device_id."'"),0);
|
||||
} else { $remote_interface_id = "0"; }
|
||||
|
||||
discover_link($interface['interface_id'], $fdp['snFdpCacheVendorId'], $remote_interface_id, $fdp['snFdpCacheDeviceId'], $fdp['snFdpCacheDevicePort'], $fdp['snFdpCachePlatform'], $fdp['snFdpCacheVersion']);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
|
||||
|
||||
echo("CISCO-CDP-MIB: ");
|
||||
|
||||
unset($cdp_array);
|
||||
@@ -13,13 +42,14 @@ if($cdp_array) {
|
||||
$interface = mysql_fetch_array(mysql_query("SELECT * FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '".$key."'"));
|
||||
$cdp_if_array = $cdp_array[$key];
|
||||
foreach( array_keys($cdp_if_array) as $entry_key) {
|
||||
$cdp_entry_array = $cdp_if_array[$entry_key];
|
||||
if($device['hostname'] && $interface['ifIndex'] && $cdp_entry_array['cdpCacheDeviceId'] && $cdp_entry_array['cdpCacheDevicePort']){
|
||||
if(strpos($cdp_entry_array['cdpCacheDeviceId'], ")")) { list(,$cdp_entry_array['cdpCacheDeviceId']) = explode("(", $cdp_entry_array['cdpCacheDeviceId']); echo($cdp_entry_array['cdpCacheDeviceId']);
|
||||
list($cdp_entry_array['cdpCacheDeviceId'],) = explode(")", $cdp_entry_array['cdpCacheDeviceId']); echo($cdp_entry_array['cdpCacheDeviceId']); }
|
||||
|
||||
$cdp_links .= $device['hostname'] . "," . $interface['ifIndex'] . "," . $cdp_entry_array['cdpCacheDeviceId'] . "," . $cdp_entry_array['cdpCacheDevicePort'] . "\n";
|
||||
echo ".";
|
||||
$cdp = $cdp_if_array[$entry_key];
|
||||
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$cdp['cdpCacheDeviceId']."' OR `hostname`='".$cdp['cdpCacheDeviceId']."'"), 0);
|
||||
if($remote_device_id) {
|
||||
$if = $cdp['cdpCacheDevicePort'];
|
||||
$remote_interface_id = @mysql_result(mysql_query("SELECT interface_id FROM `interfaces` WHERE (`ifDescr` = '$if' OR `ifName`='$if') AND `device_id` = '".$remote_device_id."'"),0);
|
||||
} else { $remote_interface_id = "0"; }
|
||||
if($interface['interface_id'] && $cdp['cdpCacheDeviceId'] && $cdp['cdpCacheDevicePort']) {
|
||||
discover_link($interface['interface_id'], 'cdp', $remote_interface_id, $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDevicePort'], $cdp['cdpCachePlatform'], $cdp['cdpCacheVersion']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,90 +67,44 @@ if($lldp_array) {
|
||||
$lldp_if_array = $lldp_array[$key];
|
||||
foreach( array_keys($lldp_if_array) as $entry_key) {
|
||||
$interface = mysql_fetch_array(mysql_query("SELECT * FROM `interfaces` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '".$entry_key."'"));
|
||||
$lldp_entry_array = $lldp_if_array[$entry_key];
|
||||
foreach ( array_keys($lldp_entry_array) as $entry_instance) {
|
||||
$lldp_entry_instance_array = $lldp_entry_array[$entry_instance];
|
||||
if($device['hostname'] && $interface['ifIndex'] && $lldp_entry_instance_array['lldpRemSysName'] && $lldp_entry_instance_array['lldpRemPortId']){
|
||||
if(strpos($lldp_entry_instance_array['lldpRemSysName'], ")")) { list(,$lldp_entry_instance_array['lldpRemSysName']) = explode("(", $lldp_entry_instance_array['lldpRemSysName']); echo($lldp_entry_instance_array['lldpRemSysName']);
|
||||
list($lldp_entry_instance_array['lldpRemSysName'],) = explode(")", $lldp_entry_instance_array['lldpRemSysName']); echo($lldp_entry_instance_array['lldpRemSysName']); }
|
||||
$lldp_instance = $lldp_if_array[$entry_key];
|
||||
foreach ( array_keys($lldp_instance) as $entry_instance) {
|
||||
$lldp = $lldp_instance[$entry_instance];
|
||||
$remote_device_id = @mysql_result(mysql_query("SELECT `device_id` FROM `devices` WHERE `sysName` = '".$lldp['lldpRemSysName']."' OR `hostname`='".$lldp['lldpRemSysName']."'"), 0);
|
||||
if($remote_device_id) {
|
||||
$if = $lldp['lldpRemPortDesc'];
|
||||
$remote_interface_id = @mysql_result(mysql_query("SELECT interface_id FROM `interfaces` WHERE (`ifDescr` = '$if' OR `ifName`='$if') AND `device_id` = '".$remote_device_id."'"),0);
|
||||
} else { $remote_interface_id = "0"; }
|
||||
|
||||
$lldp_links .= $device['hostname'] . "," . $interface['ifIndex'] . "," . $lldp_entry_instance_array['lldpRemSysName'] . "," . str_replace('"','',$lldp_entry_instance_array['lldpRemPortId']) . "\n";
|
||||
echo ".";
|
||||
if($interface['interface_id'] && $lldp['lldpRemSysDesc'] && $lldp['lldpRemPortDesc']) {
|
||||
discover_link($interface['interface_id'], 'lldp', $remote_interface_id, $lldp['lldpRemSysName'], $lldp['lldpRemPortDesc'], NULL, $lldp['lldpRemSysDesc']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($debug) {echo("$lldp_links");}
|
||||
|
||||
$discovered_links = (isset($cdp_links) ? $cdp_links : '') . (isset($lldp_links) ? $lldp_links : '');
|
||||
|
||||
if($discovered_links != "\n") {
|
||||
foreach ( explode("\n" ,$discovered_links) as $link ) {
|
||||
if ($link == "") { break; }
|
||||
list($src_host,$src_if, $dst_host, $dst_if) = explode(",", $link);
|
||||
$dst_host = strtolower($dst_host);
|
||||
$dst_if = strtolower($dst_if);
|
||||
$src_host = strtolower($src_host);
|
||||
$src_if = strtolower($src_if);
|
||||
$ip = gethostbyname($dst_host);
|
||||
if ( match_network($config['nets'], $ip) ) {
|
||||
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `sysName` = '$dst_host' OR `hostname`='$dst_host'"), 0) == '0' ) {
|
||||
if($config['lldp_autocreate']) {
|
||||
echo("++ Creating: $dst_host \n");
|
||||
createHost ($dst_host, $community, "v2c");
|
||||
}
|
||||
} else {
|
||||
echo(".");
|
||||
}
|
||||
} else {
|
||||
echo("!($dst_host)");
|
||||
if($debug) { print_r($link_exists); }
|
||||
|
||||
$sql = "SELECT * FROM `links` AS L, `interfaces` AS I WHERE L.local_interface_id = I.interface_id AND I.device_id = '".$device['device_id']."'";
|
||||
if ($query = mysql_query($sql))
|
||||
{
|
||||
while ($test = mysql_fetch_array($query))
|
||||
{
|
||||
$local_interface_id = $test['local_interface_id'];
|
||||
$remote_hostname = $test['remote_hostname'];
|
||||
$remote_port = $test['remote_port'];
|
||||
if($debug) { echo("$local_interface_id -> $remote_hostname -> $remote_port \n"); }
|
||||
if(!$link_exists[$local_interface_id][$remote_hostname][$remote_port]) {
|
||||
echo("-");
|
||||
mysql_query("DELETE FROM `links` WHERE id = '" . $test['id'] . "'");
|
||||
if($debug) {echo(mysql_affected_rows()." deleted ");}
|
||||
}
|
||||
|
||||
$dst_if_id = @mysql_result(mysql_query("SELECT I.interface_id FROM `interfaces` AS I, `devices` AS D WHERE (`ifDescr` = '$dst_if' OR `ifName`='$dst_if') AND (sysName = '$dst_host' OR hostname='$dst_host') AND D.device_id = I.device_id"), 0);
|
||||
|
||||
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `sysName` = '$dst_host' OR `hostname`='$dst_host'"), 0) == '1' &&
|
||||
mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$src_host'"), 0) == '1' &&
|
||||
$dst_if_id &&
|
||||
mysql_result(mysql_query("SELECT COUNT(*) FROM `interfaces` AS I, `devices` AS D WHERE `ifIndex` = '$src_if' AND hostname = '$src_host' AND D.device_id = I.device_id"), 0) == '1')
|
||||
{
|
||||
$src_if_id = mysql_result(mysql_query("SELECT I.interface_id FROM `interfaces` AS I, `devices` AS D WHERE `ifIndex` = '$src_if' AND hostname = '$src_host' AND D.device_id = I.device_id"), 0);
|
||||
$link_exists[] = $src_if_id . "," . $dst_if_id;
|
||||
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `links` WHERE `dst_if` = '$dst_if_id' AND `src_if` = '$src_if_id'"),0) == '0')
|
||||
{
|
||||
$sql = "INSERT INTO `links` (`src_if`, `dst_if`) VALUES ('$src_if_id', '$dst_if_id')";
|
||||
mysql_query($sql);
|
||||
echo("\n++($src_host $src_if -> $dst_host $dst_if)");
|
||||
} else {
|
||||
echo("..");
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($link_exists); echo("\n");
|
||||
|
||||
$sql = "SELECT * FROM `links` AS L, `interfaces` AS I, `devices` AS D WHERE L.src_if = I.interface_id AND I.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
while ($test_link = mysql_fetch_array($query)) {
|
||||
unset($exists);
|
||||
$i = 0;
|
||||
while ($i < count($link_exists) && !isset($exists)) {
|
||||
$this_link = $test_link['src_if'] . ",". $test_link['dst_if'];
|
||||
if ($link_exists[$i] == $this_link) { $exists = 1; }
|
||||
$i++;
|
||||
}
|
||||
if(!isset($exists)) {
|
||||
echo("-");
|
||||
mysql_query("DELETE FROM `links` WHERE `src_if` = '".$test_link['src_if']."' AND `dst_if` = '".$test_link['dst_if']."'");
|
||||
if($debug) { echo($link_exists[$i] . " REMOVED \n"); }
|
||||
} else {
|
||||
if($debug) { echo($link_exists[$i] . " VALID \n"); }
|
||||
}
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,5 +1,32 @@
|
||||
<?php
|
||||
|
||||
function discover_link($local_interface_id, $protocol, $remote_interface_id, $remote_hostname, $remote_port, $remote_platform, $remote_version) {
|
||||
|
||||
global $config; global $debug; global $link_exists;
|
||||
if (mysql_result(@mysql_query("SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = '$remote_hostname' AND `local_interface_id` = '$local_interface_id'
|
||||
AND `protocol` = '$protocol' AND `remote_port` = '$remote_port'"),0) == "0")
|
||||
{
|
||||
$sql = "INSERT INTO `links` (`local_interface_id`,`protocol`,`remote_interface_id`,`remote_hostname`,`remote_port`,`remote_platform`,`remote_version`)
|
||||
VALUES ('$local_interface_id','$protocol','$remote_interface_id','$remote_hostname','$remote_port','$remote_platform','$remote_version')";
|
||||
mysql_query($sql);
|
||||
echo("+"); if($debug) {echo("$sql");}
|
||||
} else {
|
||||
$data = mysql_fetch_array(mysql_query("SELECT * FROM `links` WHERE `remote_hostname` = '$remote_hostname' AND `local_interface_id` = '$local_interface_id'
|
||||
AND `protocol` = '$protocol' AND `remote_port` = '$remote_port'"));
|
||||
if($data['remote_interface_id'] == $remote_interface_id && $data['remote_platform'] == $remote_platform && $remote_version == $remote_version)
|
||||
{
|
||||
echo(".");
|
||||
} else {
|
||||
$sql = "UPDATE `links` SET `remote_interface_id` = $remote_interface_id, `remote_platform` = '$remote_platform', `remote_version` = '$remote_version' WHERE `id` = '".$data['id']."'";
|
||||
mysql_query($sql);
|
||||
echo("U"); if($debug) {echo("$sql");}
|
||||
}
|
||||
}
|
||||
$link_exists[$local_interface_id][$remote_hostname][$remote_port] = 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function discover_fan($device, $oid, $index, $type, $descr, $precision = 1, $low_limit = NULL, $high_limit = NULL, $current = NULL) {
|
||||
|
||||
global $config; global $debug;
|
||||
|
||||
@@ -136,7 +136,7 @@ function snmpwalk_cache_twopart_oid($oid, $device, $array, $mib = 0) {
|
||||
$device_id = $device['device_id'];
|
||||
foreach(explode("\n", $data) as $entry) {
|
||||
list($oid,$value) = explode("=", $entry);
|
||||
$oid = trim($oid); $value = trim($value);
|
||||
$oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value);
|
||||
list($oid, $first, $second) = explode(".", $oid);
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second)) {
|
||||
$array[$device_id][$first][$second][$oid] = $value;
|
||||
@@ -155,7 +155,7 @@ function snmpwalk_cache_threepart_oid($oid, $device, $array, $mib = 0) {
|
||||
$device_id = $device['device_id'];
|
||||
foreach(explode("\n", $data) as $entry) {
|
||||
list($oid,$value) = explode("=", $entry);
|
||||
$oid = trim($oid); $value = trim($value);
|
||||
$oid = trim($oid); $value = trim($value); $value = str_replace("\"", "", $value);
|
||||
list($oid, $first, $second, $third) = explode(".", $oid);
|
||||
if($debug) {echo("$entry || $oid || $first || $second || $third\n");}
|
||||
if (!strstr($value, "at this OID") && isset($oid) && isset($first) && isset($second) && isset($third)) {
|
||||
|
||||
@@ -411,8 +411,8 @@ function delHost($id)
|
||||
$int_if = $int_data['ifDescr'];
|
||||
$int_id = $int_data['interface_id'];
|
||||
mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `links` WHERE `src_if` = '$int_id'");
|
||||
mysql_query("DELETE from `links` WHERE `dst_if` = '$int_id'");
|
||||
mysql_query("DELETE from `links` WHERE `local_interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `links` WHERE `remote_interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `ipaddr` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `ip6adjacencies` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `ip6addr` WHERE `interface_id` = '$int_id'");
|
||||
@@ -449,8 +449,8 @@ function retireHost($id)
|
||||
$int_if = $int_data['ifDescr'];
|
||||
$int_id = $int_data['interface_id'];
|
||||
mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `links` WHERE `src_if` = '$int_id'");
|
||||
mysql_query("DELETE from `links` WHERE `dst_if` = '$int_id'");
|
||||
mysql_query("DELETE from `links` WHERE `local_interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `links` WHERE `remote_interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `ipaddr` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `ip6adjacencies` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `ip6addr` WHERE `interface_id` = '$int_id'");
|
||||
|
||||
12
map.php
12
map.php
@@ -29,7 +29,7 @@ while($loc_data = mysql_fetch_array($loc_result)) {
|
||||
while($dev_data = mysql_fetch_array($dev_result)) {
|
||||
$device_id = $dev_data['device_id'];
|
||||
|
||||
# if(mysql_result(mysql_query("SELECT count(*) from links WHERE src_if = '$device_id' OR dst_if = '$device_id'"),0)) {
|
||||
# if(mysql_result(mysql_query("SELECT count(*) from links WHERE local_interface_id = '$device_id' OR remote_interface_id = '$device_id'"),0)) {
|
||||
$host = $dev_data['hostname'];
|
||||
unset($hostinfo);
|
||||
if(strpos($host, "cust." . $config['mydomain'])) { $hostinfo = "shape=egg style=filled fillcolor=pink"; }
|
||||
@@ -58,16 +58,16 @@ echo("\n}\n");
|
||||
|
||||
}
|
||||
|
||||
$links_sql = "SELECT *, X.ifDescr AS sif, I.ifDescr AS dif FROM links AS L, interfaces AS I, interfaces AS X, devices as D, devices as Y WHERE I.device_id = D.device_id AND X.device_id = Y.device_id AND L.src_if = I.interface_id AND X.interface_id = L.dst_if";
|
||||
$links_sql = "SELECT *, X.ifDescr AS sif, I.ifDescr AS dif FROM links AS L, interfaces AS I, interfaces AS X, devices as D, devices as Y WHERE I.device_id = D.device_id AND X.device_id = Y.device_id AND L.local_interface_id = I.interface_id AND X.interface_id = L.remote_interface_id";
|
||||
|
||||
$links_result = mysql_query($links_sql);
|
||||
while($link_data = mysql_fetch_array($links_result)) {
|
||||
|
||||
$src_if = $link_data['src_if'];
|
||||
$dst_if = $link_data['dst_if'];
|
||||
$local_interface_id = $link_data['local_interface_id'];
|
||||
$remote_interface_id = $link_data['remote_interface_id'];
|
||||
|
||||
$sq = mysql_fetch_row(mysql_query("SELECT `hostname`,`ifSpeed` FROM interfaces AS I, devices as D where I.device_id = D.device_id and I.interface_id = '$src_if'"));
|
||||
$dq = mysql_fetch_row(mysql_query("SELECT `hostname`,`ifSpeed` FROM interfaces AS I, devices as D where I.device_id = D.device_id and I.interface_id = '$dst_if'"));
|
||||
$sq = mysql_fetch_row(mysql_query("SELECT `hostname`,`ifSpeed` FROM interfaces AS I, devices as D where I.device_id = D.device_id and I.interface_id = '$local_interface_id'"));
|
||||
$dq = mysql_fetch_row(mysql_query("SELECT `hostname`,`ifSpeed` FROM interfaces AS I, devices as D where I.device_id = D.device_id and I.interface_id = '$remote_interface_id'"));
|
||||
|
||||
$src = $sq[0];
|
||||
$dst = $dq[0];
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
include("includes/functions-poller.inc.php");
|
||||
include("includes/discovery/functions.inc.php");
|
||||
|
||||
$start = utime();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user