mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
improvements to vrf discovery from falz
git-svn-id: http://www.observium.org/svn/observer/trunk@2059 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@ -153,7 +153,7 @@ if ($config['enable_billing']) { echo('<li><a href="bills/"><img src="images/16/
|
||||
|
||||
if ($config['enable_pseudowires']) { echo('<li><a href="pseudowires/"><img src="images/16/arrow_switch.png" border="0" align="absmiddle" /> Pseudowires</a></li>'); $ifbreak = 1; }
|
||||
|
||||
if ($config['enable_pseudowires']) { echo('<li><a href="vrfs/"><img src="images/16/layers.png" border="0" align="absmiddle" /> VRFs</a></li>'); $ifbreak = 1; }
|
||||
if ($config['enable_vrfs']) { echo('<li><a href="vrfs/"><img src="images/16/layers.png" border="0" align="absmiddle" /> VRFs</a></li>'); $ifbreak = 1; }
|
||||
|
||||
?>
|
||||
<li><a href="ipv4/"><img src="images/16/email_link.png" border="0" align="absmiddle" /> IPv4 Search</a></li>
|
||||
|
@ -128,6 +128,7 @@ $config['enable_bgp'] = 1; # Enable BGP session collection and displa
|
||||
$config['enable_syslog'] = 0; # Enable Syslog
|
||||
$config['enable_inventory'] = 1; # Enable Inventory
|
||||
$config['enable_pseudowires'] = 1; # Enable Pseudowires
|
||||
$config['enable_vrfs'] = 1; # Enable VRFs
|
||||
$config['enable_printers'] = 0; # Enable Printer support
|
||||
$config['enable_libvirt'] = 0; # Enable Libvirt VM support
|
||||
|
||||
|
@ -1,104 +1,107 @@
|
||||
<?php
|
||||
|
||||
if ($device['os_group'] == "ios" || $device['os_group'] == "junos" || $device['os'] == "ironware")
|
||||
if ($config['enable_vrfs'])
|
||||
{
|
||||
unset($vrf_count);
|
||||
|
||||
echo("VRFs : ");
|
||||
|
||||
$oid_cmd = $config['snmpwalk'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfRouteDistinguisher";
|
||||
$oids = shell_exec($oid_cmd);
|
||||
|
||||
if ($debug) { echo("$oid_cmd -> $oids \n"); }
|
||||
|
||||
$oids = str_replace(".1.3.6.1.3.118.1.2.2.1.3.", "", $oids);
|
||||
$oids = str_replace(" \"", "||", $oids);
|
||||
$oids = str_replace("\"", "", $oids);
|
||||
|
||||
$oids = trim($oids);
|
||||
foreach (explode("\n", $oids) as $oid)
|
||||
if ($device['os_group'] == "ios" || $device['os_group'] == "junos" || $device['os'] == "ironware")
|
||||
{
|
||||
if ($oid)
|
||||
{
|
||||
list($vrf['oid'], $vrf['mplsVpnVrfRouteDistinguisher']) = explode("||", $oid);
|
||||
$vrf['name'] = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -Ln -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfRouteDistinguisher.".$vrf['oid']));
|
||||
list(,$vrf['name'],, $vrf['mplsVpnVrfRouteDistinguisher']) = explode("\"", $vrf['name']);
|
||||
$vrf['mplsVpnVrfDescription'] = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -Ln -Osqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfDescription.".$vrf['oid']));
|
||||
unset($vrf_count);
|
||||
|
||||
if (@mysql_result(mysql_query("SELECT count(*) FROM vrfs WHERE `device_id` = '".$device['device_id']."'
|
||||
echo("VRFs : ");
|
||||
|
||||
$oid_cmd = $config['snmpwalk'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfRouteDistinguisher";
|
||||
$oids = shell_exec($oid_cmd);
|
||||
|
||||
if ($debug) { echo("$oid_cmd -> $oids \n"); }
|
||||
|
||||
$oids = str_replace(".1.3.6.1.3.118.1.2.2.1.3.", "", $oids);
|
||||
$oids = str_replace(" \"", "||", $oids);
|
||||
$oids = str_replace("\"", "", $oids);
|
||||
|
||||
$oids = trim($oids);
|
||||
foreach (explode("\n", $oids) as $oid)
|
||||
{
|
||||
if ($oid)
|
||||
{
|
||||
list($vrf['oid'], $vrf['mplsVpnVrfRouteDistinguisher']) = explode("||", $oid);
|
||||
$vrf['name'] = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -Ln -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfRouteDistinguisher.".$vrf['oid']));
|
||||
list(,$vrf['name'],, $vrf['mplsVpnVrfRouteDistinguisher']) = explode("\"", $vrf['name']);
|
||||
$vrf['mplsVpnVrfDescription'] = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -Ln -Osqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " mplsVpnVrfDescription.".$vrf['oid']));
|
||||
|
||||
if (@mysql_result(mysql_query("SELECT count(*) FROM vrfs WHERE `device_id` = '".$device['device_id']."'
|
||||
AND `vrf_oid`='".$vrf['oid']."'"),0))
|
||||
{
|
||||
$update_query = "UPDATE `vrfs` SET `mplsVpnVrfDescription` = '".$vrf['mplsVpnVrfDescription']."', `mplsVpnVrfRouteDistinguisher` = '".$vrf['mplsVpnVrfRouteDistinguisher']."' ";
|
||||
$update_query .= "WHERE device_id = '".$device['device_id']."' AND vrf_oid = '".$vrf['oid']."'";
|
||||
mysql_query($update_query);
|
||||
}
|
||||
else
|
||||
{
|
||||
$insert_query = "INSERT INTO `vrfs` (`vrf_oid`,`vrf_name`,`mplsVpnVrfRouteDistinguisher`,`mplsVpnVrfDescription`,`device_id`) ";
|
||||
$insert_query .= "VALUES ('".$vrf['oid']."','".$vrf['name']."','".$vrf['mplsVpnVrfRouteDistinguisher']."','".$vrf['mplsVpnVrfDescription']."','".$device['device_id']."')";
|
||||
mysql_query($insert_query);
|
||||
}
|
||||
{
|
||||
$update_query = "UPDATE `vrfs` SET `mplsVpnVrfDescription` = '".$vrf['mplsVpnVrfDescription']."', `mplsVpnVrfRouteDistinguisher` = '".$vrf['mplsVpnVrfRouteDistinguisher']."' ";
|
||||
$update_query .= "WHERE device_id = '".$device['device_id']."' AND vrf_oid = '".$vrf['oid']."'";
|
||||
mysql_query($update_query);
|
||||
}
|
||||
else
|
||||
{
|
||||
$insert_query = "INSERT INTO `vrfs` (`vrf_oid`,`vrf_name`,`mplsVpnVrfRouteDistinguisher`,`mplsVpnVrfDescription`,`device_id`) ";
|
||||
$insert_query .= "VALUES ('".$vrf['oid']."','".$vrf['name']."','".$vrf['mplsVpnVrfRouteDistinguisher']."','".$vrf['mplsVpnVrfDescription']."','".$device['device_id']."')";
|
||||
mysql_query($insert_query);
|
||||
}
|
||||
|
||||
$vrf_id = @mysql_result(mysql_query("SELECT vrf_id FROM vrfs WHERE `device_id` = '".$device['device_id']."' AND `vrf_oid`='".$vrf['oid']."'"),0);
|
||||
$valid_vrf[$vrf_id] = 1;
|
||||
echo("\nRD:".$vrf['mplsVpnVrfRouteDistinguisher']." ".$vrf['name']." ".$vrf['mplsVpnVrfDescription']." ");
|
||||
$ports_oid = ".1.3.6.1.3.118.1.2.1.1.2." . $vrf['oid'];
|
||||
$ports = shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " $ports_oid");
|
||||
$ports = trim(str_replace($ports_oid . ".", "", $ports));
|
||||
# list($ports) = explode(" ", $ports);
|
||||
echo(" ( ");
|
||||
foreach (explode("\n", $ports) as $if_id)
|
||||
{
|
||||
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM ports WHERE ifIndex = '$if_id' AND device_id = '" . $device['device_id'] . "'"));
|
||||
echo(makeshortif($interface['ifDescr']) . " ");
|
||||
mysql_query("UPDATE ports SET ifVrf = '".$vrf_id."' WHERE interface_id = '".$interface['interface_id']."'");
|
||||
$if = $interface['interface_id'];
|
||||
$valid_vrf_if[$vrf_id][$if] = 1;
|
||||
$vrf_id = @mysql_result(mysql_query("SELECT vrf_id FROM vrfs WHERE `device_id` = '".$device['device_id']."' AND `vrf_oid`='".$vrf['oid']."'"),0);
|
||||
$valid_vrf[$vrf_id] = 1;
|
||||
echo("\nRD:".$vrf['mplsVpnVrfRouteDistinguisher']." ".$vrf['name']." ".$vrf['mplsVpnVrfDescription']." ");
|
||||
$ports_oid = ".1.3.6.1.3.118.1.2.1.1.2." . $vrf['oid'];
|
||||
$ports = shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m MPLS-VPN-MIB -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " $ports_oid");
|
||||
$ports = trim(str_replace($ports_oid . ".", "", $ports));
|
||||
# list($ports) = explode(" ", $ports);
|
||||
echo(" ( ");
|
||||
foreach (explode("\n", $ports) as $if_id)
|
||||
{
|
||||
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM ports WHERE ifIndex = '$if_id' AND device_id = '" . $device['device_id'] . "'"));
|
||||
echo(makeshortif($interface['ifDescr']) . " ");
|
||||
mysql_query("UPDATE ports SET ifVrf = '".$vrf_id."' WHERE interface_id = '".$interface['interface_id']."'");
|
||||
$if = $interface['interface_id'];
|
||||
$valid_vrf_if[$vrf_id][$if] = 1;
|
||||
}
|
||||
echo(") ");
|
||||
}
|
||||
echo(") ");
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM ports WHERE device_id = '" . $device['device_id'] . "'";
|
||||
$data = mysql_query($sql);
|
||||
while ($row = mysql_fetch_assoc($data))
|
||||
{
|
||||
$if = $row['interface_id'];
|
||||
$vrf_id = $row['ifVrf'];
|
||||
if ($row['ifVrf'])
|
||||
$sql = "SELECT * FROM ports WHERE device_id = '" . $device['device_id'] . "'";
|
||||
$data = mysql_query($sql);
|
||||
while ($row = mysql_fetch_assoc($data))
|
||||
{
|
||||
if (!$valid_vrf_if[$vrf_id][$if])
|
||||
$if = $row['interface_id'];
|
||||
$vrf_id = $row['ifVrf'];
|
||||
if ($row['ifVrf'])
|
||||
{
|
||||
if (!$valid_vrf_if[$vrf_id][$if])
|
||||
{
|
||||
echo("-");
|
||||
$query = @mysql_query("UPDATE ports SET `ifVrf` = NULL WHERE interface_id = '$if'");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM vrfs WHERE device_id = '" . $device['device_id'] . "'";
|
||||
$data = mysql_query($sql);
|
||||
while ($row = mysql_fetch_assoc($data))
|
||||
{
|
||||
$vrf_id = $row['vrf_id'];
|
||||
if (!$valid_vrf[$vrf_id])
|
||||
{
|
||||
echo("-");
|
||||
$query = @mysql_query("UPDATE ports SET `ifVrf` = NULL WHERE interface_id = '$if'");
|
||||
$query = @mysql_query("DELETE FROM vrfs WHERE vrf_id = '$vrf_id'");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM vrfs WHERE device_id = '" . $device['device_id'] . "'";
|
||||
$data = mysql_query($sql);
|
||||
while ($row = mysql_fetch_assoc($data))
|
||||
{
|
||||
$vrf_id = $row['vrf_id'];
|
||||
if (!$valid_vrf[$vrf_id])
|
||||
{
|
||||
echo("-");
|
||||
$query = @mysql_query("DELETE FROM vrfs WHERE vrf_id = '$vrf_id'");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
}
|
||||
unset($valid_vrf_if);
|
||||
unset($valid_vrf);
|
||||
|
||||
unset($valid_vrf_if);
|
||||
unset($valid_vrf);
|
||||
echo("\n");
|
||||
} # ios/junos/ironware
|
||||
} # enable_vrfs
|
||||
|
||||
echo("\n");
|
||||
} # ios/junos/ironware
|
||||
|
||||
?>
|
||||
?>
|
||||
|
Reference in New Issue
Block a user