aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMark Nellemann2015-08-26 12:29:30 +0200
committerMark Nellemann2015-08-26 12:29:30 +0200
commit26cd32c6deb372dc25e3c010b65d9697962edf16 (patch)
tree2ab8aba3d1e1091932ac2f6393968c7fb2efd0a8
parentinc/functions: a host, pi and ti may contain colons (:) and spaces ( ) (diff)
downloadapt-panopticon_cgp-26cd32c6deb372dc25e3c010b65d9697962edf16.zip
apt-panopticon_cgp-26cd32c6deb372dc25e3c010b65d9697962edf16.tar.gz
apt-panopticon_cgp-26cd32c6deb372dc25e3c010b65d9697962edf16.tar.bz2
apt-panopticon_cgp-26cd32c6deb372dc25e3c010b65d9697962edf16.tar.xz
Support for host categories bases on regular expression matching against host names
-rw-r--r--conf/config.php3
-rw-r--r--index.php23
2 files changed, 24 insertions, 2 deletions
diff --git a/conf/config.php b/conf/config.php
index ec55d30..0628bfe 100644
--- a/conf/config.php
+++ b/conf/config.php
@@ -18,6 +18,9 @@ $CONFIG['rrdtool_opts'] = array();
18# category of hosts to show on main page 18# category of hosts to show on main page
19#$CONFIG['cat']['category1'] = array('host1', 'host2'); 19#$CONFIG['cat']['category1'] = array('host1', 'host2');
20 20
21# category of hosts based on regular expression
22#$CONFIG['cat']['Mailservers'] = '/mail\d+/';
23
21# default plugins to show on host page 24# default plugins to show on host page
22$CONFIG['overview'] = array('load', 'cpu', 'memory', 'swap'); 25$CONFIG['overview'] = array('load', 'cpu', 'memory', 'swap');
23 26
diff --git a/index.php b/index.php
index 94ecf80..9069152 100644
--- a/index.php
+++ b/index.php
@@ -11,11 +11,30 @@ $h = array();
11# show all categorized hosts 11# show all categorized hosts
12if (isset($CONFIG['cat']) && is_array($CONFIG['cat'])) { 12if (isset($CONFIG['cat']) && is_array($CONFIG['cat'])) {
13 foreach($CONFIG['cat'] as $cat => $hosts) { 13 foreach($CONFIG['cat'] as $cat => $hosts) {
14 host_summary($cat, $hosts); 14
15 $h = array_merge($h, $hosts); 15 if(is_array($hosts)) {
16 host_summary($cat, $hosts);
17 $h = array_merge($h, $hosts);
18 } else {
19 // Asume regexp
20 $regexp = $hosts;
21 $ahosts = collectd_hosts();
22 $rhosts = array();
23
24 foreach($ahosts as $host) {
25 if(preg_match($regexp, $host)) {
26 array_push($rhosts, $host);
27 }
28 }
29
30 host_summary($cat, $rhosts);
31 $h = array_merge($h, $rhosts);
32 }
33
16 } 34 }
17} 35}
18 36
37
19# search for uncategorized hosts 38# search for uncategorized hosts
20if(!$chosts = collectd_hosts()) 39if(!$chosts = collectd_hosts())
21 printf('<p class="warn">Error: No Collectd hosts found in <em>%s</em></p>', $CONFIG['datadir']); 40 printf('<p class="warn">Error: No Collectd hosts found in <em>%s</em></p>', $CONFIG['datadir']);