mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
fix ipv6-addresses discovery
git-svn-id: http://www.observium.org/svn/observer/trunk@2235 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -155,6 +155,7 @@ function discover_device($device, $options)
|
||||
{
|
||||
|
||||
global $config;
|
||||
global $valid; $valid = array(); ## Reset $valid array
|
||||
|
||||
$device_start = utime(); // Start counting device poll time
|
||||
|
||||
@@ -175,6 +176,8 @@ function discover_device($device, $options)
|
||||
|
||||
#include("includes/discovery/os.inc.php");
|
||||
|
||||
### If we've specified a module, use that, else walk the modules array
|
||||
|
||||
if ($options['m'])
|
||||
{
|
||||
if (is_file("includes/discovery/".$options['m'].".inc.php"))
|
||||
@@ -182,7 +185,6 @@ function discover_device($device, $options)
|
||||
include("includes/discovery/".$options['m'].".inc.php");
|
||||
}
|
||||
} else {
|
||||
|
||||
foreach($config['discovery_modules'] as $module => $module_status)
|
||||
{
|
||||
if($module_status || $device_attribs['discovery_module'][$module])
|
||||
@@ -190,8 +192,10 @@ function discover_device($device, $options)
|
||||
include('includes/discovery/'.$module.'.inc.php');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
### Set type to a predefined type for the OS if it's not already set
|
||||
|
||||
if ($device['type'] == "unknown" || $device['type'] == "")
|
||||
{
|
||||
if ($config['os'][$device['os']]['type'])
|
||||
|
@@ -328,4 +328,52 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity
|
||||
$valid[$type][$index] = 1;
|
||||
}
|
||||
|
||||
function discover_process_ipv6(&$valid, $ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_origin)
|
||||
{
|
||||
global $device,$config;
|
||||
|
||||
$ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen") . '/' . $ipv6_prefixlen;
|
||||
$ipv6_compressed = Net_IPv6::compress($ipv6_address);
|
||||
|
||||
if (Net_IPv6::getAddressType($ipv6_address) == NET_IPV6_LOCAL_LINK)
|
||||
{
|
||||
# ignore link-locals (coming from IPV6-MIB)
|
||||
return;
|
||||
}
|
||||
|
||||
if (mysql_result(mysql_query("SELECT count(*) FROM `ports`
|
||||
WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1')
|
||||
{
|
||||
$i_query = "SELECT interface_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'";
|
||||
$interface_id = mysql_result(mysql_query($i_query), 0);
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')");
|
||||
echo("N");
|
||||
}
|
||||
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')");
|
||||
echo("N");
|
||||
}
|
||||
|
||||
$ipv6_network_id = @mysql_result(mysql_query("SELECT `ipv6_network_id` from `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0);
|
||||
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `interface_id` = '$interface_id'"), 0) == '0')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `interface_id`)
|
||||
VALUES ('$ipv6_address', '$ipv6_compressed', '$ipv6_prefixlen', '$ipv6_origin', '$ipv6_network_id', '$interface_id')");
|
||||
echo("+");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
$full_address = "$ipv6_address/$ipv6_prefixlen";
|
||||
$valid_address = $full_address . "-" . $interface_id;
|
||||
$valid['ipv6'][$valid_address] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -2,8 +2,6 @@
|
||||
|
||||
echo("IPv6 Addresses : ");
|
||||
|
||||
global $valid_v6;
|
||||
|
||||
$oids = snmp_walk($device, "ipAddressIfIndex.ipv6", "-Ln -Osq", "IP-MIB");
|
||||
$oids = str_replace("ipAddressIfIndex.ipv6.", "", $oids);
|
||||
$oids = str_replace("\"", "", $oids);
|
||||
@@ -36,7 +34,7 @@ foreach (explode("\n", $oids) as $data)
|
||||
|
||||
$ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", "-Ovq", "IP-MIB");
|
||||
|
||||
discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_origin);
|
||||
discover_process_ipv6($valid, $ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_origin);
|
||||
} // if $data
|
||||
} // foreach
|
||||
|
||||
@@ -55,7 +53,7 @@ if (!$oids)
|
||||
list($ifIndex,$ipv6addr) = explode(".",$if_ipv6addr,2);
|
||||
$ipv6_address = snmp2ipv6($ipv6addr);
|
||||
$ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", "-Ovq", "IPV6-MIB");
|
||||
discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_origin);
|
||||
discover_process_ipv6($valid, $ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_origin);
|
||||
} // if $data
|
||||
} // foreach
|
||||
} // if $oids
|
||||
@@ -67,8 +65,8 @@ while ($row = mysql_fetch_assoc($data))
|
||||
{
|
||||
$full_address = $row['ipv6_address'] . "/" . $row['ipv6_prefixlen'];
|
||||
$interface_id = $row['interface_id'];
|
||||
$valid = $full_address . "-" . $interface_id;
|
||||
if (!$valid_v6[$valid])
|
||||
$valid_address = $full_address . "-" . $interface_id;
|
||||
if (!$valid['ipv6'][$valid_address])
|
||||
{
|
||||
echo("-");
|
||||
$query = @mysql_query("DELETE FROM `ipv6_addresses` WHERE `ipv6_address_id` = '".$row['ipv6_address_id']."'");
|
||||
@@ -79,8 +77,6 @@ while ($row = mysql_fetch_assoc($data))
|
||||
}
|
||||
}
|
||||
|
||||
unset($valid_v6);
|
||||
|
||||
echo("\n");
|
||||
|
||||
?>
|
||||
|
@@ -458,54 +458,6 @@ function ipv62snmp($ipv6)
|
||||
return implode('.',$ipv6_split);
|
||||
}
|
||||
|
||||
function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_origin)
|
||||
{
|
||||
global $valid_v6,$device,$config;
|
||||
|
||||
$ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen") . '/' . $ipv6_prefixlen;
|
||||
$ipv6_compressed = Net_IPv6::compress($ipv6_address);
|
||||
|
||||
if (Net_IPv6::getAddressType($ipv6_address) == NET_IPV6_LOCAL_LINK)
|
||||
{
|
||||
# ignore link-locals (coming from IPV6-MIB)
|
||||
return;
|
||||
}
|
||||
|
||||
if (mysql_result(mysql_query("SELECT count(*) FROM `ports`
|
||||
WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'"), 0) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1')
|
||||
{
|
||||
$i_query = "SELECT interface_id FROM `ports` WHERE device_id = '".$device['device_id']."' AND `ifIndex` = '$ifIndex'";
|
||||
$interface_id = mysql_result(mysql_query($i_query), 0);
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')");
|
||||
echo("N");
|
||||
}
|
||||
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0) < '1')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv6_networks` (`ipv6_network`) VALUES ('$ipv6_network')");
|
||||
echo("N");
|
||||
}
|
||||
|
||||
$ipv6_network_id = @mysql_result(mysql_query("SELECT `ipv6_network_id` from `ipv6_networks` WHERE `ipv6_network` = '$ipv6_network'"), 0);
|
||||
|
||||
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = '$ipv6_address' AND `ipv6_prefixlen` = '$ipv6_prefixlen' AND `interface_id` = '$interface_id'"), 0) == '0')
|
||||
{
|
||||
mysql_query("INSERT INTO `ipv6_addresses` (`ipv6_address`, `ipv6_compressed`, `ipv6_prefixlen`, `ipv6_origin`, `ipv6_network_id`, `interface_id`)
|
||||
VALUES ('$ipv6_address', '$ipv6_compressed', '$ipv6_prefixlen', '$ipv6_origin', '$ipv6_network_id', '$interface_id')");
|
||||
echo("+");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
$full_address = "$ipv6_address/$ipv6_prefixlen";
|
||||
$valid = $full_address . "-" . $interface_id;
|
||||
$valid_v6[$valid] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
function get_astext($asn)
|
||||
{
|
||||
global $config,$cache;
|
||||
@@ -647,7 +599,7 @@ function isHexString($str)
|
||||
# Include all .inc.php files in $dir
|
||||
function include_dir($dir, $regex = "")
|
||||
{
|
||||
global $device, $config, $debug;
|
||||
global $device, $config, $debug, $valid;
|
||||
if ($regex == "")
|
||||
{
|
||||
$regex = "/\.inc\.php$/";
|
||||
|
Reference in New Issue
Block a user