From 4fac761f987e81e82ef19b29dad42d14cc73a2b7 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Mon, 11 Apr 2011 18:54:15 +0000 Subject: [PATCH] improvements to vrf discovery from falz git-svn-id: http://www.observium.org/svn/observer/trunk@2059 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/includes/print-menubar.php | 2 +- includes/defaults.inc.php | 1 + includes/discovery/cisco-vrf.inc.php | 167 ++++++++++++++------------- 3 files changed, 87 insertions(+), 83 deletions(-) diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 0105bb86ec..2062fd620e 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -153,7 +153,7 @@ if ($config['enable_billing']) { echo('
  • Pseudowires
  • '); $ifbreak = 1; } -if ($config['enable_pseudowires']) { echo('
  • VRFs
  • '); $ifbreak = 1; } +if ($config['enable_vrfs']) { echo('
  • VRFs
  • '); $ifbreak = 1; } ?>
  • IPv4 Search
  • diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index c51ea97d50..d30bbc5188 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -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 diff --git a/includes/discovery/cisco-vrf.inc.php b/includes/discovery/cisco-vrf.inc.php index 17c1c234cf..f05d0d375b 100755 --- a/includes/discovery/cisco-vrf.inc.php +++ b/includes/discovery/cisco-vrf.inc.php @@ -1,104 +1,107 @@ $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 - -?> \ No newline at end of file +?>