diff --git a/addhost.php b/addhost.php index d61cccf3d..2c75d6573 100755 --- a/addhost.php +++ b/addhost.php @@ -28,7 +28,7 @@ if (isset($options['g']) && $options['g'] >= 0) { array_shift($argv); array_unshift($argv, $cmd); $poller_group = $options['g']; -} elseif ($config['distributed_poller_group'] > 0 && $config['distributed_poller'] === TRUE) { +} elseif ($config['distributed_poller'] === TRUE) { $poller_group = $config['distributed_poller_group']; } diff --git a/discovery.php b/discovery.php index e0e0a3b88..37f75db4a 100755 --- a/discovery.php +++ b/discovery.php @@ -99,7 +99,7 @@ include("includes/sql-schema/update.php"); $discovered_devices = 0; if ($config['distributed_poller'] === TRUE) { - $where .= " AND poller_group=?"; + $where .= " AND poller_group IN(?)"; $params = array($config['distributed_poller_group']); } foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC",$params) as $device) diff --git a/includes/functions.php b/includes/functions.php index 96d6a5227..b6583ab8a 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -530,14 +530,36 @@ function utime() return $sec + $usec; } +function getpollergroup($poller_group='0') +{ + //Is poller group an integer + if (is_int($poller_group) || ctype_digit($poller_group)) { + return $poller_group; + } else { + //Check if it contains a comma + if (strpos($poller_group,',')!== FALSE) { + //If it has a comma use the first element as the poller group + $poller_group=explode(',',$poller_group)[0]; + return getpollergroup($poller_group); + } else { + if ($config['distributed_poller_group']) { + //If not use the poller's group from the config + return getpollergroup($config['distributed_poller_group']); + } else { + //If all else fails use default + return '0'; + } + } + } +} + function createHost($host, $community = NULL, $snmpver, $port = 161, $transport = 'udp', $v3 = array(), $poller_group='0') { global $config; $host = trim(strtolower($host)); - if (is_numeric($poller_group) === FALSE) { - $poller_group = $config['distributed_poller_group']; - } + $poller_group=getpollergroup($poller_group); + $device = array('hostname' => $host, 'sysName' => $host, 'community' => $community, diff --git a/poller-wrapper.py b/poller-wrapper.py index be52f1bb7..02efa825d 100755 --- a/poller-wrapper.py +++ b/poller-wrapper.py @@ -195,7 +195,7 @@ except: """ # (c) 2015, GPLv3, Daniel Preussker <<