diff --git a/discover-cdp.php b/discover-cdp.php index 20f526f75d..81ca9381e1 100755 --- a/discover-cdp.php +++ b/discover-cdp.php @@ -1,24 +1,6 @@ #!/usr/bin/php $dst_if_id REMOVED \n"); - } else { -# echo("$src_if_id -> $dst_if_id VALID \n"); - } -} - ?> diff --git a/discovery.php b/discovery.php index f13ac5773b..8ddcddbacb 100755 --- a/discovery.php +++ b/discovery.php @@ -3,6 +3,7 @@ include("config.php"); include("includes/functions.php"); +include("includes/functions-poller.inc.php"); $start = utime(); @@ -80,6 +81,7 @@ while ($device = mysql_fetch_array($device_query)) { include("includes/discovery/cisco-processors.php"); include("includes/discovery/cemp-mib.php"); include("includes/discovery/cmp-mib.php"); + include("includes/discovery/cisco-cdp.inc.php"); } echo("\n"); $devices_discovered++; diff --git a/includes/discovery/cisco-physical.php b/includes/discovery/cisco-physical.php index a7ba299caa..6aa3c84910 100755 --- a/includes/discovery/cisco-physical.php +++ b/includes/discovery/cisco-physical.php @@ -6,36 +6,33 @@ if($config['enable_inventory']) { - $ents_cmd = $config['snmpbulkwalk'] . " -m ENTITY-MIB -O qn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['$port'] . " "; - $ents_cmd .= "1.3.6.1.2.1.47.1.1.1.1.2 | sed s/.1.3.6.1.2.1.47.1.1.1.1.2.//g | grep -v OID | cut -f 1 -d\" \""; + $empty = array(); + $entity_array = snmpwalk_cache_oid("entityPhysical", $device, $empty, "ENTITY-MIB"); + $entity_array = snmpwalk_cache_oid("entSensorValues", $device, $entity_array, "CISCO-ENTITY-SENSOR-MIB"); - $ents = trim(`$ents_cmd | grep -v o`); + print_r($entity_array); - foreach(explode("\n", $ents) as $entPhysicalIndex) { + foreach($entity_array[$device[device_id]] as $entPhysicalIndex => $entry) { - $ent_data = $config['snmpget'] . " -m ENTITY-MIB:IF-MIB -Ovqs -"; + $entPhysicalDescr = $entry['entPhysicalDescr']; + $entPhysicalContainedIn = $entry['entPhysicalContainedIn']; + $entPhysicalClass = $entry['entPhysicalClass']; + $entPhysicalName = $entry['entPhysicalName']; + $entPhysicalSerialNum = $entry['entPhysicalSerialNum']; + $entPhysicalModelName = $entry['entPhysicalModelName']; + $entPhysicalMfgName = $entry['entPhysicalMfgName']; + $entPhysicalVendorType = $entry['entPhysicalVendorType']; + $entPhysicalParentRelPos = $entry['entPhysicalParentRelPos']; + + $ent_data = $config['snmpget'] . " -m ENTITY-MIB:IF-MIB -Ovqs -"; $ent_data .= $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] .":".$device['port']; - $ent_data .= " entPhysicalDescr." . $entPhysicalIndex; - $ent_data .= " entPhysicalContainedIn." . $entPhysicalIndex; - $ent_data .= " entPhysicalClass." . $entPhysicalIndex; - $ent_data .= " entPhysicalName." . $entPhysicalIndex; - $ent_data .= " entPhysicalSerialNum." . $entPhysicalIndex; - $ent_data .= " entPhysicalModelName." . $entPhysicalIndex; - $ent_data .= " entPhysicalMfgName." . $entPhysicalIndex; - $ent_data .= " entPhysicalVendorType." . $entPhysicalIndex; - $ent_data .= " entPhysicalParentRelPos." . $entPhysicalIndex; $ent_data .= " entAliasMappingIdentifier." . $entPhysicalIndex. ".0"; - list($entPhysicalDescr,$entPhysicalContainedIn,$entPhysicalClass,$entPhysicalName,$entPhysicalSerialNum,$entPhysicalModelName,$entPhysicalMfgName,$entPhysicalVendorType,$entPhysicalParentRelPos, $ifIndex) = explode("\n", `$ent_data`); + $ifIndex = shell_exec($ent_data); if(!strpos($ifIndex, "fIndex") || $ifIndex == "") { unset($ifIndex); } list(,$ifIndex) = explode(".", $ifIndex); - $entPhysicalModelName = trim($entPhysicalModelName); - $entPhysicalSerialNum = trim($entPhysicalSerialNum); - $entPhysicalMfgName = trim($entPhysicalMfgName); - $entPhysicalVendorType = trim($entPhysicalVendorType); - if ($entPhysicalVendorTypes[$entPhysicalVendorType] && !$entPhysicalModelName) { $entPhysicalModelName = $entPhysicalVendorTypes[$entPhysicalVendorType]; } @@ -59,14 +56,20 @@ } if($entPhysicalClass == "sensor") { - $sensor_cmd = $config['snmpget'] . " -m CISCO-ENTITY-SENSOR-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; - $sensor_cmd .= " entSensorType.$entPhysicalIndex entSensorScale.$entPhysicalIndex entSensorPrecision.$entPhysicalIndex"; - $sensor_cmd .= " entSensorValueUpdateRate.$entPhysicalIndex entSensorMeasuredEntity.$entPhysicalIndex"; - $sensor_data = shell_exec($sensor_cmd); - list($entSensorType,$entSensorScale,$entSensorPrecision,$entSensorValueUpdateRate,$entSensorMeasuredEntity) = explode("\n", $sensor_data); - if($entSensorMeasuredEntity) { - #echo("M:$entSensorMeasuredEntity"); - } + +# $sensor_cmd = $config['snmpget'] . " -m CISCO-ENTITY-SENSOR-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port']; +# $sensor_cmd .= " entSensorType.$entPhysicalIndex entSensorScale.$entPhysicalIndex entSensorPrecision.$entPhysicalIndex"; +# $sensor_cmd .= " entSensorValueUpdateRate.$entPhysicalIndex entSensorMeasuredEntity.$entPhysicalIndex"; +# $sensor_data = shell_exec($sensor_cmd); +# list($entSensorType,$entSensorScale,$entSensorPrecision,$entSensorValueUpdateRate,$entSensorMeasuredEntity) = explode("\n", $sensor_data); + + $entSensorType = $entry['entSensorType']; + $entSensorScale = $entry['entSensorScale']; + $entSensorPrecision = $entry['entSensorPrecision']; + $entSensorValueUpdateRate = $entry['entSensorValueUpdateRate']; + $entSensorMeasuredEntity = $entry['entSensorMeasuredEntity']; + + if($config['allow_entity_sensor'][$entSensorType]) { $sql = "UPDATE `entPhysical` SET entSensorType = '$entSensorType', entSensorScale = '$entSensorScale', entSensorPrecision = '$entSensorPrecision', "; $sql .= " entSensorMeasuredEntity = '$entSensorMeasuredEntity'"; @@ -76,7 +79,7 @@ $sql = "UPDATE `entPhysical` SET entSensorType = '', entSensorScale = '', entSensorPrecision = '', entSensorMeasuredEntity = ''"; $sql .= " WHERE device_id = '".$device['device_id']."' AND entPhysicalIndex = '$entPhysicalIndex'"; } - + echo("$sql\n"); mysql_query($sql); } $valid[$entPhysicalIndex] = 1; diff --git a/includes/functions-poller.inc.php b/includes/functions-poller.inc.php index eb3ee4260d..8a99ec2b0e 100644 --- a/includes/functions-poller.inc.php +++ b/includes/functions-poller.inc.php @@ -50,6 +50,25 @@ global $config; return $array; } +function snmpwalk_cache_oid($oid, $device, $array, $mib = 0) { + global $config; + $cmd = $config['snmpbulkwalk'] . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " " . + $device['hostname'].":".$device['port'] . " "; + if($mib) { $cmd .= "-m $mib "; } + $cmd .= $oid; + $data = trim(shell_exec($cmd)); + $device_id = $device['device_id']; + foreach(explode("\n", $data) as $entry) { + list($oid,$value) = explode("=", $entry); + $oid = trim($oid); $value = trim($value); + list($oid, $index) = explode(".", $oid); + if (!strstr($this_value, "No Such Instance currently exists at this OID") && $oid && $index) { + $array[$device_id][$index][$oid] = $value; + } + } + return $array; +} + function snmpwalk_cache_twopart_oid($oid, $device, $array, $mib = 0) { global $config; $cmd = $config['snmpbulkwalk'] . " -O Qs -" . $device['snmpver'] . " -c " . $device['community'] . " " .