cleaup some graph drawing functions and interface text printing functions (much moar needed)

git-svn-id: http://www.observium.org/svn/observer/trunk@1086 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2010-05-02 23:24:47 +00:00
parent 3eba59c8ab
commit 81277280da
6 changed files with 108 additions and 56 deletions

View File

@ -1,5 +1,53 @@
<?php
function generateiflink($interface, $text=0, $type = NULL)
{
## Exists only to support older version of this function (i suck)
if($type) { $interface['type'] = $type; }
return generate_if_link($interface, $text);
}
function overlib_link($url, $text, $contents, $class) {
global $config;
$contents = str_replace("\"", "\'", $contents);
$output = "<a class='".$class."' href='".$url."'";
$output .= " onmouseover=\"return overlib('".$contents."'".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">";
$output .= $text."</a>";
return $output;
}
function generate_graph_popup($graph_array)
{
global $config;
## Take $graph_array and print day,week,month,year graps in overlib, hovered over graph
$graph = generate_graph_tag($graph_array);
$content = "<div class=list-large>".$graph_array['popup_title']."</div>";
$content .= "<div style=\'width: 850px\'>";
$graph_array['legend'] = "yes";
$graph_array['height'] = "100";
$graph_array['width'] = "340";
$graph_array['from'] = $config['day'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $config['week'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $config['month'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $config['year'];
$content .= generate_graph_tag($graph_array);
$content .= "</div>";
return overlib_link($graph_array['link'], $graph, $content, NULL);
}
function print_graph_popup($graph_array)
{
echo (generate_graph_popup($graph_array));
}
function permissions_cache($user_id) {
$permissions = array();
$query = mysql_query("SELECT * FROM devices_perms WHERE user_id = '".$user_id."'");
@ -76,23 +124,41 @@ function print_percentage_bar ($width, $height, $percent, $left_text, $left_colo
return $output;
}
function generate_if_link($args)
function generate_if_link($args, $text = NULL)
{
global $twoday; global $now; global $config; global $day; global $month;
$args = ifNameDescr($args);
if(!$args['content']) { $args['content'] = fixIfName($args['label']); }
if(!$args['graph_type']) { $args['graph_type'] = 'bits'; }
if(!$text) { $text = fixIfName($args['label']); }
if(!$args['graph_type']) { $args['graph_type'] = 'port_bits'; }
$class = ifclass($args['ifOperStatus'], $args['ifAdminStatus']);
$graph_url = $config['base_url'] . "/graph.php?if=" . $args['interface_id'] . "&from=$day&to=$now&width=400&height=100&type=" . $args['graph_type'];
$graph_url_month = $config['base_url'] . "/graph.php?if=" . $args['interface_id'] . "&from=$month&to=$now&width=400&height=100&type=" . $args['graph_type'];
$device_id = getifhost($args['interface_id']);
$link = "<a class=$class href='".$config['base_url']."/device/$device_id/interface/" . $args['interface_id'] . "/' ";
$link .= "onmouseover=\" return overlib('";
$link .= "<img src=\'$graph_url\'><br /><img src=\'$graph_url_month\'>', CAPTION, '<span class=list-large>" . $args['hostname'] . " - " . fixifName($args['label']) . "</span>";
if($args['ifAlias']) { $link .= "<br />" . $args['ifAlias']; }
$link .= "' ";
$link .= $config['overlib_defaults'].");\" onmouseout=\"return nd();\" >".$args['content']."</a>";
return $link;
if(!isset($args['hostname'])) { $args = array_merge($args, device_by_id_cache($args['device_id'])); }
$content = "<div class=list-large>".$args['hostname']." - " . fixifName($args['label']) . "</div>";
if($args['ifAlias']) { $content .= $args['ifAlias']."<br />"; }
$content .= "<div style=\'width: 850px\'>";
$graph_array['type'] = $args['graph_type'];
$graph_array['legend'] = "yes";
$graph_array['height'] = "100";
$graph_array['width'] = "340";
$graph_array['from'] = $config['day'];
$graph_array['port'] = $args['interface_id'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $config['week'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $config['month'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $config['year'];
$content .= generate_graph_tag($graph_array);
$content .= "</div>";
$url = $config['base_url']."/device/".$args['device_id']."/interface/" . $args['interface_id'] . "/";
if(interfacepermitted($args['interface_id'])) {
return overlib_link($url, $text, $content, $class);
} else {
return fixifName($text);
}
}
function generate_port_thumbnail($args)

View File

@ -49,8 +49,8 @@ if($ports['total']) {
$ifsep = "";
while($data = mysql_fetch_array($query)) {
$data = ifNameDescr($data);
$data['hostname'] = $device['hostname'];
echo("$ifsep" . generateiflink($data, makeshortif(strtolower($data['label']))));
$data = array_merge($data, $device);
echo("$ifsep" . generate_if_link($data, makeshortif(strtolower($data['label']))));
$ifsep = ", ";
}
unset($ifsep);

View File

@ -116,14 +116,24 @@ echo("</div>
echo("<div style=' margin-bottom: 5px;'>");
if($ports['fileserver']) {
echo("<div style='width: 470px;'>
<a onmouseover=\"return overlib('\
<img src=\'graph.php?type=multi_bits&ports=".$ports['fileserver']."&from=".$day."&to=".$now."&width=400&height=150\'>\
<img src=\'graph.php?type=multi_bits&ports=".$ports['fileserver']."&from=".$week."&to=".$now."&width=400&height=150\'>\
', LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >".
"<div style='font-size: 16px; font-weight: bold; color: #555555;'>Main Fileserver</div>".
"<img src='graph.php?type=multi_bits&ports=".$ports['broadband'].
"&from=".$day."&to=".$now."&width=385&height=100&legend=no'></a></div>");
echo("<div style='width: 470px;'>");
echo("<div style='font-size: 16px; font-weight: bold; color: #555555;'>Central Fileserver</div>");
$graph_array['height'] = "100";
$graph_array['width'] = "385";
$graph_array['to'] = $now;
$graph_array['port'] = $ports['fileserver'];
$graph_array['type'] = "port_bits";
$graph_array['from'] = $day;
$graph_array['legend'] = "no";
$graph_array['popup_title'] = "Central Fileserver";
print_graph_popup($graph_array);
echo("</div>");
}
echo("</div>");

View File

@ -224,39 +224,6 @@ function geteventicon ($message)
if (isset($icon)) { return $icon; } else { return false; }
}
function generateiflink($interface, $text=0, $type = NULL)
{
global $twoday; global $now; global $config; global $day; global $month;
$interface = ifNameDescr($interface);
if (!$text) { $text = fixIfName($interface['label']); }
if (isset($type)) { $interface['graph_type'] = $type; } else { $interface['graph_type'] = 'port_bits'; }
if(!isset($interface['hostname'])) { $interface = array_merge($interface, device_by_id_cache($interface['device_id'])); }
$class = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']);
$graph_url = $config['base_url'] . "/graph.php?port=" . $interface['interface_id'] . "&amp;from=$day&amp;to=$now&amp;width=400&amp;height=100&amp;type=" . $interface['graph_type'];
$graph_url_month = $config['base_url'] . "/graph.php?port=" . $interface['interface_id'] . "&amp;from=$month&amp;to=$now&amp;width=400&amp;height=100&amp;type=" . $interface['graph_type'];
$device_id = getifhost($interface['interface_id']);
$url = $config['base_url']."/device/$device_id/interface/" . $interface['interface_id'] . "/";
$contents = "<div class=list-large>" . $interface['hostname'] . " - " . fixifName($interface['label']) . "</div>";
if ($interface['ifAlias']) { $contents .= htmlentities($interface['ifAlias'] ."<br />" ); }
$contents .= "<img src=\'$graph_url\'><br /><img src=\'$graph_url_month\'>";
$link = overlib_link($url, $text, $contents, $class);
if(interfacepermitted($interface['interface_id'])) {
return $link;
} else {
return fixifName($interface['label']);
}
}
function overlib_link($url, $text, $contents, $class) {
global $config;
$contents = str_replace("\"", "\'", $contents);
$output = "<a class='".$class."' href='".$url."'";
$output .= " onmouseover=\"return overlib('".$contents."'".$config['overlib_defaults'].");\" onmouseout=\"return nd();\">";
$output .= $text."</a>";
return $output;
}
function generatedevicelink($device, $text=0, $start=0, $end=0)
{
global $twoday; global $day; global $now; global $config;

View File

@ -140,6 +140,7 @@ if ($device['os'] == "junos")
$cbgp_cmd .= " cbgpPeerAdvertisedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
$cbgp_cmd .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
$cbgp_cmd .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
if($debug) { echo("$cbgp_cmd\n"); }
$cbgp_data = preg_replace("/^OID.*$/", "", trim(`$cbgp_cmd`));
if($debug) { echo("$cbgp_data\n"); }

View File

@ -122,4 +122,12 @@ $week = time() - (7 * 24 * 60 * 60);
$month = time() - (31 * 24 * 60 * 60);
$year = time() - (365 * 24 * 60 * 60);
$config['now'] = $now;
$config['day'] = $day;
$config['twoday'] = $twoday;
$config['week'] = $week;
$config['month'] = $month;
$config['year'] = $year;
?>