fix lldp discovery code, small fix, addhost fix

git-svn-id: http://www.observium.org/svn/observer/trunk@1547 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2010-07-30 15:04:44 +00:00
parent be799247e3
commit ee3fbf8a5f
4 changed files with 16 additions and 12 deletions

View File

@@ -15,14 +15,15 @@ if($argv[1]) {
$port = 161;
if (!$snmpver) $snmpver = "v2c";
if (!$community) $community = $config['snmp']['community'][0];
if ($community) { unset($config['snmp']['community']); $config['snmp']['community'][] = $community; }
list($hostshort) = explode(".", $host);
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '".mres($host)."'"), 0) == '0' ) {
if ( isDomainResolves($argv[1])){
if ( isPingable($argv[1])) {
if ( isSNMPable($argv[1], $community, $snmpver, $port)) {
$snmphost = trim(str_replace("\"", "", shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0")));
# FIXME should be a foreach $config['snmp']['community'][0] as $community
$snmphost = trim(str_replace("\"", "", shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c ".$config['snmp']['community'][0]." $host:$port sysName.0")));
if ($snmphost == "" || ($snmphost && ($snmphost == $host || $hostshort = $host))) {
$return = createHost ($host, $community, $snmpver, $port);
if($return) { echo($return . "\n"); } else { echo("Adding $host failed\n"); }

View File

@@ -41,7 +41,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
{
if($device)
{
$sql = "SELECT * from ports AS I, links AS L WHERE I.device_id = ".$device['device_id']." AND L.local_interface_id = I.interface_id";
$sql = "SELECT * from ports AS I, links AS L WHERE I.device_id = ".$device['device_id']." AND L.local_interface_id = I.interface_id ORDER BY L.remote_hostname";
$links = mysql_query($sql);
if (mysql_num_rows($links))
@@ -57,8 +57,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
$i = 0; $done = 0;
while (isset($linkdone) && $i < count($linkdone))
{
$thislink = "$remote_interface_id $local_interface_id";
if ($linkdone[$i] == $thislink) { $done = 1; }
if ($linkdone[$i] == "$remote_interface_id $local_interface_id") { $done = 1; }
$i++;
}
@@ -68,7 +67,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
if($link['ifSpeed'] >= "10000000000")
{
$info = "color=lightred style=\"setlinewidth(8)\"";
$info = "color=red3 style=\"setlinewidth(6)\"";
} elseif ($link['ifSpeed'] >= "1000000000") {
$info = "color=lightblue style=\"setlinewidth(4)\"";
} elseif ($link['ifSpeed'] >= "100000000") {
@@ -88,8 +87,6 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
$dst = $link['remote_hostname'];
}
$sif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['local_interface_id'])),$device);
if($remote_interface_id) {
$dif = ifNameDescr(mysql_fetch_array(mysql_query("SELECT * FROM ports WHERE `interface_id`=" . $link['remote_interface_id'])));
@@ -107,7 +104,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
$map .= "\"$dst\" [URL=\"{$config['base_url']}/device/$dst_host/map/\" fontsize=20 shape=box3d]\n";
if($dst_host == $device['device_id']) {
if($dst_host == $device['device_id'] || $where == '') {
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n";
} else {
$map .= "\"" . $dif['interface_id'] . "\" [label=\"" . $dif['label'] . " \", fontsize=12, fillcolor=lightgray, URL=\"{$config['base_url']}/device/$dst_host/interface/$remote_interface_id/\"]\n";
@@ -140,7 +137,11 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format']))
$_GET['format'] = 'png';
}
$img = shell_exec("echo \"".addslashes($map)."\" | dot -T".$_GET['format']."");
$maptool = 'unflatten -f -l 5 |dot';
if ($where == '') { $maptool = 'neato -Gpack'; }
$img = shell_exec("echo \"".addslashes($map)."\" | $maptool -T".$_GET['format']."");
if($_GET['format'] == "png") {
header("Content-type: image/".$_GET['format']);
} elseif ($_GET['format'] == "svg") {

View File

@@ -73,6 +73,7 @@ if ($device['os'] == "mgeups")
list($unused,$numPhase) = explode(' ',$oids);
for($i = 1; $i <= $numPhase;$i++)
{
unset($current);
$current_oid = ".1.3.6.1.4.1.705.1.7.2.1.5.$i";
$descr = "Output"; if ($numPhase > 1) $descr .= " Phase $i";
$current = snmp_get($device, $current_oid, "-Oqv");
@@ -97,6 +98,7 @@ if ($device['os'] == "mgeups")
list($unused,$numPhase) = explode(' ',$oids);
for($i = 1; $i <= $numPhase;$i++)
{
unset($current);
$current_oid = ".1.3.6.1.4.1.705.1.6.2.1.6.$i";
$descr = "Input"; if ($numPhase > 1) $descr .= " Phase $i";
$current = snmp_get($device, $current_oid, "-Oqv");

View File

@@ -84,8 +84,8 @@ if($lldp_array) {
$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 `ports` WHERE (`ifDescr` = '$if' OR `ifName`='$if') AND `device_id` = '".$remote_device_id."'"),0);
$if = $lldp['lldpRemPortDesc']; $id = $lldp['lldpRemPortId'];
$remote_interface_id = @mysql_result(mysql_query("SELECT interface_id FROM `ports` WHERE (`ifDescr` = '$if' OR `ifName`='$if' OR `ifDescr`= '$id' OR `ifName`='$id') AND `device_id` = '".$remote_device_id."'"),0);
} else { $remote_interface_id = "0"; }
if(is_numeric($interface['interface_id']) && isset($lldp['lldpRemSysName']) && isset($lldp['lldpRemPortId'])) {
discover_link($interface['interface_id'], 'lldp', $remote_interface_id, $lldp['lldpRemSysName'], $lldp['lldpRemPortId'], NULL, $lldp['lldpRemSysDesc']);