mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
enclose IPv6 literal in [brackets] for snmpget and unix-agent (#13130)
Co-authored-by: Kevin Wallace <kevinwallace@users.noreply.github.com>
This commit is contained in:
@@ -447,4 +447,14 @@ class Rewrite
|
||||
{
|
||||
return str_pad($num, $length, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* If given input is an IPv6 address, wrap it in [] for use in applications that require it
|
||||
* @param string $ip
|
||||
* @return string
|
||||
*/
|
||||
public static function addIpv6Brackets($ip): string
|
||||
{
|
||||
return IPv6::isValid($ip) ? "[$ip]" : $ip;
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ if ($device['os_group'] == 'unix' || $device['os'] == 'windows') {
|
||||
}
|
||||
|
||||
$agent_start = microtime(true);
|
||||
$poller_target = Device::pollerTarget($device['hostname']);
|
||||
$poller_target = \LibreNMS\Util\Rewrite::addIpv6Brackets(Device::pollerTarget($device['hostname']));
|
||||
$agent = fsockopen($poller_target, $agent_port, $errno, $errstr, \LibreNMS\Config::get('unix-agent.connection-timeout'));
|
||||
|
||||
if (! $agent) {
|
||||
|
@@ -176,7 +176,7 @@ function gen_snmp_cmd($cmd, $device, $oids, $options = null, $mib = null, $mibdi
|
||||
array_push($cmd, '-r', $retries);
|
||||
}
|
||||
|
||||
$pollertarget = Device::pollerTarget($device);
|
||||
$pollertarget = \LibreNMS\Util\Rewrite::addIpv6Brackets(Device::pollerTarget($device));
|
||||
$cmd[] = $device['transport'] . ':' . $pollertarget . ':' . $device['port'];
|
||||
$cmd = array_merge($cmd, (array) $oids);
|
||||
|
||||
|
Reference in New Issue
Block a user