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

Last change on this file since 270 was 267, checked in by bastiaans, 18 years ago

web/addons/job_monarch/index.php:

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