mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Reduce DB polling while getting SNMP data (#11162)
This commit is contained in:
@@ -106,19 +106,26 @@ class Device extends BaseModel
|
||||
/**
|
||||
* Returns IP/Hostname where polling will be targeted to
|
||||
*
|
||||
* @param string $hostname hostname which will be triggered
|
||||
* @param string $device hostname which will be triggered
|
||||
* array $device associative array with device data
|
||||
* @return string IP/Hostname to which Device polling is targeted
|
||||
*/
|
||||
public static function pollerTarget($hostname)
|
||||
public static function pollerTarget($device)
|
||||
{
|
||||
$ret = static::where('hostname', $hostname)->first(['hostname', 'overwrite_ip']);
|
||||
if (! is_array($device)) {
|
||||
$ret = static::where('hostname', $device)->first(['hostname', 'overwrite_ip']);
|
||||
if (empty($ret)) {
|
||||
return $hostname;
|
||||
return $device;
|
||||
}
|
||||
$_overwrite_ip = $ret->overwrite_ip;
|
||||
$_hostname = $ret->hostname;
|
||||
|
||||
return $_overwrite_ip ?: $_hostname;
|
||||
$overwrite_ip = $ret->overwrite_ip;
|
||||
$hostname = $ret->hostname;
|
||||
} elseif (array_key_exists('overwrite_ip', $device)) {
|
||||
$overwrite_ip = $device['overwrite_ip'];
|
||||
$hostname = $device['hostname'];
|
||||
} else {
|
||||
return $device['hostname'];
|
||||
}
|
||||
return $overwrite_ip ?: $hostname;
|
||||
}
|
||||
|
||||
public static function findByIp($ip)
|
||||
|
||||
@@ -172,7 +172,7 @@ function gen_snmp_cmd($cmd, $device, $oids, $options = null, $mib = null, $mibdi
|
||||
array_push($cmd, '-r', $retries);
|
||||
}
|
||||
|
||||
$pollertarget = Device::pollerTarget($device['hostname']);
|
||||
$pollertarget = Device::pollerTarget($device);
|
||||
$cmd[] = $device['transport'].':'.$pollertarget.':'.$device['port'];
|
||||
$cmd = array_merge($cmd, (array)$oids);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user