Reduce DB polling while getting SNMP data (#11162)

This commit is contained in:
SourceDoctor
2020-02-18 13:26:41 +01:00
committed by GitHub
parent 3838d8e41f
commit c8bdd10e6a
2 changed files with 17 additions and 10 deletions

View File

@@ -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)

View File

@@ -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);