some experimental map code to show all map data we have on one image.. does not alter current behaviour for existing single device tree maps

git-svn-id: http://www.observium.org/svn/observer/trunk@640 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2010-01-09 18:23:39 +00:00
parent acce06e54e
commit 73708aeb58

View File

@ -3,42 +3,51 @@
include("../config.php"); include("../config.php");
include("../includes/functions.php"); include("../includes/functions.php");
#FIXME if no get device this produces an error (and there is no authentication on this file?) #FIXME no auth on thie file??
$device = mysql_fetch_array(mysql_query("SELECT * from devices WHERE device_id = ".$_GET['device']."")); if ($_GET['device']) { $where = "WHERE device_id = ".$_GET['device']; } else { $where = ""; }
$deviceresult = mysql_query("SELECT * from devices $where");
if($device && preg_match("/^[a-z]*$/", $_GET['format'])) { if (preg_match("/^[a-z]*$/", $_GET['format']))
{
$map = "digraph G { sep=0.01; size=\"12,5.5\"; pack=100; bgcolor=transparent; splines=true; overlap=scale; concentrate=0; epsilon=0.001; rankdir=0; $map = "digraph G { sep=0.01; size=\"12,5.5\"; pack=100; bgcolor=transparent; splines=true; overlap=scale; concentrate=0; epsilon=0.001; rankdir=0;
node [ fontname=\"helvetica\", fontstyle=bold, style=filled, color=white, fillcolor=lightgrey, overlap=false;]; node [ fontname=\"helvetica\", fontstyle=bold, style=filled, color=white, fillcolor=lightgrey, overlap=false;];
edge [ bgcolor=white; fontname=\"helvetica\"; fontstyle=bold; arrowhead=dot; arrowtail=dot]; edge [ bgcolor=white; fontname=\"helvetica\"; fontstyle=bold; arrowhead=dot; arrowtail=dot];
graph [bgcolor=transparent;]; graph [bgcolor=transparent;];
"; ";
$map .= "\"".$device['hostname']."\" [fontsize=20 fillcolor=\"lightblue\" URL=\"/device/".$device['device_id']."/map/\" shape=box3d]\n"; while ($device = mysql_fetch_array($deviceresult))
{
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";
$links = mysql_query($sql);
if (mysql_num_rows($links))
{
$map .= "\"".$device['hostname']."\" [fontsize=20 fillcolor=\"lightblue\" URL=\"/device/".$device['device_id']."/map/\" shape=box3d]\n";
}
$sql = "SELECT * from interfaces AS I, links AS L WHERE I.device_id = ".$device['device_id']." AND L.src_if = I.interface_id"; while($link = mysql_fetch_array($links))
$links = mysql_query($sql); {
while($link = mysql_fetch_array($links)) {
$src_if = $link['src_if']; $src_if = $link['src_if'];
$dst_if = $link['dst_if']; $dst_if = $link['dst_if'];
$i = 0; $done = 0; $i = 0; $done = 0;
while ($i < count($linkdone)) { while ($i < count($linkdone))
{
$thislink = "$dst_if $src_if"; $thislink = "$dst_if $src_if";
if ($linkdone[$i] == $thislink) { $done = 1; } if ($linkdone[$i] == $thislink) { $done = 1; }
$i++; $i++;
} }
if(!$done)
{
if(!$done) {
$linkdone[] = "$src_if $dst_if"; $linkdone[] = "$src_if $dst_if";
if($link['ifSpeed'] >= "10000000000") { if($link['ifSpeed'] >= "10000000000")
{
$info = "color=lightred style=\"setlinewidth(8)\""; $info = "color=lightred style=\"setlinewidth(8)\"";
} elseif ($link['ifSpeed'] >= "1000000000") { } elseif ($link['ifSpeed'] >= "1000000000") {
$info = "color=lightblue style=\"setlinewidth(4)\""; $info = "color=lightblue style=\"setlinewidth(4)\"";
@ -68,28 +77,27 @@ while($link = mysql_fetch_array($links)) {
$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/$dst_if/\"]\n";
} }
$map .= "\"" . $dif['interface_id'] . "\" -> \"$dst\" [weight=500000, arrowsize=0, len=0];\n"; $map .= "\"" . $dif['interface_id'] . "\" -> \"$dst\" [weight=500000, arrowsize=0, len=0];\n";
$map .= "\"" . $sif['interface_id'] . "\" -> \"" . $dif['interface_id'] . "\" [weight=1, arrowhead=normal, arrowtail=normal, len=2, $info] \n"; $map .= "\"" . $sif['interface_id'] . "\" -> \"" . $dif['interface_id'] . "\" [weight=1, arrowhead=normal, arrowtail=normal, len=2, $info] \n";
}
}
$done = 0;
}
} }
} $map .= "
$map .= "
};"; };";
if ($_GET['debug'] == 1) { echo("<pre>$map</pre>");exit(); } if ($_GET['debug'] == 1) { echo("<pre>$map</pre>");exit(); }
$img = shell_exec("echo \"".addslashes($map)."\" | dot -T".$_GET['format'].""); $img = shell_exec("echo \"".addslashes($map)."\" | dot -T".$_GET['format']."");
if($_GET['format'] == "png") { if($_GET['format'] == "png") {
header("Content-type: image/".$_GET['format']); header("Content-type: image/".$_GET['format']);
} elseif ($_GET['format'] == "svg") { } elseif ($_GET['format'] == "svg") {
header("Content-type: image/svg+xml"); header("Content-type: image/svg+xml");
$img = str_replace("<a ", "<a target = \"_parent\" ", $img); $img = str_replace("<a ", "<a target = \"_parent\" ", $img);
} }
echo("$img"); echo("$img");
} }
?> ?>