mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
refactor: discovery code cleanups (#6856)
* Use foreach $key => value * use get_port_by_ifIndex get rid of the rest of the array_keys() * improve hex_to_ip() function, add tests, use in more places * Simplify can_skip_discovery logic
This commit is contained in:
committed by
Neil Lathwood
parent
03a273f722
commit
90aa485149
@@ -1357,22 +1357,33 @@ function first_oid_match($device, $list)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a hex ip to a human readable string
|
||||
*
|
||||
* @param string $hex
|
||||
* @return string
|
||||
*/
|
||||
function hex_to_ip($hex)
|
||||
{
|
||||
$return = "";
|
||||
if (filter_var($hex, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false && filter_var($hex, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
|
||||
$hex_exp = explode(' ', $hex);
|
||||
foreach ($hex_exp as $item) {
|
||||
if (!empty($item) && $item != "\"") {
|
||||
$return .= hexdec($item).'.';
|
||||
}
|
||||
}
|
||||
$return = substr($return, 0, -1);
|
||||
} else {
|
||||
$return = $hex;
|
||||
$hex = str_replace(array(' ', '"'), '', $hex);
|
||||
|
||||
if (filter_var($hex, FILTER_VALIDATE_IP)) {
|
||||
return $hex;
|
||||
}
|
||||
return $return;
|
||||
|
||||
if (strlen($hex) == 8) {
|
||||
return long2ip(hexdec($hex));
|
||||
}
|
||||
|
||||
if (strlen($hex) == 32) {
|
||||
$ipv6 = implode(':', str_split($hex, 4));
|
||||
return preg_replace('/:0*([0-9a-fA-F])/', ':$1', $ipv6);
|
||||
}
|
||||
|
||||
return ''; // invalid input
|
||||
}
|
||||
|
||||
function fix_integer_value($value)
|
||||
{
|
||||
if ($value < 0) {
|
||||
|
||||
Reference in New Issue
Block a user