From a6ab74893a98af2f17616486d5e4f5b7ccfcca71 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Thu, 12 Apr 2007 00:07:25 +0000 Subject: [PATCH] Build a better vlan discoverer! git-svn-id: http://www.observium.org/svn/observer/trunk@93 61d68cd4-352d-0410-923a-c4978735b2b8 --- discover-vlans.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/discover-vlans.php b/discover-vlans.php index 3532a363f..63d8063ef 100644 --- a/discover-vlans.php +++ b/discover-vlans.php @@ -9,20 +9,29 @@ while ($device = mysql_fetch_array($device_query)) { echo("Discovering VLANs on " . $device['hostname'] . "\n"); - $vlans_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " "; - $vlans_cmd .= "1.3.6.1.4.1.9.9.46.1.3.1.1.2.1 | sed s/.1.3.6.1.4.1.9.9.46.1.3.1.1.2.1.//g | cut -f 1 -d\" \""; + $vtpversion_cmd = "snmpget -Oqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.9.9.46.1.1.1.0"; + $vtpversion = trim(`$vtpversion_cmd 2>/dev/null`); - $vlans = trim(`$vlans_cmd | grep -v o`); + if($vtpversion == '1' || $vtpversion == '2') { - foreach(explode("\n", $vlans) as $vlan) { + echo("VLAN Trunking Protocol Version $vtpversion\n"); - $vlan_descr_cmd = "snmpget -O nvq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " "; - $vlan_descr_cmd .= ".1.3.6.1.4.1.9.9.46.1.3.1.1.4.1." . $vlan; - $vlan_descr = `$vlan_descr_cmd`; + $vlans_cmd = "snmpwalk -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " "; + $vlans_cmd .= "1.3.6.1.4.1.9.9.46.1.3.1.1.2.1 | sed s/.1.3.6.1.4.1.9.9.46.1.3.1.1.2.1.//g | cut -f 1 -d\" \""; - $vlan_descr = trim(str_replace("\"", "", $vlan_descr)); + $vlans = trim(`$vlans_cmd | grep -v o`); - echo("VLAN $vlan ($vlan_descr)\n"); + foreach(explode("\n", $vlans) as $vlan) { + + $vlan_descr_cmd = "snmpget -O nvq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " "; + $vlan_descr_cmd .= ".1.3.6.1.4.1.9.9.46.1.3.1.1.4.1." . $vlan; + $vlan_descr = `$vlan_descr_cmd`; + + $vlan_descr = trim(str_replace("\"", "", $vlan_descr)); + + echo("VLAN $vlan ($vlan_descr)\n"); + + } }