source: trunk/web/addons/toga/index.php @ 161

Last change on this file since 161 was 161, checked in by bastiaans, 19 years ago

toga/index.php:

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