aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc
diff options
context:
space:
mode:
authorPim van den Berg2014-05-03 10:14:49 +0200
committerPim van den Berg2014-05-03 10:14:49 +0200
commitd91e5d3cd62e599b24e13b41a6bb54a2b4afd095 (patch)
tree57df5872a872be89ca1c96427e583eeb4d70521d /inc
parentinc/collectd: consistently return false instead of an empty array or false (diff)
downloadapt-panopticon_cgp-d91e5d3cd62e599b24e13b41a6bb54a2b4afd095.zip
apt-panopticon_cgp-d91e5d3cd62e599b24e13b41a6bb54a2b4afd095.tar.gz
apt-panopticon_cgp-d91e5d3cd62e599b24e13b41a6bb54a2b4afd095.tar.bz2
apt-panopticon_cgp-d91e5d3cd62e599b24e13b41a6bb54a2b4afd095.tar.xz
inc: mv graphs_from_plugin, build_url functions to html.inc.php
They generate html.
Diffstat (limited to 'inc')
-rw-r--r--inc/collectd.inc.php69
-rw-r--r--inc/html.inc.php69
2 files changed, 68 insertions, 70 deletions
diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php
index 5927bf6..74595aa 100644
--- a/inc/collectd.inc.php
+++ b/inc/collectd.inc.php
@@ -168,75 +168,6 @@ function plugin_sort($data) {
168 return $data; 168 return $data;
169} 169}
170 170
171# generate graph url's for a plugin of a host
172function graphs_from_plugin($host, $plugin, $overview=false) {
173 global $CONFIG;
174
175 if (!$plugindata = collectd_plugindata($host, $plugin))
176 return false;
177 if (!$plugindata = group_plugindata($plugindata))
178 return false;
179 if (!$plugindata = plugin_sort($plugindata))
180 return false;
181
182 foreach ($plugindata as $items) {
183
184 if (
185 $overview && isset($CONFIG['overview_filter'][$plugin]) &&
186 $CONFIG['overview_filter'][$plugin] !== array_intersect_assoc($CONFIG['overview_filter'][$plugin], $items)
187 ) {
188 continue;
189 }
190
191 $items['h'] = $host;
192
193 $time = array_key_exists($plugin, $CONFIG['time_range'])
194 ? $CONFIG['time_range'][$plugin]
195 : $CONFIG['time_range']['default'];
196
197 if ($CONFIG['graph_type'] == 'canvas') {
198 chdir($CONFIG['webdir']);
199 isset($items['p']) ? $_GET['p'] = $items['p'] : $_GET['p'] = '';
200 isset($items['pi']) ? $_GET['pi'] = $items['pi'] : $_GET['pi'] = '';
201 isset($items['t']) ? $_GET['t'] = $items['t'] : $_GET['t'] = '';
202 isset($items['ti']) ? $_GET['ti'] = $items['ti'] : $_GET['ti'] = '';
203 include $CONFIG['webdir'].'/plugin/'.$plugin.'.php';
204 } else {
205 printf('<a href="%s%s"><img src="%s%s"></a>'."\n",
206 $CONFIG['weburl'],
207 build_url('detail.php', $items, $time),
208 $CONFIG['weburl'],
209 build_url('graph.php', $items, $time)
210 );
211 }
212 }
213}
214
215# generate an url with GET values from $items
216function build_url($base, $items, $s=NULL) {
217 global $CONFIG;
218
219 if (!is_array($items))
220 return false;
221
222 if (!is_numeric($s))
223 $s = $CONFIG['time_range']['default'];
224
225 $i=0;
226 foreach ($items as $key => $value) {
227 # don't include empty values
228 if ($value == 'NULL')
229 continue;
230
231 $base .= sprintf('%s%s=%s', $i==0 ? '?' : '&amp;', $key, $value);
232 $i++;
233 }
234 if (!isset($items['s']))
235 $base .= '&amp;s='.$s;
236
237 return $base;
238}
239
240function socket_cmd($socket, $cmd) { 171function socket_cmd($socket, $cmd) {
241 $r = fwrite($socket, $cmd, strlen($cmd)); 172 $r = fwrite($socket, $cmd, strlen($cmd));
242 if ($r === false || $r != strlen($cmd)) { 173 if ($r === false || $r != strlen($cmd)) {
diff --git a/inc/html.inc.php b/inc/html.inc.php
index 01e7328..2bcbc3f 100644
--- a/inc/html.inc.php
+++ b/inc/html.inc.php
@@ -269,4 +269,71 @@ function breadcrumbs() {
269 return $path; 269 return $path;
270} 270}
271 271
272?> 272# generate graph url's for a plugin of a host
273function graphs_from_plugin($host, $plugin, $overview=false) {
274 global $CONFIG;
275
276 if (!$plugindata = collectd_plugindata($host, $plugin))
277 return false;
278 if (!$plugindata = group_plugindata($plugindata))
279 return false;
280 if (!$plugindata = plugin_sort($plugindata))
281 return false;
282
283 foreach ($plugindata as $items) {
284
285 if (
286 $overview && isset($CONFIG['overview_filter'][$plugin]) &&
287 $CONFIG['overview_filter'][$plugin] !== array_intersect_assoc($CONFIG['overview_filter'][$plugin], $items)
288 ) {
289 continue;
290 }
291
292 $items['h'] = $host;
293
294 $time = array_key_exists($plugin, $CONFIG['time_range'])
295 ? $CONFIG['time_range'][$plugin]
296 : $CONFIG['time_range']['default'];
297
298 if ($CONFIG['graph_type'] == 'canvas') {
299 chdir($CONFIG['webdir']);
300 isset($items['p']) ? $_GET['p'] = $items['p'] : $_GET['p'] = '';
301 isset($items['pi']) ? $_GET['pi'] = $items['pi'] : $_GET['pi'] = '';
302 isset($items['t']) ? $_GET['t'] = $items['t'] : $_GET['t'] = '';
303 isset($items['ti']) ? $_GET['ti'] = $items['ti'] : $_GET['ti'] = '';
304 include $CONFIG['webdir'].'/plugin/'.$plugin.'.php';
305 } else {
306 printf('<a href="%s%s"><img src="%s%s"></a>'."\n",
307 $CONFIG['weburl'],
308 build_url('detail.php', $items, $time),
309 $CONFIG['weburl'],
310 build_url('graph.php', $items, $time)
311 );
312 }
313 }
314}
315
316# generate an url with GET values from $items
317function build_url($base, $items, $s=NULL) {
318 global $CONFIG;
319
320 if (!is_array($items))
321 return false;
322
323 if (!is_numeric($s))
324 $s = $CONFIG['time_range']['default'];
325
326 $i=0;
327 foreach ($items as $key => $value) {
328 # don't include empty values
329 if ($value == 'NULL')
330 continue;
331
332 $base .= sprintf('%s%s=%s', $i==0 ? '?' : '&amp;', $key, $value);
333 $i++;
334 }
335 if (!isset($items['s']))
336 $base .= '&amp;s='.$s;
337
338 return $base;
339}