mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
ipv6-mib support
git-svn-id: http://www.observium.org/svn/observer/trunk@583 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -73,12 +73,9 @@
|
||||
$peers = trim(str_replace(".1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.","", `$peers_cmd`));
|
||||
foreach (explode("\n", $peers) as $peer) {
|
||||
list($peer_ip_snmp, $peer_as) = split(" ", $peer);
|
||||
$peer_ip_ex = explode('.',$peer_ip_snmp);
|
||||
$peer_ip_ex = array_slice($peer_ip_ex,count($peer_ip_ex)-16);
|
||||
for ($i = 0;$i <= 15;$i++) { $peer_ip_ex[$i] = dechex($peer_ip_ex[$i]); if (strlen($peer_ip_ex[$i]) < 2) $peer_ip_ex[$i] = '0' . $peer_ip_ex[$i]; }
|
||||
for ($i = 0;$i <= 15;$i+=2) { $peer_ip_ex2[] = $peer_ip_ex[$i] . $peer_ip_ex[$i+1]; }
|
||||
$peer_ip = implode(':',$peer_ip_ex2); unset($peer_ip_ex2);
|
||||
$peer_ip = Net_IPv6::compress($peer_ip);
|
||||
|
||||
# Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs.
|
||||
$peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.',array_slice(explode('.',$peer_ip_snmp),count($ipv6)-16))));
|
||||
|
||||
if($peer) {
|
||||
|
||||
|
||||
@@ -1,9 +1,40 @@
|
||||
<?php
|
||||
|
||||
echo("IPv6 Addresses : ");
|
||||
function discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_origin)
|
||||
{
|
||||
global $valid_v6,$device;
|
||||
|
||||
#$ipv6interfaces = shell_exec($config['snmpget']." -m IPV6-MIB -Ovnq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." ipv6Interfaces.0");
|
||||
#if($ipv6interfaces){
|
||||
$ipv6_network = trim(shell_exec($config['sipcalc']." $ipv6_address/$ipv6_prefixlen | grep Subnet | cut -f 2 -d '-'"));
|
||||
$ipv6_compressed = trim(shell_exec($config['sipcalc']." $ipv6_address/$ipv6_prefixlen | grep Compressed | cut -f 2 -d '-'"));
|
||||
|
||||
if (mysql_result(mysql_query("SELECT count(*) FROM `interfaces`
|
||||
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 `interfaces` 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;
|
||||
}
|
||||
}
|
||||
|
||||
echo("IPv6 Addresses : ");
|
||||
|
||||
$cmd = $config['snmpwalk']." -m IP-MIB -".$device['snmpver']." -Ln -c ".$device['community']." ".$device['hostname'].":".$device['port'];
|
||||
$cmd .= " ipAddressIfIndex.ipv6 -Osq | grep -v No";
|
||||
@@ -28,36 +59,29 @@ echo("IPv6 Addresses : ");
|
||||
$ipv6_prefixlen = trim(shell_exec($config['snmpget']." -m IP-MIB -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." .1.3.6.1.2.1.4.34.1.5.2.16.$oid | sed 's/.*\.//'"));
|
||||
$ipv6_origin = trim(shell_exec($config['snmpget']." -m IP-MIB -Ovq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." .1.3.6.1.2.1.4.34.1.6.2.16.$oid"));
|
||||
|
||||
$ipv6_network = trim(shell_exec($config['sipcalc']." $ipv6_address/$ipv6_prefixlen | grep Subnet | cut -f 2 -d '-'"));
|
||||
$ipv6_compressed = trim(shell_exec($config['sipcalc']." $ipv6_address/$ipv6_prefixlen | grep Compressed | cut -f 2 -d '-'"));
|
||||
discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_origin);
|
||||
} # if $data
|
||||
} # foreach
|
||||
|
||||
if (mysql_result(mysql_query("SELECT count(*) FROM `interfaces`
|
||||
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 `interfaces` 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 (!$oids)
|
||||
{
|
||||
$cmd = $config['snmpwalk']." -m IPV6-MIB -".$device['snmpver']." -Ln -c ".$device['community']." ".$device['hostname'].":".$device['port'];
|
||||
$cmd .= " ipv6AddrPfxLength -Osq -OnU| grep -v No";
|
||||
$oids = trim(trim(shell_exec($cmd)));
|
||||
$oids = str_replace(".1.3.6.1.2.1.55.1.8.1.2.", "", $oids); $oids = str_replace("\"", "", $oids); $oids = trim($oids);
|
||||
foreach(explode("\n", $oids) as $data) {
|
||||
if($data) {
|
||||
$data = trim($data);
|
||||
list($if_ipv6addr,$ipv6_prefixlen) = explode(" ", $data);
|
||||
list($ifindex,$ipv6addr) = split("\\.",$if_ipv6addr,2);
|
||||
$ipv6_address = snmp2ipv6($ipv6addr);
|
||||
|
||||
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);
|
||||
$ipv6_origin = trim(shell_exec($config['snmpget']." -m IPV6-MIB -Ovq -".$device['snmpver']." -c ".$device['community']." ".$device['hostname'].":".$device['port']." IPV6-MIB::ipv6AddrType.$if_ipv6addr"));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
#} else { echo("None configured"); }
|
||||
discover_process_ipv6($ifIndex,$ipv6_address,$ipv6_prefixlen,$ipv6_origin);
|
||||
} # if $data
|
||||
} # foreach
|
||||
} # if $oids
|
||||
|
||||
$sql = "SELECT * FROM ipv6_addresses AS A, interfaces AS I WHERE I.device_id = '".$device['device_id']."' AND A.interface_id = I.interface_id";
|
||||
$data = mysql_query($sql);
|
||||
|
||||
@@ -673,4 +673,21 @@ function match_network ($nets, $ip, $first=false) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
function snmp2ipv6($ipv6_snmp)
|
||||
{
|
||||
$ipv6 = explode('.',$ipv6_snmp);
|
||||
for ($i = 0;$i <= 15;$i++) { $ipv6[$i] = zeropad(dechex($ipv6[$i])); }
|
||||
for ($i = 0;$i <= 15;$i+=2) { $ipv6_2[] = $ipv6[$i] . $ipv6[$i+1]; }
|
||||
return implode(':',$ipv6_2);
|
||||
}
|
||||
|
||||
function ipv62snmp($ipv6)
|
||||
{
|
||||
$ipv6_ex = explode(':',Net_IPv6::uncompress($ipv6));
|
||||
for ($i = 0;$i < 8;$i++) { while (strlen($ipv6_ex[$i]) < 4) $ipv6_ex[$i] = "0" . $ipv6_ex[$i]; } # Pad zeroes back
|
||||
$ipv6_ip = implode('',$ipv6_ex);
|
||||
for ($i = 0;$i < 16;$i+=2) $ipv6_split[] = hexdec(substr($ipv6_ip,$i,2));
|
||||
return implode($ipv6_split,'.');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -26,11 +26,7 @@ else
|
||||
if ($device['os'] == "junos")
|
||||
{
|
||||
# v6 for JunOS via Juniper MIB
|
||||
$peer_ip_ex = explode(':',Net_IPv6::uncompress($peer['bgpPeerIdentifier']));
|
||||
for ($i = 0;$i < 8;$i++) { while (strlen($peer_ip_ex[$i]) < 4) $peer_ip_ex[$i] = "0" . $peer_ip_ex[$i]; } # Pad zeroes back
|
||||
$peer_ip = implode('',$peer_ip_ex);
|
||||
for ($i = 0;$i < 16;$i+=2) $peer_ip_split[] = hexdec(substr($peer_ip,$i,2));
|
||||
$peer_ip = implode($peer_ip_split,'.'); unset($peer_ip_split); # Now in JunOS SNMP format
|
||||
$peer_ip = ipv62snmp($peer['bgpPeerIdentifier']);
|
||||
|
||||
if (!isset($junos_v6))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user