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:
Kevin Wallace
2021-08-19 16:00:06 -07:00
committed by GitHub
parent 3c6f9fd60f
commit e981570c34
3 changed files with 12 additions and 2 deletions

View File

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

View File

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

View File

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