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

Last change on this file since 754 was 754, checked in by ramonb, 11 years ago

job_monarch/index.php:

  • bring back anti cache headers

job_monarch/templates/index.tpl:

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