From d91e5d3cd62e599b24e13b41a6bb54a2b4afd095 Mon Sep 17 00:00:00 2001
From: Pim van den Berg
Date: Sat, 3 May 2014 10:14:49 +0200
Subject: inc: mv graphs_from_plugin, build_url functions to html.inc.php
They generate html.
---
inc/collectd.inc.php | 69 ----------------------------------------------------
inc/html.inc.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++-
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) {
return $data;
}
-# generate graph url's for a plugin of a host
-function graphs_from_plugin($host, $plugin, $overview=false) {
- global $CONFIG;
-
- if (!$plugindata = collectd_plugindata($host, $plugin))
- return false;
- if (!$plugindata = group_plugindata($plugindata))
- return false;
- if (!$plugindata = plugin_sort($plugindata))
- return false;
-
- foreach ($plugindata as $items) {
-
- if (
- $overview && isset($CONFIG['overview_filter'][$plugin]) &&
- $CONFIG['overview_filter'][$plugin] !== array_intersect_assoc($CONFIG['overview_filter'][$plugin], $items)
- ) {
- continue;
- }
-
- $items['h'] = $host;
-
- $time = array_key_exists($plugin, $CONFIG['time_range'])
- ? $CONFIG['time_range'][$plugin]
- : $CONFIG['time_range']['default'];
-
- if ($CONFIG['graph_type'] == 'canvas') {
- chdir($CONFIG['webdir']);
- isset($items['p']) ? $_GET['p'] = $items['p'] : $_GET['p'] = '';
- isset($items['pi']) ? $_GET['pi'] = $items['pi'] : $_GET['pi'] = '';
- isset($items['t']) ? $_GET['t'] = $items['t'] : $_GET['t'] = '';
- isset($items['ti']) ? $_GET['ti'] = $items['ti'] : $_GET['ti'] = '';
- include $CONFIG['webdir'].'/plugin/'.$plugin.'.php';
- } else {
- printf(''."\n",
- $CONFIG['weburl'],
- build_url('detail.php', $items, $time),
- $CONFIG['weburl'],
- build_url('graph.php', $items, $time)
- );
- }
- }
-}
-
-# generate an url with GET values from $items
-function build_url($base, $items, $s=NULL) {
- global $CONFIG;
-
- if (!is_array($items))
- return false;
-
- if (!is_numeric($s))
- $s = $CONFIG['time_range']['default'];
-
- $i=0;
- foreach ($items as $key => $value) {
- # don't include empty values
- if ($value == 'NULL')
- continue;
-
- $base .= sprintf('%s%s=%s', $i==0 ? '?' : '&', $key, $value);
- $i++;
- }
- if (!isset($items['s']))
- $base .= '&s='.$s;
-
- return $base;
-}
-
function socket_cmd($socket, $cmd) {
$r = fwrite($socket, $cmd, strlen($cmd));
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() {
return $path;
}
-?>
+# generate graph url's for a plugin of a host
+function graphs_from_plugin($host, $plugin, $overview=false) {
+ global $CONFIG;
+
+ if (!$plugindata = collectd_plugindata($host, $plugin))
+ return false;
+ if (!$plugindata = group_plugindata($plugindata))
+ return false;
+ if (!$plugindata = plugin_sort($plugindata))
+ return false;
+
+ foreach ($plugindata as $items) {
+
+ if (
+ $overview && isset($CONFIG['overview_filter'][$plugin]) &&
+ $CONFIG['overview_filter'][$plugin] !== array_intersect_assoc($CONFIG['overview_filter'][$plugin], $items)
+ ) {
+ continue;
+ }
+
+ $items['h'] = $host;
+
+ $time = array_key_exists($plugin, $CONFIG['time_range'])
+ ? $CONFIG['time_range'][$plugin]
+ : $CONFIG['time_range']['default'];
+
+ if ($CONFIG['graph_type'] == 'canvas') {
+ chdir($CONFIG['webdir']);
+ isset($items['p']) ? $_GET['p'] = $items['p'] : $_GET['p'] = '';
+ isset($items['pi']) ? $_GET['pi'] = $items['pi'] : $_GET['pi'] = '';
+ isset($items['t']) ? $_GET['t'] = $items['t'] : $_GET['t'] = '';
+ isset($items['ti']) ? $_GET['ti'] = $items['ti'] : $_GET['ti'] = '';
+ include $CONFIG['webdir'].'/plugin/'.$plugin.'.php';
+ } else {
+ printf(''."\n",
+ $CONFIG['weburl'],
+ build_url('detail.php', $items, $time),
+ $CONFIG['weburl'],
+ build_url('graph.php', $items, $time)
+ );
+ }
+ }
+}
+
+# generate an url with GET values from $items
+function build_url($base, $items, $s=NULL) {
+ global $CONFIG;
+
+ if (!is_array($items))
+ return false;
+
+ if (!is_numeric($s))
+ $s = $CONFIG['time_range']['default'];
+
+ $i=0;
+ foreach ($items as $key => $value) {
+ # don't include empty values
+ if ($value == 'NULL')
+ continue;
+
+ $base .= sprintf('%s%s=%s', $i==0 ? '?' : '&', $key, $value);
+ $i++;
+ }
+ if (!isset($items['s']))
+ $base .= '&s='.$s;
+
+ return $base;
+}
--
cgit v1.1