Skip to content

Commit

Permalink
Move views to be on the same level as clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
vuksanv committed Oct 17, 2011
1 parent 226ba64 commit ea898ac
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 104 deletions.
2 changes: 1 addition & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ function retrieve_metrics_cache () {
}
}

if ( ! isset($index_array) ) {
if ( ! isset($index_array) || sizeof($index_array) == 0 ) {

if ( $debug == 1 ) {
echo("DEBUG: Querying GMond for new data\n");
Expand Down
6 changes: 4 additions & 2 deletions ganglia.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
# information as we need to make the page.
#

include_once($conf['ganglia_dir'] . "/version.php");
$ganglia_dir = dirname(__FILE__);

include_once($ganglia_dir . "/version.php");

$error="";

Expand All @@ -35,7 +37,7 @@
$version = array();

# The web frontend version, from conf.php.
$version["webfrontend"] = "$ganglia_version";
$version["webfrontend"] = $GLOBALS["ganglia_version"];

# Get rrdtool version
$rrdtool_version = array();
Expand Down
16 changes: 14 additions & 2 deletions get_context.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<?php
/* $Id: get_context.php 2559 2011-04-11 22:01:34Z bernardli $ */

include_once "./functions.php";

$meta_designator = "Grid";
$cluster_designator = "Cluster Overview";

# Blocking malicious CGI input.
///////////////////////////////////////////////////////////////////////////////
// Determine which context we are in. Context is not specifically specified
// so we have to figure it out ie. if vn(view_name) is present it's the views
// context, if cluster name is specified without a hostname it's cluster etc.
///////////////////////////////////////////////////////////////////////////////
// Blocking malicious CGI input.
$user['clustername'] = isset($_GET["c"]) ?
escapeshellcmd( clean_string( rawurldecode($_GET["c"]) ) ) : NULL;
$user['gridname'] = isset($_GET["G"]) ?
escapeshellcmd( clean_string( rawurldecode($_GET["G"]) ) ) : NULL;

$user['viewname'] = isset($_GET["vn"]) ?
escapeshellcmd( clean_string( rawurldecode($_GET["vn"]) ) ) : NULL;

if($conf['case_sensitive_hostnames'] == 1) {
$user['hostname'] = isset($_GET["h"]) ?
escapeshellcmd( clean_string( rawurldecode($_GET["h"]) ) ) : NULL;
Expand Down Expand Up @@ -111,6 +119,10 @@
{
$context = "tree";
}
else if (isset($user['viewname']))
{
$context = "views";
}
else if(!$user['clustername'] and !$user['gridname'] and !$user['hostname'])
{
$context = "meta";
Expand Down
196 changes: 109 additions & 87 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@

$tpl = new Dwoo_Template_File( template("$header.tpl") );
$data = new Dwoo_Data();

// Server offset used in generating pretty dates and times when zooming
$data->assign("server_utc_offset", date('Z'));
//
$data->assign("page_title", $title);
$data->assign("refresh", $conf['default_refresh']);

Expand Down Expand Up @@ -125,24 +128,19 @@
$data->assign("cluster_url", $cluster_url);
$alt_view = "";

if ($context=="cluster")
{
$alt_view = "<a href=\"./?p=2&amp;c=$cluster_url\">Physical View</a>";
}
elseif ($context=="physical")
{
$alt_view = "<a href=\"./?c=$cluster_url\">Full View</a>";
}
elseif ($context=="node")
{
$alt_view =
"<a href=\"./?c=$cluster_url&amp;h=$node_url&amp;$get_metric_string\">Host View</a>";
}
elseif ($context=="host")
{
$alt_view =
"<a href=\"./?p=2&amp;c=$cluster_url&amp;h=$node_url\">Node View</a>";
if ($context == "cluster") {
$alt_view = "<a href=\"./?p=2&amp;c=$cluster_url\">Physical View</a>";
} elseif ($context == "physical") {
$alt_view = "<a href=\"./?c=$cluster_url\">Full View</a>";
} elseif ($context=="node") {
$alt_view = "<a href=\"./?c=$cluster_url&amp;h=$node_url&amp;$get_metric_string\">Host View</a>";
} elseif ($context=="host") {
$alt_view = "<a href=\"./?p=2&amp;c=$cluster_url&amp;h=$node_url\">Node View</a>";
} elseif ( $context = "views") {
if( checkAccess( GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf ) ) {
$alt_view = '<button onclick="return false" id="create_view_button">Create View</button>';
}
}

$data->assign("alt_view", $alt_view);

Expand All @@ -164,76 +162,100 @@
if ($physical)
$node_menu .= hiddenvar("p", $physical);

if ( $clustername )
{
$url = rawurlencode($clustername);
$node_menu .= "<B><A HREF=\"./?c=$url&amp;$get_metric_string\">$clustername</A></B> ";
$node_menu .= "<B>&gt;</B>\n";
$node_menu .= hiddenvar("c", $clustername);
}
else
{
# No cluster has been specified, so drop in a list
$node_menu .= "<SELECT NAME=\"c\" OnChange=\"ganglia_form.submit();\">\n";
$node_menu .= "<OPTION VALUE=\"\">--Choose a Source\n";
ksort($grid);
foreach( $grid as $k => $v )
{
if ($k==$self) continue;
if (isset($v['GRID']) and $v['GRID'])
{
$url = $v['AUTHORITY'];
$node_menu .="<OPTION VALUE=\"$url\">$k $meta_designator\n";
}
else
{
$url = rawurlencode($k);
$node_menu .="<OPTION VALUE=\"$url\">$k\n";
}
}
$node_menu .= "</SELECT>\n";
}

if ( $clustername && !$hostname )
{
# Drop in a host list if we have hosts
if (!$showhosts) {
$node_menu .= "[Summary Only]";
//////////////////////////////////////////////////////////////////////////////
// Cluster name has been specified. It comes right after
// Grid >
//////////////////////////////////////////////////////////////////////////////
if ( $clustername ) {
$url = rawurlencode($clustername);
$node_menu .= "<b><a href=\"./?c=$url&amp;$get_metric_string\">$clustername</a></b> ";
$node_menu .= "<b>&gt;</b>\n";
$node_menu .= hiddenvar("c", $clustername);
} else if ( $viewname) {
$url = "Views";
$node_menu .= "<b><a href=\"./?vn=default&amp;$get_metric_string\">Views</a></b> ";
$node_menu .= "<b>&gt;</b>\n";
} else {
# No cluster has been specified, so drop in a list
$node_menu .= "<select name=\"c\" OnChange=\"ganglia_form.submit();\">\n";
$node_menu .= "<option value=\"\">--Choose a Source\n";
$node_menu .= "<option value=\"Views\">Views\n";
ksort($grid);
foreach( $grid as $k => $v )
{
if ($k==$self) continue;
if (isset($v['GRID']) and $v['GRID'])
{
$url = $v['AUTHORITY'];
$node_menu .="<OPTION VALUE=\"$url\">$k $meta_designator\n";
}
else
{
$url = rawurlencode($k);
$node_menu .="<OPTION VALUE=\"$url\">$k\n";
}
}
elseif (is_array($hosts_up) || is_array($hosts_down))
{
$node_menu .= "<SELECT NAME=\"h\" OnChange=\"ganglia_form.submit();\">";
$node_menu .= "<OPTION VALUE=\"\">--Choose a Node\n";
if(is_array($hosts_up))
{
uksort($hosts_up, "strnatcmp");
foreach($hosts_up as $k=> $v)
{
$url = rawurlencode($k);
$node_menu .= "<OPTION VALUE=\"$url\">$k\n";
}
}
if(is_array($hosts_down))
{
uksort($hosts_down, "strnatcmp");
foreach($hosts_down as $k=> $v)
{
$url = rawurlencode($k);
$node_menu .= "<OPTION VALUE=\"$url\">$k\n";
}
}
$node_menu .= "</SELECT>\n";
}
else
{
$node_menu .= "<B>No Hosts</B>\n";
}
$node_menu .= "</select>\n";
}

if ( $context == "views" ) {

$node_menu .= "<select name=\"vn\" OnChange=\"ganglia_form.submit();\">";
$node_menu .= "<option value=\"\">--Choose a View</option>";

$available_views = get_available_views();

foreach ( $available_views as $index => $view ) {
if ( $viewname == $view["view_name"])
$extra_options = "selected";
$node_menu .= "<option value=\"" . $view["view_name"] . "\" $extra_options >" . $view['view_name'] . "</option>";
unset($extra_options);
}
else
{
$node_menu .= "<B>$hostname</B>\n";
$node_menu .= hiddenvar("h", $hostname);

$node_menu .= "</select>";

}

/////////////////////////////////////////////////////////////////////////////////
// We are in the cluster view pop up a list box of nodes
/////////////////////////////////////////////////////////////////////////////////
if ( $clustername && !$hostname ) {
# Drop in a host list if we have hosts
if (!$showhosts) {
$node_menu .= "[Summary Only]";
}
elseif (is_array($hosts_up) || is_array($hosts_down))
{
$node_menu .= "<select name=\"h\" OnChange=\"ganglia_form.submit();\">";
$node_menu .= "<option value=\"\">--Choose a Node</option>";
if(is_array($hosts_up))
{
uksort($hosts_up, "strnatcmp");
foreach($hosts_up as $k=> $v)
{
$url = rawurlencode($k);
$node_menu .= "<option value=\"$url\">$k\n";
}
}
if(is_array($hosts_down))
{
uksort($hosts_down, "strnatcmp");
foreach($hosts_down as $k=> $v)
{
$url = rawurlencode($k);
$node_menu .= "<option value=\"$url\">$k\n";
}
}
$node_menu .= "</select>\n";
}
else
{
$node_menu .= "<B>No Hosts</B>\n";
}
} else {
$node_menu .= "<B>$hostname</B>\n";
$node_menu .= hiddenvar("h", $hostname);
}

# Save other CGI variables
$node_menu .= hiddenvar("cr", $controlroom);
Expand Down Expand Up @@ -390,14 +412,14 @@

$custom_time = "";

if ($context == "meta" or $context == "cluster" or $context == "host")
if ($context == "meta" or $context == "cluster" or $context == "host" or $context == "views")
{
$examples = "Feb 27 2007 00:00, 2/27/2007, 27.2.2007, now -1 week,"
. " -2 days, start + 1 hour, etc.";
$custom_time = "&nbsp;&nbsp;or <span class=\"nobr\">from <INPUT TYPE=\"TEXT\" TITLE=\"$examples\" NAME=\"cs\" ID=\"datepicker-cs\" SIZE=\"17\"";
$custom_time = "&nbsp;&nbsp;or <span class=\"nobr\">from <input type=\"TEXT\" title=\"$examples\" NAME=\"cs\" ID=\"datepicker-cs\" SIZE=\"17\"";
if ($cs)
$custom_time .= " value=\"$cs\"";
$custom_time .= "> to <INPUT TYPE=\"TEXT\" TITLE=\"$examples\" NAME=\"ce\" ID=\"datepicker-ce\" SIZE=\"17\"";
$custom_time .= "> to <input type=\"TEXT\" title=\"$examples\" name=\"ce\" ID=\"datepicker-ce\" SIZE=\"17\"";
if ($ce)
$custom_time .= " value=\"$ce\"";
$custom_time .= "> <input type=\"submit\" value=\"Go\">\n";
Expand Down
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
include_once "./header.php";
include_once "./host_view.php";
}
else if ($context == "views")
{
$title = "$viewname view";
include_once "./header.php";
include_once "./views_view.php";
}
else
{
$title = "Unknown Context";
Expand Down
16 changes: 16 additions & 0 deletions js/ganglia.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ $(function(){

$( "#datepicker-cs" ).datepicker({
showOn: "button",
constrainInput: false,
buttonImage: "img/calendar.gif",
buttonImageOnly: true
});
$( "#datepicker-ce" ).datepicker({
showOn: "button",
constrainInput: false,
buttonImage: "img/calendar.gif",
buttonImageOnly: true
});
Expand Down Expand Up @@ -213,3 +215,17 @@ function ganglia_submit(clearonly) {
if (! clearonly)
document.ganglia_form.submit();
}

/* ----------------------------------------------------------------------------
Enlarges a graph using Flot
-----------------------------------------------------------------------------*/
function enlargeGraph(graphArgs) {
$("#enlarge-graph-dialog").dialog('open');
$("#enlarge-graph-dialog").bind( "dialogbeforeclose", function(event, ui) {
$("#enlargeTooltip").remove();
});
// $('#enlarge-graph-dialog-content').html('<img src="graph.php?' + graphArgs + '" />');
$.get('enlarge_graph.php', "flot=1&" + graphArgs, function(data) {
$('#enlarge-graph-dialog-content').html(data);
})
}
11 changes: 0 additions & 11 deletions templates/default/host_view.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,6 @@ function toggleMetricGroup(mgId, mgDiv) {
document.ganglia_form.submit();
}
function enlargeGraph(graphArgs) {
$("#enlarge-graph-dialog").dialog('open');
$("#enlarge-graph-dialog").bind( "dialogbeforeclose", function(event, ui) {
$("#enlargeTooltip").remove();
});
// $('#enlarge-graph-dialog-content').html('<img src="graph.php?' + graphArgs + '" />');
$.get('enlarge_graph.php', "flot=1&" + graphArgs, function(data) {
$('#enlarge-graph-dialog-content').html(data);
})
}
$(function() {
// Modified from http://jqueryui.com/demos/toggle/
//run the currently selected effect
Expand Down
5 changes: 5 additions & 0 deletions templates/default/meta_view.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
{/if}

<table border="0" width="100%">
<tr>
<td class="cluster" colspan="3">
<a href="?vn=default&r=hour"><strong>Views</strong></a> {$source.alt_view}
</td>
</tr>

{foreach $sources source}
<tr>
Expand Down
Loading

0 comments on commit ea898ac

Please sign in to comment.