forked from ganglia/ganglia-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.php
486 lines (415 loc) · 16.3 KB
/
header.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<?php
session_start();
if (isset($_GET['date_only'])) {
$d = date("r");
echo $d;
exit(0);
}
# RFM - These definitions are here to eliminate "undefined variable"
# error messages in ssl_error_log.
!isset($initgrid) and $initgrid = 0;
!isset($metricname) and $metricname = "";
!isset($context_metrics) and $context_metrics = "";
if ( $context == "control" && $controlroom < 0 )
$header = "header-nobanner";
else
$header = "header";
#
# sacerdoti: beginning of Grid tree state handling
#
$me = $self . "@";
array_key_exists($self, $grid) and $me = $me . $grid[$self]['AUTHORITY'];
if ($initgrid)
{
$gridstack = array();
$gridstack[] = $me;
}
else if ($gridwalk=="fwd")
{
# push our info on gridstack, format is "name@url>name2@url".
if (end($gridstack) != $me)
{
$gridstack[] = $me;
}
}
else if ($gridwalk=="back")
{
# pop a single grid off stack.
if (end($gridstack) != $me)
{
array_pop($gridstack);
}
}
$gridstack_str = join(">", $gridstack);
$gridstack_url = rawurlencode($gridstack_str);
if (strstr($clustername, "http://")) {
header("Location: $clustername?gw=fwd&gs=$gridstack_url");
}
if ($initgrid or $gridwalk)
{
# Use cookie so we dont have to pass gridstack around within this site.
# Cookie values are automatically urlencoded. Expires in a day.
if ( !isset($_COOKIE["gs"]) or $_COOKIE["gs"] != $gridstack_str )
setcookie("gs", $gridstack_str, time() + 86400);
}
# Invariant: back pointer is second-to-last element of gridstack. Grid stack
# never has duplicate entries.
# RFM - The original line caused an error when count($gridstack) = 1. This
# should fix that.
$parentgrid = $parentlink = NULL;
if(count($gridstack) > 1) {
list($parentgrid, $parentlink) = explode("@", $gridstack[count($gridstack)-2]);
}
$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']);
# Templated Logo image
$data->assign("images","./templates/${conf['template_name']}/images");
$data->assign( "date", date("r"));
# The page to go to when "Get Fresh Data" is pressed.
if (isset($page))
$data->assign("page",$page);
else
$data->assign("page","./");
#
# Used when making graphs via graph.php. Included in most URLs
#
$sort_url=rawurlencode($sort);
$get_metric_string = "m=$metricname&r=$range&s=$sort_url&hc=${conf['hostcols']}&mc=${conf['metriccols']}";
if ($jobrange and $jobstart)
$get_metric_string .= "&jr=$jobrange&js=$jobstart";
if ($cs)
$get_metric_string .= "&cs=" . rawurlencode($cs);
if ($ce)
$get_metric_string .= "&ce=" . rawurlencode($ce);
$start_timestamp = null;
$end_timestamp = null;
if ($cs) {
if (! is_numeric($cs)) {
$start_timestamp = strtotime($cs);
} else {
$start_timestamp = $cs;
}
if ($ce) {
if (! is_numeric($ce)) {
$end_timestamp = strtotime($ce);
} else {
$end_timestamp = $ce;
}
} else {
$end_timestamp = $start_timestamp - $conf['time_ranges'][$range];
}
} else {
$end_timestamp = time();
$start_timestamp = $end_timestamp - $conf['time_ranges'][$range];
}
$data->assign("start_timestamp", $start_timestamp);
$data->assign("end_timestamp", $end_timestamp);
# Set the Alternate view link.
$cluster_url=rawurlencode($clustername);
$node_url=rawurlencode($hostname);
# Make some information available to templates.
$data->assign("cluster_url", $cluster_url);
$alt_view = "";
if ($context == "cluster") {
$alt_view = "<button class=\"header_btn\" onclick=\"window.location='./?p=2&c=$cluster_url';return false;\">Physical View</button>";
} elseif ($context == "physical") {
$alt_view = "<button class=\"header_btn\" onclick=\"window.location='./?c=$cluster_url';return false;\">Full View</button>";
} elseif ($context=="node") {
$alt_view = "<button class=\"header_btn\" onclick=\"window.location='./?c=$cluster_url&h=$node_url&$get_metric_string';return false;\">Host View</button>";
} elseif ($context=="host") {
$alt_view = "<button class=\"header_btn\" onclick=\"window.location='./?p=2&c=$cluster_url&h=$node_url';return false;\">Node View</button>";
} elseif ( $context == "views") {
if( checkAccess( GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf ) ) {
$alt_view = '<button onclick="return false" id="create_view_button">Create View</button>';
$alt_view .= ' <button onclick="return false" id="delete_view_button">Delete View</button>';
}
}
$data->assign("alt_view", $alt_view);
# Build the node_menu
$node_menu = "";
if (($context != 'views') && ($context != 'compare_hosts')) {
if ($parentgrid) {
$node_menu .= "<B><A HREF=\"$parentlink?gw=back&gs=$gridstack_url&$get_metric_string\">". "$parentgrid $meta_designator</A></B> ";
$node_menu .= "<B>></B>\n";
}
# Show grid.
if ((($self != "unspecified") && !$parentgrid) ||
$conf['always_display_grid_view']) {
$mygrid = ($self == "unspecified") ? "" : $self;
$node_menu .= "<B><A HREF=\"./?$get_metric_string\">$mygrid $meta_designator</A></B> ";
$node_menu .= "<B>></B>\n";
}
if ($physical)
$node_menu .= hiddenvar("p", $physical);
/////////////////////////////////////////////////////////////////////////////
// Cluster name has been specified. It comes right after
// Grid >
/////////////////////////////////////////////////////////////////////////////
if ( $clustername ) {
$url = rawurlencode($clustername);
$node_menu .= "<b><a href=\"./?c=$url&$get_metric_string\">$clustername</a></b> ";
$node_menu .= "<b>></b>\n";
$node_menu .= hiddenvar("c", $clustername);
} else if ($context == "decompose_graph") {
$node_menu .= '<input type="hidden" name="dg" value="1">';
$node_menu .= "Decompose Graph";
} 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";
}
/////////////////////////////////////////////////////////////////////////////
// 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);
$node_menu .= hiddenvar("js", $jobstart);
$node_menu .= hiddenvar("jr", $jobrange);
}
$data->assign("node_menu", $node_menu);
//////////////////// Build the metric menu ////////////////////////////////////
if (count($metrics)) {
$firsthost = key($metrics);
foreach ($metrics[$firsthost] as $m => $foo)
$context_metrics[] = $m;
foreach ($reports as $r => $foo)
$context_metrics[] = $r;
}
#
# If there are graphs present, show ranges.
#
$range_menu = "";
if (!$physical) {
$context_ranges = array_keys( $conf['time_ranges'] );
if ($jobrange)
$context_ranges[]="job";
if ($cs or $ce)
$context_ranges[]="custom";
$range_menu = "Last ";
foreach ($context_ranges as $v) {
$url=rawurlencode($v);
if ($v == $range)
$checked = "checked=\"checked\"";
else
$checked = "";
$range_menu .= "<input OnChange=\"ganglia_submit();\" type=\"radio\" id=\"range-$v\" name=\"r\" value=\"$v\" $checked/><label for=\"range-$v\">$v</label>";
}
}
$data->assign("range_menu", $range_menu);
#
# Only compute metric-picker options if we have some, and are in cluster context.
#
if (is_array($context_metrics) and $context == "cluster") {
$picker_metrics = array();
# Find all the optional reports
if ($handle = opendir($conf['gweb_root'] . '/graph.d')) {
// If we are using RRDtool reports can be json or PHP suffixes
if ( $conf['graph_engine'] == "rrdtool" )
$report_suffix = "php|json";
else
$report_suffix = "json";
while (false !== ($file = readdir($handle))) {
if ( preg_match("/(.*)(_report)\.(" . $report_suffix .")/", $file, $out) ) {
if ( ! in_array($out[1] . "_report", $context_metrics) )
$context_metrics[] = $out[1] . "_report";
}
}
closedir($handle);
}
sort($context_metrics);
foreach ($context_metrics as $key) {
$url = rawurlencode($key);
$picker_metrics[] = "<option value=\"$url\">$key</option>";
}
$data->assign("picker_metrics", join("", $picker_metrics));
$data->assign("is_metrics_picker_disabled", "");
} else {
// We have to disable the sort_menu if we are not in the cluster context
$data->assign("is_metrics_picker_disabled", '$("#sort_menu").toggle(); ');
$data->assign("picker_metrics", "" );
}
#
# Show sort order if there is more than one physical machine present.
#
$sort_menu = "";
if ($context == "meta" or $context == "cluster") {
$context_sorts[]="ascending";
$context_sorts[]="descending";
$context_sorts[]="by name";
// Show sort order options for meta context only:
if ($context == "meta" ) {
$context_sorts[]="by hosts up";
$context_sorts[]="by hosts down";
}
$sort_menu = "Sorted ";
foreach ($context_sorts as $v) {
$url=rawurlencode($v);
if ($v == $sort)
$checked = "checked=\"checked\"";
else
$checked = "";
$sort_menu .= "<input OnChange=\"ganglia_submit();\" type=\"radio\" id=\"radio-" .str_replace(" ", "_", $v) . "\" name=\"s\" value=\"$v\" $checked/><label for=\"radio-" . str_replace(" ", "_", $v) . "\">$v</label>";
}
}
$data->assign("sort_menu", $sort_menu );
if ($context == "physical" or $context == "cluster" or $context == 'host' )
{
# Present a width list
$cols_menu = "<SELECT NAME=\"hc\" OnChange=\"ganglia_form.submit();\">\n";
foreach(range(0,25) as $cols)
{
$cols_menu .= "<OPTION VALUE=$cols ";
if ($cols == $conf['hostcols'])
$cols_menu .= "SELECTED";
$cols_menu .= ">$cols\n";
}
$cols_menu .= "</SELECT>\n";
$size_menu = '<SELECT NAME="z" OnChange="ganglia_form.submit();">';
$size_arr = $conf['graph_sizes_keys'];
foreach ($size_arr as $size) {
if ($size == "default")
continue;
$size_menu .= "<OPTION VALUE=\"$size\"";
if ( ( isset($clustergraphsize) && ($size === $clustergraphsize))
|| (!isset($clustergraphsize) && ($size === 'small' )) || ( !isset($_GET['z']) && $context == 'host' && $size == "medium" ) ) {
$size_menu .= " SELECTED";
}
$size_menu .= ">$size</OPTION>\n";
}
$size_menu .= "</SELECT>\n";
# Assign template variable in cluster view.
}
if ($context == "host") {
# Present a width list
$metric_cols_menu = "<select name=\"mc\" OnChange=\"ganglia_form.submit();\">\n";
foreach(range(1,25) as $metric_cols) {
$metric_cols_menu .= "<option value=$metric_cols ";
if ($metric_cols == $conf['metriccols'])
$metric_cols_menu .= "selected";
$metric_cols_menu .= ">$metric_cols\n";
}
$metric_cols_menu .= "</select>\n";
}
$custom_time = "";
if ( in_array($context , array ("meta", "cluster", "host", "views", "decompose_graph", "compare_hosts") ) ) {
$examples = "Feb 27 2007 00:00, 2/27/2007, 27.2.2007, now -1 week,"
. " -2 days, start + 1 hour, etc.";
$custom_time = "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\"";
if ($ce)
$custom_time .= " value=\"$ce\"";
$custom_time .= "> <input type=\"submit\" value=\"Go\">\n";
$custom_time .= "<input type=\"button\" value=\"Clear\" onclick=\"ganglia_submit(1)\"></span>\n";
# $custom_time .= $calendar;
$data->assign("custom_time", $custom_time);
# $tpl->assign("custom_time_head", $calendar_head);
$data->assign("custom_time_head", "");
} else {
$data->assign("custom_time_head", "");
}
$data->assign("custom_time", $custom_time);
/////////////////////////////////////////////////////////////////////////
// Additional filter to add after the list of nodes. Only useful in
// cluster_view
/////////////////////////////////////////////////////////////////////////
if ( $context == "cluster" ) {
if ( isset($user['host_regex']) && $user['host_regex'] != "" )
$set_host_regex_value="value='" . $user['host_regex'] . "'";
else
$set_host_regex_value="";
// In some clusters you may have thousands of hosts which may load
// for a long time. For those cases we have the ability to display
// only the max amount of graphs and put place holders for the rest ie.
// it will say only print host name without an image
$max_graphs_options = array(1000,500,200,100,50,25,20,15,10);
if ( isset($user['max_graphs']) && is_numeric($user['max_graphs']) )
$max_graphs = $user['max_graphs'];
else
$max_graphs = $conf['max_graphs'];
$max_graphs_values = "<option value=0>all</option>";
foreach ( $max_graphs_options as $key => $value ) {
if ( $max_graphs == $value )
$max_graphs_values .= "<option selected>" . $value . "</option>";
else
$max_graphs_values .= "<option>" . $value . "</option>";
}
$data->assign("additional_filter_options", 'Show only nodes matching <input name=host_regex ' .$set_host_regex_value . '>'
. '<input class="header_btn" type="SUBMIT" VALUE="Filter">'
. ' <span class="nobr">Max graphs to show <select onChange="ganglia_submit();" name="max_graphs">' . $max_graphs_values . '</select></span>'
);
} else
$data->assign("additional_filter_options", '');
if($conf['auth_system'] == 'enabled') {
$data->assign('auth_system_enabled', true);
$username = sanitize( GangliaAuth::getInstance()->getUser() );
$data->assign('username', $username);
} else {
$data->assign('auth_system_enabled', false);
$data->assign('username', null);
}
if ( $conf['overlay_events'] == true )
$data->assign('overlay_events', true);
$data->assign('selected_tab', $user['selected_tab']);
$data->assign('view_name', $user['viewname']);
$additional_buttons = "";
if ($context == 'views' || $context == 'decompose_graph' || $context == 'host') {
$additional_buttons = '<input title="Hide/Show Events" type="checkbox" id="show_all_events" onclick="showAllEvents(this.checked)"/><label for="show_all_events">Hide/Show Events</label>';
}
$data->assign('additional_buttons', $additional_buttons);
# Make sure that no data is cached..
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); # Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified
header ("Cache-Control: no-cache, must-revalidate"); # HTTP/1.1
header ("Pragma: no-cache"); # HTTP/1.0
if (file_exists("./templates/${conf['template_name']}/user_header.tpl"))
$data->assign('user_header', "1");
$dwoo->output($tpl, $data);
?>