source: branches/0.4/web/addons/job_monarch/index.php @ 821

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