Skip to content

Commit

Permalink
Support for host categories bases on regular expression matching agai…
Browse files Browse the repository at this point in the history
…nst host names
  • Loading branch information
mnellemann committed Aug 26, 2015
1 parent cf12c83 commit 26cd32c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions conf/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# 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');

Expand Down
23 changes: 21 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,30 @@
# 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('<p class="warn">Error: No Collectd hosts found in <em>%s</em></p>', $CONFIG['datadir']);
Expand Down

0 comments on commit 26cd32c

Please sign in to comment.