Merge pull request #2088 from paszczus/discovery_linux_only

- add option to (re)discovery only linux devices (inspired by _Robsan_ from IRC)
This commit is contained in:
Daniel Preussker
2015-10-09 17:59:59 +00:00

View File

@@ -22,8 +22,8 @@ require 'includes/discovery/functions.inc.php';
$start = utime();
$runtime_stats = array();
$options = getopt('h:m:i:n:d::a::q');
$sqlparams = array();
$options = getopt('h:m:i:n:d::a::q',array('os:','type:'));
if (!isset($options['q'])) {
echo $config['project_name_version']." Discovery\n";
@@ -59,8 +59,18 @@ if (isset($options['h'])) {
}//end if
}//end if
if (isset($options['os'])) {
$where .= " AND os = ?";
$sqlparams[] = $options['os'];
}
if (isset($options['type'])) {
$where .= " AND type = ?";
$sqlparams[] = $options['type'];
}
if (isset($options['i']) && $options['i'] && isset($options['n'])) {
$where = 'AND MOD(device_id,'.$options['i'].") = '".$options['n']."'";
$where .= ' AND MOD(device_id,'.$options['i'].") = '".$options['n']."'";
$doing = $options['n'].'/'.$options['i'];
}
@@ -85,9 +95,11 @@ if (!$where) {
echo "-h odd Poll odd numbered devices (same as -i 2 -n 0)\n";
echo "-h even Poll even numbered devices (same as -i 2 -n 1)\n";
echo "-h all Poll all devices\n";
echo "-h new Poll all devices that have not had a discovery run before\n\n";
echo "-h new Poll all devices that have not had a discovery run before\n";
echo "--os <os_name> Poll devices only with specified operating system\n";
echo "--type <type> Poll devices only with specified type\n";
echo "-i <instances> -n <number> Poll as instance <number> of <instances>\n";
echo " Instances start at 0. 0-3 for -n 4\n\n";
echo " Instances start at 0. 0-3 for -n 4\n";
echo "\n";
echo "Debugging and testing options:\n";
echo "-d Enable debugging output\n";
@@ -105,7 +117,7 @@ if ($config['distributed_poller'] === true) {
$where .= ' AND poller_group IN('.$config['distributed_poller_group'].')';
}
foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC") as $device) {
foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC",$sqlparams) as $device) {
discover_device($device, $options);
}