source: trunk/web/addons/job_monarch/index.php @ 406

Last change on this file since 406 was 406, checked in by bastiaans, 17 years ago

web/addons/job_monarch/index.php:

  • moved (duplicate) makeHeader when overview
  • fix for metrics compilation list

web/addons/job_monarch/overview.php:

  • added makeHeader call
  • Property svn:keywords set to Id
File size: 11.4 KB
Line 
1<?php
2/*
3 *
4 * This file is part of Jobmonarch
5 *
6 * Copyright (C) 2006  Ramon Bastiaans
7 *
8 * Jobmonarch is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * Jobmonarch is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 *
22 * SVN $Id: index.php 406 2007-07-05 15:49:25Z bastiaans $
23 */
24
25ini_set("memory_limit","80M");
26set_time_limit(0);
27
28if ( !empty( $_GET ) ) {
29        extract( $_GET );
30}
31
32$my_dir = getcwd();
33
34include_once "./libtoga.php";
35
36global $GANGLIA_PATH;
37chdir( $GANGLIA_PATH );
38
39include_once "./class.TemplatePower.inc.php";
40chdir( $my_dir );
41
42$httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET );
43$clustername = $httpvars->getClusterName();
44$view = $httpvars->getHttpVar( "view" );
45
46$filter = array();
47
48if( !isset($view) ) $view = "overview";
49if( !isset($sortorder) ) $sortorder = "asc";
50if( !isset($sortby) ) $sortby = "id";
51
52if( isset( $filterorder ) && ($filterorder!='') ) {
53        $myfilter_fields = explode( ",", $filterorder );
54} else {
55        if( isset($queue) && ($queue!='')) $filter[queue]=$queue;
56        if( isset($state) && ($state!='')) $filter[state]=$state;
57        if( isset($user) && ($user!='')) $filter[user]=$user;
58        if( isset($id) && ($id!='')) $filter[id]=$id;
59}
60
61// Fill filter array in order they were picked by user
62if( isset($myfilter_fields) ) {
63
64        foreach( $myfilter_fields as $myfilter ) {
65
66                switch( $myfilter ) {
67
68                        case "queue":
69                                $filter[queue]=$queue;
70                                break;
71                        case "state":
72                                $filter[state]=$state;
73                                break;
74                        case "user":
75                                $filter[user]=$user;
76                                break;
77                        case "id":
78                                $filter[id]=$id;
79                                break;
80                }
81        }
82}
83
84//if( isset($queue) && ($queue!='')) $filter[queue]=$queue;
85//if( isset($state) && ($state!='')) $filter[state]=$state;
86//if( isset($user) && ($user!='')) $filter[user]=$user;
87//if( isset($id) && ($id!='')) $filter[id]=$id;
88
89function epochToDatetime( $epoch ) {
90
91        return strftime( "%d-%m-%Y %H:%M:%S", $epoch );
92}
93
94function makeHeader( $page_call, $title, $longtitle ) {
95
96        global $tpl, $grid, $context, $initgrid;
97        global $jobrange, $jobstart;
98        global $page, $gridwalk, $clustername;
99        global $parentgrid, $physical, $hostname;
100        global $self, $filter, $cluster_url, $get_metric_string;
101        global $metrics, $reports, $m, $default_metric;
102        global $default_refresh, $filterorder, $view;
103        global $JOB_ARCHIVE, $period_start, $period_stop, $h, $id;
104        global $job_start, $job_stop;
105       
106        if( isset($default_metric) and !isset($m) )
107                $metricname = $default_metric;
108        else
109                if( isset( $m ) )
110                        $metricname = $m;
111                else
112                        $metricname = "load_one";
113
114        $header = "header";
115
116        # Maintain our path through the grid tree.
117        $me = $self . "@" . $grid[$self][AUTHORITY];
118
119        $gridstack = array();
120        $gridstack[] = $me;
121
122        if ($gridwalk=="fwd") {
123                # push our info on gridstack, format is "name@url>name2@url".
124                if (end($gridstack) != $me) {
125                        $gridstack[] = $me;
126                }
127        } else if ($gridwalk=="back") {
128                # pop a single grid off stack.
129                if (end($gridstack) != $me) {
130                        array_pop($gridstack);
131                }
132        }
133
134        $gridstack_str = join(">", $gridstack);
135        $gridstack_url = rawurlencode($gridstack_str);
136
137        if ($initgrid or $gridwalk) {
138                # Use cookie so we dont have to pass gridstack around within this site.
139                # Cookie values are automatically urlencoded. Expires in a day.
140                setcookie("gs", $gridstack_str, time() + 86400);
141        }
142
143        # Invariant: back pointer is second-to-last element of gridstack. Grid stack never
144        # has duplicate entries.
145        list($parentgrid, $parentlink) = explode("@", $gridstack[count($gridstack)-2]);
146
147        # Setup a redirect to a remote server if you choose a grid from pulldown menu. Tell
148        # destination server that we're walking foward in the grid tree.
149        if (strstr($clustername, "http://")) {
150                $tpl->assign("refresh", "0");
151                $tpl->assign("redirect", ";URL=$clustername?gw=fwd&gs=$gridstack_url");
152                echo "<h2>Redirecting, please wait...</h2>";
153                $tpl->printToScreen();
154                exit;
155        }
156        $tpl->gotoBlock( "_ROOT" );
157
158        if( $view != "search" )
159                $tpl->assign( "refresh", $default_refresh );
160
161        $tpl->assign( "date", date("r") );
162        //printf("lg %s\n", $longtitle );
163        //printf("title %s\n", $title );
164        $tpl->assign( "longpage_title", $longtitle );
165        $tpl->assign( "page_title", $title );
166
167        # The page to go to when "Get Fresh Data" is pressed.
168        $tpl->assign("page","./");
169
170        # Templated Logo image
171        $tpl->assign("images","./templates/$template_name/images");
172
173        #
174        # Used when making graphs via graph.php. Included in most URLs
175        #
176        $sort_url=rawurlencode($sort);
177        $get_metric_string = "m=$metric&r=$range&s=$sort_url&hc=$hostcols";
178
179        if ($jobrange and $jobstart)
180                $get_metric_string .= "&jr=$jobrange&js=$jobstart";
181
182        # Set the Alternate view link.
183        $cluster_url=rawurlencode($clustername);
184        $node_url=rawurlencode($hostname);
185
186        # Make some information available to templates.
187        $tpl->assign("cluster_url", $cluster_url);
188        # Build the node_menu
189        $node_menu = "";
190
191        if ($parentgrid) {
192                $node_menu .= "<B>$parentgrid $meta_designator</B> ";
193                $node_menu .= "<B>&gt;</B>\n";
194        }
195
196        # Show grid.
197        $mygrid =  ($self == "unspecified") ? "" : $self;
198        $node_menu .= "<B><A HREF=\"../..\">$mygrid $meta_designator</A></B> ";
199        $node_menu .= "<B>&gt;</B>\n";
200
201        if ($physical)
202                $node_menu .= hiddenvar("p", $physical);
203
204        if ( $clustername ) {
205                $url = rawurlencode($clustername);
206                $node_menu .= "<B><A HREF=\"../../?c=".rawurlencode($clustername)."\">$clustername</A></B> ";
207                $node_menu .= "<B>&gt;</B>\n";
208                $node_menu .= hiddenvar("c", $clustername);
209        }
210
211        if (!count($metrics)) {
212                echo "<h4>Cannot find any metrics for selected cluster \"$clustername\", exiting.</h4>\n";
213                echo "Check ganglia XML tree (telnet $ganglia_ip $ganglia_port)\n";
214                exit;
215        }
216        reset($metrics);
217        $firsthost = key($metrics);
218
219        $mmfh   = array();
220
221        $mmfh   = $metrics[$firsthost];
222
223        $context_metrics        = array();
224
225        //foreach ($mmfh as $mm => $mfoo)
226        foreach( $mmfh as $mm => $bla )
227        {
228                $context_metrics[] = $mm;
229        }
230
231        foreach ($reports as $mr => $mfoo)
232                $context_metrics[] = $mr;
233
234        $node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> ";
235
236        if( isset( $hostname ) ) {
237
238                $node_menu .= "<B>&gt;</B>\n";
239                $href = "<A HREF=\"./?c=".rawurlencode($clustername)."&h=".$hostname."\">";
240                $node_menu .= "<B>$href";
241                $node_menu .= "host: $hostname</A></B> ";
242        }
243
244        if( count( $filter ) > 0 && $view != "search" ) {
245
246                $my_ct = 1;
247                $filter_nr = count( $filter );
248
249                foreach( $filter as $filtername=>$filterval ) {
250
251                        $node_menu .= "<B>&gt;</B>\n";
252
253                        $href = "<A HREF=\"./?c=".rawurlencode($clustername);
254                        $temp_ct = 0;
255                        $n_filter = $filter;
256                        $my_filterorder = "";
257                        $my_filters = array_keys( $filter );
258
259                        foreach( $n_filter as $n_filtername=>$n_filterval ) {
260
261                                if( $temp_ct < $my_ct ) {
262                                        $href .= "&". $n_filtername . "=" . $n_filterval;
263
264                                        if( $my_filterorder == "" )
265                                                $my_filterorder = $my_filters[$temp_ct];
266                                        else
267                                                $my_filterorder .= "," . $my_filters[$temp_ct];
268                                }
269
270                                $temp_ct++;
271                        }
272                        $href .= "&filterorder=$my_filterorder\">";
273
274                        if( $my_ct < $filter_nr )
275                                $node_menu .= "<B>$href$filtername: $filterval</A></B> ";
276                        else
277                                $node_menu .= "<B>$filtername: $filterval</B> ";
278
279                        $my_ct++;
280                }
281        }
282
283        $m = $metricname;
284
285
286        $tpl->gotoBlock( "_ROOT" );
287        $tpl->assignGlobal("view", $view);
288
289        if( array_key_exists( "id", $filter ) or isset($hostname) ) {
290
291                //print_r( $context_metrics );
292
293                if (is_array($context_metrics) ) {
294                        $metric_menu = "<B>Metric</B>&nbsp;&nbsp;"
295                                ."<SELECT NAME=\"m\" OnChange=\"".$form_name.".submit();\">\n";
296
297                        sort($context_metrics);
298                        foreach( $context_metrics as $k ) {
299                                $url = rawurlencode($k);
300                                $metric_menu .= "<OPTION VALUE=\"$url\" ";
301                                if ($k == $metricname )
302                                        $metric_menu .= "SELECTED";
303                                $metric_menu .= ">$k\n";
304                        }
305                        $metric_menu .= "</SELECT>\n";
306
307                }
308
309                $tpl->assign("metric_menu", $metric_menu );
310
311                if( $view == "search" or $view == "host" ) {
312                        $tpl->newBlock("timeperiod");
313                        if( is_numeric( $period_start ) ) {
314                                $period_start = epochToDatetime( $period_start );
315                        }
316                        if( is_numeric( $period_stop ) ) {
317                                $period_stop = epochToDatetime( $period_stop );
318                        }
319                        $tpl->assign("period_start", $period_start );
320                        $tpl->assign("period_stop", $period_stop );
321                        $tpl->assign("hostname", $hostname );
322
323                        if( $view == "host" ) {
324                                $tpl->newBlock("hostview");
325                                $tpl->assign("job_start", $job_start );
326                                $tpl->assign("job_stop", $job_stop );
327                        }
328                }
329
330        }
331
332        //$ex_fn = $tpl->getVarValue( "_ROOT", "form_name" );
333
334        if( $view == "search" or $view == "host" ) {
335
336                $node_menu .= "<B>&gt;</B>\n";
337                $node_menu .= "<B>Jobarchive</B> ";
338                $form_name = "archive_search_form";
339                $tpl->assignGlobal("form_name", $form_name );
340
341        } else {
342                $form_name = "toga_form";
343                $tpl->assignGlobal("form_name", $form_name );
344        }
345
346        if( $JOB_ARCHIVE && $page_call == 'overview' ) {
347                $tpl->newBlock( "search" );
348                $tpl->assignGlobal( "cluster_url", rawurlencode($clustername) );
349                $tpl->assignGlobal( "cluster", $clustername );
350        }
351        $tpl->gotoBlock( "_ROOT" );
352        $tpl->assignGlobal( "cluster", $clustername );
353        $tpl->assign("node_menu", $node_menu);
354
355        # Make sure that no data is cached..
356        header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    # Date in the past
357        header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified
358        header ("Cache-Control: no-cache, must-revalidate");  # HTTP/1.1
359        header ("Pragma: no-cache");                          # HTTP/1.0
360}
361
362function makeFooter() {
363        global $tpl, $version, $parsetime, $monarchversion;
364
365        $tpl->gotoBlock( "_ROOT" );
366        $tpl->assign("webfrontend-version",$version["webfrontend"]);
367        $tpl->assign("monarch-version", $monarchversion);
368
369        if ($version["gmetad"]) {
370                $tpl->assign("webbackend-component", "gmetad");
371                $tpl->assign("webbackend-version",$version["gmetad"]);
372        } else if ($version["gmond"]) {
373                $tpl->assign("webbackend-component", "gmond");
374                $tpl->assign("webbackend-version", $version["gmond"]);
375        }
376
377        $tpl->assign("parsetime", sprintf("%.4f", $parsetime) . "s");
378}
379
380function includeSearchpage() {
381        global $tpl;
382
383        $tpl->assignInclude( "main", "templates/search.tpl" );
384
385}
386
387function includeOverview() {
388        global $tpl;
389
390        $tpl->assignInclude( "main", "templates/overview.tpl" );
391}
392
393function includeHostPage() {
394
395        global $tpl;
396
397        $tpl->assignInclude( "main", "templates/host_view.tpl" );
398}
399
400$tpl = new TemplatePower( "templates/index.tpl" );
401
402$tpl->assignInclude( "header", "templates/header.tpl" );
403
404if( isset( $h ) and $h != '' ) {
405        $hostname = $h;
406        //$view = "host";
407}
408
409switch( $view ) {
410
411        case "overview":
412
413                includeOverview();
414                break;
415
416        case "search":
417
418                includeSearchPage();
419                break;
420
421        case "host":
422
423                includeHostPage();
424                break;
425
426        default:
427
428                includeOverview();
429                break;
430}
431
432$tpl->assignInclude( "footer", "templates/footer.tpl" );
433$tpl->prepare();
434
435$longtitle = "Batch Report :: Powered by Job Monarch!";
436$title = "Batch Report";
437//makeHeader( 'index' );
438$tpl->assign("cluster_url", rawurlencode($clustername) );
439$tpl->assign("cluster", $clustername );
440
441switch( $view ) {
442
443        case "overview":
444
445                include "./overview.php";
446                makeOverview();
447                break;
448
449        case "search":
450
451                include "./search.php";
452                makeSearchPage();
453                break;
454
455        case "host":
456
457                include "./host_view.php";
458                makeHostView();
459                break;
460
461        default:
462
463                makeOverview();
464                break;
465}
466
467makeFooter();
468$tpl->printToScreen();
469?>
Note: See TracBrowser for help on using the repository browser.