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 --- index.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'index.php') 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