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: image.php 329 2007-04-22 13:36:26Z bastiaans $ |
---|
23 | */ |
---|
24 | |
---|
25 | ini_set("memory_limit","200M"); |
---|
26 | set_time_limit(0); |
---|
27 | |
---|
28 | include_once "./libtoga.php"; |
---|
29 | |
---|
30 | if ( !empty( $_GET ) ) |
---|
31 | { |
---|
32 | extract( $_GET ); |
---|
33 | } |
---|
34 | |
---|
35 | function makeSession() |
---|
36 | { |
---|
37 | $ds = new DataSource(); |
---|
38 | $myxml_data = &$ds->getData(); |
---|
39 | |
---|
40 | unset( $_SESSION['data'] ); |
---|
41 | |
---|
42 | $_SESSION['data'] = &$myxml_data; |
---|
43 | $_SESSION['gather_time'] = time(); |
---|
44 | } |
---|
45 | |
---|
46 | global $session_active, $_SESSION, $myxml_data; |
---|
47 | |
---|
48 | function checkSessionPollInterval( $poll_interval ) |
---|
49 | { |
---|
50 | global $session_active, $_SESSION; |
---|
51 | |
---|
52 | if( ! session_active ) |
---|
53 | { |
---|
54 | return 0; |
---|
55 | } |
---|
56 | |
---|
57 | if( isset( $_SESSION['poll_interval'] ) ) |
---|
58 | { |
---|
59 | if( $poll_interval <> $_SESSION['poll_interval'] ) |
---|
60 | { |
---|
61 | $_SESSION['poll_interval'] = $poll_interval; |
---|
62 | } |
---|
63 | } |
---|
64 | else |
---|
65 | { |
---|
66 | $_SESSION['poll_interval'] = $poll_interval; |
---|
67 | } |
---|
68 | |
---|
69 | session_write_close(); |
---|
70 | |
---|
71 | $session_active = false; |
---|
72 | } |
---|
73 | |
---|
74 | function checkSession() |
---|
75 | { |
---|
76 | global $session_active, $_SESSION; |
---|
77 | |
---|
78 | session_start(); |
---|
79 | |
---|
80 | $session_active = true; |
---|
81 | |
---|
82 | // I got nothing; create session |
---|
83 | // |
---|
84 | if( ! isset( $_SESSION['gather_time'] ) || ! isset( $_SESSION['data'] ) ) |
---|
85 | { |
---|
86 | makeSession(); |
---|
87 | |
---|
88 | return 0; |
---|
89 | } |
---|
90 | |
---|
91 | if( isset( $_SESSION['poll_interval'] ) ) |
---|
92 | { |
---|
93 | $gather_time = $_SESSION['gather_time']; |
---|
94 | $poll_interval = $_SESSION['poll_interval']; |
---|
95 | |
---|
96 | $cur_time = time(); |
---|
97 | |
---|
98 | // If poll_interval time elapsed since last update; recreate session |
---|
99 | // |
---|
100 | if( ($cur_time - $gather_time) >= $poll_interval ) |
---|
101 | { |
---|
102 | makeSession(); |
---|
103 | |
---|
104 | return 0; |
---|
105 | } |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | checkSession(); |
---|
110 | $myxml_data = &$_SESSION['data']; |
---|
111 | session_write_close(); |
---|
112 | |
---|
113 | $httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET ); |
---|
114 | $view = $httpvars->getHttpVar( "view" ); |
---|
115 | $host = $httpvars->getHttpVar( "host" ); |
---|
116 | $query = $httpvars->getHttpVar( "query" ); |
---|
117 | $clustername = $httpvars->getClusterName(); |
---|
118 | |
---|
119 | if( isset($jid) && ($jid!='')) $filter['jid']=$jid; |
---|
120 | if( isset($state) && ($state!='')) $filter['state']=$state; |
---|
121 | if( isset($owner) && ($owner!='')) $filter['owner']=$owner; |
---|
122 | if( isset($queue) && ($queue!='')) $filter['queue']=$queue; |
---|
123 | if( isset($host) && ($host!='')) $filter['host']=$host; |
---|
124 | if( isset($query) && ($query!='')) $filter['query']=$query; |
---|
125 | |
---|
126 | $data_gatherer = new DataGatherer( $clustername ); |
---|
127 | $data_gatherer->parseXML( &$myxml_data ); |
---|
128 | |
---|
129 | function drawHostImage() |
---|
130 | { |
---|
131 | global $clustername, $hostname, $data_gatherer; |
---|
132 | |
---|
133 | if( $data_gatherer->isJobmonRunning() ) |
---|
134 | { |
---|
135 | $ic = new HostImage( $data_gatherer, $clustername, $hostname ); |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | $ic = new EmptyImage(); |
---|
140 | } |
---|
141 | |
---|
142 | $ic->draw(); |
---|
143 | } |
---|
144 | |
---|
145 | function drawSmallClusterImage() |
---|
146 | { |
---|
147 | global $clustername, $data_gatherer, $myxml_data; |
---|
148 | |
---|
149 | if( $data_gatherer->isJobmonRunning() ) |
---|
150 | { |
---|
151 | $ic = new ClusterImage( $myxml_data, $clustername ); |
---|
152 | $ic->setSmall(); |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | $ic = new EmptyImage(); |
---|
157 | } |
---|
158 | |
---|
159 | $ic->draw(); |
---|
160 | } |
---|
161 | |
---|
162 | function drawBigClusterImage() |
---|
163 | { |
---|
164 | global $filter, $clustername, $myxml_data; |
---|
165 | |
---|
166 | $ic = new ClusterImage( $myxml_data, $clustername ); |
---|
167 | $ic->setBig(); |
---|
168 | |
---|
169 | if( isset( $filter ) ) |
---|
170 | { |
---|
171 | foreach( $filter as $filtername=>$filtervalue ) |
---|
172 | { |
---|
173 | $ic->setFilter( $filtername, $filtervalue ); |
---|
174 | } |
---|
175 | } |
---|
176 | $ic->draw(); |
---|
177 | } |
---|
178 | |
---|
179 | switch( $view ) |
---|
180 | { |
---|
181 | case "small-clusterimage": |
---|
182 | |
---|
183 | drawSmallClusterImage(); |
---|
184 | |
---|
185 | break; |
---|
186 | |
---|
187 | case "big-clusterimage": |
---|
188 | |
---|
189 | drawBigClusterImage(); |
---|
190 | |
---|
191 | break; |
---|
192 | |
---|
193 | case "hostimage": |
---|
194 | |
---|
195 | drawHostImage(); |
---|
196 | |
---|
197 | break; |
---|
198 | |
---|
199 | default: |
---|
200 | |
---|
201 | break; |
---|
202 | } |
---|
203 | |
---|
204 | ?> |
---|