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

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

web/addons/job_monarch/index.php,
web/addons/job_monarch/templates/header.tpl:

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