From 26cd32c6deb372dc25e3c010b65d9697962edf16 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Wed, 26 Aug 2015 12:29:30 +0200 Subject: Support for host categories bases on regular expression matching against host names --- conf/config.php | 3 +++ index.php | 23 +++++++++++++++++++++-- 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(); # category of hosts to show on main page #$CONFIG['cat']['category1'] = array('host1', 'host2'); +# category of hosts based on regular expression +#$CONFIG['cat']['Mailservers'] = '/mail\d+/'; + # default plugins to show on host page $CONFIG['overview'] = array('load', 'cpu', 'memory', 'swap'); diff --git a/index.php b/index.php index 94ecf80..9069152 100644 --- a/index.php +++ b/index.php @@ -11,11 +11,30 @@ $h = array(); # show all categorized hosts if (isset($CONFIG['cat']) && is_array($CONFIG['cat'])) { foreach($CONFIG['cat'] as $cat => $hosts) { - host_summary($cat, $hosts); - $h = array_merge($h, $hosts); + + if(is_array($hosts)) { + host_summary($cat, $hosts); + $h = array_merge($h, $hosts); + } else { + // Asume regexp + $regexp = $hosts; + $ahosts = collectd_hosts(); + $rhosts = array(); + + foreach($ahosts as $host) { + if(preg_match($regexp, $host)) { + array_push($rhosts, $host); + } + } + + host_summary($cat, $rhosts); + $h = array_merge($h, $rhosts); + } + } } + # search for uncategorized hosts if(!$chosts = collectd_hosts()) printf('

Error: No Collectd hosts found in %s

', $CONFIG['datadir']); -- cgit v1.1