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 );
2011-03-15 11:39:50 +00:00
if ( $config [ 'enable_inventory' ]) {
2008-03-12 17:12:17 +00:00
2010-08-11 17:08:56 +00:00
echo ( " \n Caching OIDs: " );
$entity_array = array ();
echo ( " entPhysicalEntry " );
$entity_array = snmpwalk_cache_oid ( $device , " entPhysicalEntry " , $entity_array , " ENTITY-MIB " );
echo ( " entAliasMappingIdentifier " );
$entity_array = snmpwalk_cache_twopart_oid ( $device , " entAliasMappingIdentifier " , $entity_array , " ENTITY-MIB:IF-MIB " );
2009-11-28 09:48:23 +00:00
2011-03-15 11:39:50 +00:00
foreach ( $entity_array 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' ];
2011-03-15 11:39:50 +00:00
if ( isset ( $entity_array [ '$entPhysicalIndex' ][ '0' ][ 'entAliasMappingIdentifier' ])) { $ifIndex = $entity_array [ '$entPhysicalIndex' ][ '0' ][ 'entAliasMappingIdentifier' ]; }
2009-11-10 19:28:24 +00:00
2010-08-11 17:08:56 +00:00
# $ent_data = $config['snmpget'] . " -M ".$config['mibdir']." -m ENTITY-MIB:IF-MIB -Ovqs -";
# $ent_data .= $device['snmpver'] . " -M ".$config['mibdir']." -c " . $device['community'] . " " . $device['hostname'] .":".$device['port'];
# $ent_data .= " entAliasMappingIdentifier." . $entPhysicalIndex. ".0";
# $ifIndex = shell_exec($ent_data);
2008-03-12 17:12:17 +00:00
2011-03-15 11:39:50 +00:00
if ( ! strpos ( $ifIndex , " fIndex " ) || $ifIndex == " " ) { unset ( $ifIndex ); }
2009-05-11 13:43:59 +00:00
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 );
2011-03-15 11:39:50 +00:00
if ( $entPhysical_id ) {
2010-01-10 16:03:48 +00:00
$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
$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' ];
2011-03-15 11:39:50 +00:00
if ( ! $valid [ $id ]) {
2009-05-06 16:50:51 +00:00
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
?>