2008-03-12 17:12:17 +00:00
< ? php
2009-01-09 15:00:17 +00:00
echo ( " Physical Inventory : " );
2009-05-06 16:50:51 +00:00
unset ( $valid );
2009-01-09 15:00:17 +00:00
if ( $config [ 'enable_inventory' ]) {
2008-03-12 17:12:17 +00:00
2009-11-10 19:28:24 +00:00
$empty = array ();
2009-11-28 09:48:23 +00:00
$entity_array = snmpwalk_cache_oid ( " entPhysicalEntry " , $device , $empty , " ENTITY-MIB " );
2009-11-10 19:28:24 +00:00
$entity_array = snmpwalk_cache_oid ( " entSensorValues " , $device , $entity_array , " CISCO-ENTITY-SENSOR-MIB " );
2008-03-12 17:12:17 +00:00
2010-01-16 23:56:33 +00:00
if ( ! $entity_array [ $device [ 'device_id' ]]) { $entity_array [ $device [ 'device_id' ]] = array (); }
2009-11-28 09:48:23 +00:00
2010-01-16 23:56:33 +00:00
foreach ( $entity_array [ $device [ 'device_id' ]] as $entPhysicalIndex => $entry ) {
2008-03-12 17:12:17 +00:00
2009-11-10 19:28:24 +00:00
$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' ];
2009-11-28 09:48:23 +00:00
$entPhysicalHardwareRev = $entry [ 'entPhysicalHardwareRev' ];
$entPhysicalFirmwareRev = $entry [ 'entPhysicalFirmwareRev' ];
$entPhysicalSoftwareRev = $entry [ 'entPhysicalSoftwareRev' ];
$entPhysicalIsFRU = $entry [ 'entPhysicalIsFRU' ];
$entPhysicalAlias = $entry [ 'entPhysicalAlias' ];
$entPhysicalAssetID = $entry [ 'entPhysicalAssetID' ];
2009-11-10 19:28:24 +00:00
$ent_data = $config [ 'snmpget' ] . " -m ENTITY-MIB:IF-MIB -Ovqs - " ;
2009-02-02 16:00:11 +00:00
$ent_data .= $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ];
2008-03-12 17:12:17 +00:00
$ent_data .= " entAliasMappingIdentifier. " . $entPhysicalIndex . " .0 " ;
2009-11-10 19:28:24 +00:00
$ifIndex = shell_exec ( $ent_data );
2008-03-12 17:12:17 +00:00
2009-05-11 13:43:59 +00:00
if ( ! strpos ( $ifIndex , " fIndex " ) || $ifIndex == " " ) { unset ( $ifIndex ); }
list (, $ifIndex ) = explode ( " . " , $ifIndex );
2008-03-12 17:12:17 +00:00
2010-01-10 16:03:48 +00:00
if ( $entPhysicalVendorTypes [ $entPhysicalVendorType ] && ! $entPhysicalModelName )
{
2008-03-12 17:12:17 +00:00
$entPhysicalModelName = $entPhysicalVendorTypes [ $entPhysicalVendorType ];
}
2010-01-10 16:03:48 +00:00
if ( $entPhysicalDescr || $entPhysicalName )
{
$entPhysical_id = @ mysql_result ( mysql_query ( " SELECT entPhysical_id FROM `entPhysical` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND entPhysicalIndex = ' $entPhysicalIndex ' " ), 0 );
if ( $entPhysical_id ) {
$sql = " UPDATE `entPhysical` SET `ifIndex` = ' $ifIndex ' " ;
$sql .= " , entPhysicalIndex = ' $entPhysicalIndex ', entPhysicalDescr = ' $entPhysicalDescr ', entPhysicalClass = ' $entPhysicalClass ', entPhysicalName = ' $entPhysicalName ' " ;
$sql .= " , entPhysicalModelName = ' $entPhysicalModelName ', entPhysicalSerialNum = ' $entPhysicalSerialNum ', entPhysicalContainedIn = ' $entPhysicalContainedIn ' " ;
$sql .= " , entPhysicalMfgName = ' $entPhysicalMfgName ', entPhysicalParentRelPos = ' $entPhysicalParentRelPos ', entPhysicalVendorType = ' $entPhysicalVendorType ' " ;
$sql .= " , entPhysicalHardwareRev = ' $entPhysicalHardwareRev ', entPhysicalFirmwareRev = ' $entPhysicalFirmwareRev ', entPhysicalSoftwareRev = ' $entPhysicalSoftwareRev ' " ;
$sql .= " , entPhysicalIsFRU = ' $entPhysicalIsFRU ', entPhysicalAlias = ' $entPhysicalAlias ', entPhysicalAssetID = ' $entPhysicalAssetID ' " ;
$sql .= " WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND entPhysicalIndex = ' $entPhysicalIndex ' " ;
2009-05-11 13:43:59 +00:00
2010-01-10 16:03:48 +00:00
mysql_query ( $sql );
echo ( " . " );
} else {
$sql = " INSERT INTO `entPhysical` ( `device_id` , `entPhysicalIndex` , `entPhysicalDescr` , `entPhysicalClass` , `entPhysicalName` , `entPhysicalModelName` , `entPhysicalSerialNum` , `entPhysicalContainedIn`, `entPhysicalMfgName`, `entPhysicalParentRelPos`, `entPhysicalVendorType`, `entPhysicalHardwareRev`,`entPhysicalFirmwareRev`,`entPhysicalSoftwareRev`,`entPhysicalIsFRU`,`entPhysicalAlias`,`entPhysicalAssetID`, `ifIndex` ) " ;
$sql .= " VALUES ( ' " . $device [ 'device_id' ] . " ', ' $entPhysicalIndex ', ' $entPhysicalDescr ', ' $entPhysicalClass ', ' $entPhysicalName ', ' $entPhysicalModelName ', ' $entPhysicalSerialNum ', ' $entPhysicalContainedIn ', ' $entPhysicalMfgName ',' $entPhysicalParentRelPos ' , ' $entPhysicalVendorType ', ' $entPhysicalHardwareRev ', ' $entPhysicalFirmwareRev ', ' $entPhysicalSoftwareRev ', ' $entPhysicalIsFRU ', ' $entPhysicalAlias ', ' $entPhysicalAssetID ', ' $ifIndex ') " ;
mysql_query ( $sql );
echo ( " + " );
}
2009-11-10 19:28:24 +00:00
2010-01-10 16:03:48 +00:00
if ( $entPhysicalClass == " sensor " )
{
$entSensorType = $entry [ 'entSensorType' ];
$entSensorScale = $entry [ 'entSensorScale' ];
$entSensorPrecision = $entry [ 'entSensorPrecision' ];
$entSensorValueUpdateRate = $entry [ 'entSensorValueUpdateRate' ];
$entSensorMeasuredEntity = $entry [ 'entSensorMeasuredEntity' ];
2009-11-10 19:28:24 +00:00
2010-01-10 16:03:48 +00:00
if ( $config [ 'allow_entity_sensor' ][ $entSensorType ]) {
$sql = " UPDATE `entPhysical` SET entSensorType = ' $entSensorType ', entSensorScale = ' $entSensorScale ', entSensorPrecision = ' $entSensorPrecision ', " ;
$sql .= " entSensorMeasuredEntity = ' $entSensorMeasuredEntity ' " ;
$sql .= " WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND entPhysicalIndex = ' $entPhysicalIndex ' " ;
} else {
echo ( " ! " );
$sql = " UPDATE `entPhysical` SET entSensorType = '', entSensorScale = '', entSensorPrecision = '', entSensorMeasuredEntity = '' " ;
$sql .= " WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND entPhysicalIndex = ' $entPhysicalIndex ' " ;
}
mysql_query ( $sql );
2009-05-11 13:43:59 +00:00
}
2010-01-10 16:03:48 +00:00
$valid [ $entPhysicalIndex ] = 1 ;
2009-05-06 16:50:51 +00:00
}
2008-03-12 17:12:17 +00:00
}
2009-01-09 15:00:17 +00:00
} else { echo ( " Disabled! " ); }
2009-05-06 16:50:51 +00:00
$sql = " SELECT * FROM `entPhysical` WHERE `device_id` = ' " . $device [ 'device_id' ] . " ' " ;
$query = mysql_query ( $sql );
while ( $test = mysql_fetch_array ( $query )) {
2009-05-11 13:43:59 +00:00
$id = $test [ 'entPhysicalIndex' ];
2009-05-06 16:50:51 +00:00
if ( ! $valid [ $id ]) {
echo ( " - " );
2009-05-11 13:43:59 +00:00
mysql_query ( " DELETE FROM `entPhysical` WHERE entPhysical_id = ' " . $test [ 'entPhysical_id' ] . " ' " );
2009-05-06 16:50:51 +00:00
}
}
unset ( $valid );
2009-01-09 15:00:17 +00:00
echo ( " \n " );
2008-03-12 17:12:17 +00:00
?>