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
|
* 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
|
* @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)) {
|
||||||
if (empty($ret)) {
|
$ret = static::where('hostname', $device)->first(['hostname', 'overwrite_ip']);
|
||||||
return $hostname;
|
if (empty($ret)) {
|
||||||
|
return $device;
|
||||||
|
}
|
||||||
|
$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'];
|
||||||
}
|
}
|
||||||
$_overwrite_ip = $ret->overwrite_ip;
|
return $overwrite_ip ?: $hostname;
|
||||||
$_hostname = $ret->hostname;
|
|
||||||
|
|
||||||
return $_overwrite_ip ?: $_hostname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function findByIp($ip)
|
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);
|
array_push($cmd, '-r', $retries);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pollertarget = Device::pollerTarget($device['hostname']);
|
$pollertarget = Device::pollerTarget($device);
|
||||||
$cmd[] = $device['transport'].':'.$pollertarget.':'.$device['port'];
|
$cmd[] = $device['transport'].':'.$pollertarget.':'.$device['port'];
|
||||||
$cmd = array_merge($cmd, (array)$oids);
|
$cmd = array_merge($cmd, (array)$oids);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user