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

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

job_monarch/search.php,
job_monarch/index.php:

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