2008-03-12 17:12:17 +00:00
< ? php
2015-04-17 14:59:47 -04:00
if ( $config [ 'enable_inventory' ]) {
2015-07-13 20:10:26 +02:00
echo 'Physical Inventory : ' ;
2009-11-10 19:28:24 +00:00
2015-07-13 20:10:26 +02:00
echo " \n Caching OIDs: " ;
2008-03-12 17:12:17 +00:00
2015-04-17 14:59:47 -04:00
if ( $device [ 'os' ] == 'junos' ) {
$entity_array = array ();
2015-07-13 20:10:26 +02:00
echo ' jnxBoxAnatomy' ;
$entity_array = snmpwalk_cache_oid ( $device , 'jnxBoxAnatomy' , $entity_array , 'JUNIPER-MIB' );
}
2016-05-18 16:40:10 -04:00
elseif ( $device [ 'os' ] == 'timos' ) {
2016-05-24 13:52:04 -04:00
$entity_array = array ();
2016-05-18 16:40:10 -04:00
echo 'tmnxHwObjs' ;
$entity_array = snmpwalk_cache_multi_oid ( $device , 'tmnxHwObjs' , $entity_array , 'TIMETRA-CHASSIS-MIB' , '+' . $config [ 'mib_dir' ] . '/aos:' . $config [ 'mib_dir' ]);
}
2015-07-13 20:10:26 +02:00
else {
2015-04-17 14:59:47 -04:00
$entity_array = array ();
2015-07-13 20:10:26 +02:00
echo ' entPhysicalEntry' ;
$entity_array = snmpwalk_cache_oid ( $device , 'entPhysicalEntry' , $entity_array , 'ENTITY-MIB:CISCO-ENTITY-VENDORTYPE-OID-MIB' );
echo ' entAliasMappingIdentifier' ;
$entity_array = snmpwalk_cache_twopart_oid ( $device , 'entAliasMappingIdentifier' , $entity_array , 'ENTITY-MIB:IF-MIB' );
2009-05-06 16:50:51 +00:00
}
2008-03-12 17:12:17 +00:00
2015-07-13 20:10:26 +02:00
foreach ( $entity_array as $entPhysicalIndex => $entry ) {
if ( $device [ 'os' ] == 'junos' ) {
// Juniper's MIB doesn't have the same objects as the Entity MIB, so some values
// are made up here.
$entPhysicalDescr = $entry [ 'jnxContentsDescr' ];
$entPhysicalContainedIn = $entry [ 'jnxContainersWithin' ];
$entPhysicalClass = $entry [ 'jnxBoxClass' ];
$entPhysicalName = $entry [ 'jnxOperatingDescr' ];
$entPhysicalSerialNum = $entry [ 'jnxContentsSerialNo' ];
$entPhysicalModelName = $entry [ 'jnxContentsPartNo' ];
$entPhysicalMfgName = 'Juniper' ;
$entPhysicalVendorType = 'Juniper' ;
$entPhysicalParentRelPos = - 1 ;
$entPhysicalHardwareRev = $entry [ 'jnxContentsRevision' ];
$entPhysicalFirmwareRev = $entry [ 'entPhysicalFirmwareRev' ];
$entPhysicalSoftwareRev = $entry [ 'entPhysicalSoftwareRev' ];
$entPhysicalIsFRU = $entry [ 'jnxFruType' ];
$entPhysicalAlias = $entry [ 'entPhysicalAlias' ];
$entPhysicalAssetID = $entry [ 'entPhysicalAssetID' ];
2015-11-20 10:47:47 +00:00
// fix for issue 1865, $entPhysicalIndex, as it contains a quad dotted number on newer Junipers
// using str_replace to remove all dots should fix this even if it changes in future
2016-05-24 13:52:04 -04:00
$entPhysicalIndex = str_replace ( '.' , '' , $entPhysicalIndex );
2015-07-13 20:10:26 +02:00
}
2016-05-18 16:40:10 -04:00
elseif ( $device [ 'os' ] == 'timos' ) {
$entPhysicalDescr = $entry [ 'tmnxCardTypeDescription' ];
$entPhysicalContainedIn = $entry [ 'tmnxHwContainedIn' ];
$entPhysicalClass = $entry [ 'tmnxHwClass' ];
$entPhysicalName = $entry [ 'tmnxCardTypeName' ];
$entPhysicalSerialNum = $entry [ 'tmnxHwSerialNumber' ];
$entPhysicalModelName = $entry [ 'tmnxHwMfgBoardNumber' ];
$entPhysicalMfgName = $entry [ 'tmnxHwMfgBoardNumber' ];
$entPhysicalVendorType = $entry [ 'tmnxCardTypeName' ];
$entPhysicalParentRelPos = $entry [ 'tmnxHwParentRelPos' ];
$entPhysicalHardwareRev = '1.0' ;
$entPhysicalFirmwareRev = $entry [ 'tmnxHwBootCodeVersion' ];
$entPhysicalSoftwareRev = $entry [ 'tmnxHwBootCodeVersion' ];
$entPhysicalIsFRU = $entry [ 'tmnxHwIsFRU' ];
$entPhysicalAlias = $entry [ 'tmnxHwAlias' ];
$entPhysicalAssetID = $entry [ 'tmnxHwAssetID' ];
2016-05-24 13:52:04 -04:00
$entPhysicalIndex = str_replace ( '.' , '' , $entPhysicalIndex );
2016-05-18 16:40:10 -04:00
}
2015-07-13 20:10:26 +02:00
else {
$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' ];
$entPhysicalHardwareRev = $entry [ 'entPhysicalHardwareRev' ];
$entPhysicalFirmwareRev = $entry [ 'entPhysicalFirmwareRev' ];
$entPhysicalSoftwareRev = $entry [ 'entPhysicalSoftwareRev' ];
$entPhysicalIsFRU = $entry [ 'entPhysicalIsFRU' ];
$entPhysicalAlias = $entry [ 'entPhysicalAlias' ];
$entPhysicalAssetID = $entry [ 'entPhysicalAssetID' ];
} //end if
if ( isset ( $entity_array [ $entPhysicalIndex ][ '0' ][ 'entAliasMappingIdentifier' ])) {
$ifIndex = $entity_array [ $entPhysicalIndex ][ '0' ][ 'entAliasMappingIdentifier' ];
}
2015-04-17 14:59:47 -04:00
2015-07-13 20:10:26 +02:00
if ( ! strpos ( $ifIndex , 'fIndex' ) || $ifIndex == '' ) {
unset ( $ifIndex );
}
else {
$ifIndex_array = explode ( '.' , $ifIndex );
$ifIndex = $ifIndex_array [ 1 ];
}
2015-04-17 14:59:47 -04:00
2015-07-13 20:10:26 +02:00
if ( $entPhysicalVendorTypes [ $entPhysicalVendorType ] && ! $entPhysicalModelName ) {
$entPhysicalModelName = $entPhysicalVendorTypes [ $entPhysicalVendorType ];
}
2015-04-17 14:59:47 -04:00
2015-07-13 20:10:26 +02:00
// FIXME - dbFacile
if ( $entPhysicalDescr || $entPhysicalName ) {
$entPhysical_id = dbFetchCell ( 'SELECT entPhysical_id FROM `entPhysical` WHERE device_id = ? AND entPhysicalIndex = ?' , array ( $device [ 'device_id' ], $entPhysicalIndex ));
2015-04-17 14:59:47 -04:00
2015-07-13 20:10:26 +02:00
if ( $entPhysical_id ) {
$update_data = array (
2015-04-17 14:59:47 -04:00
'entPhysicalIndex' => $entPhysicalIndex ,
'entPhysicalDescr' => $entPhysicalDescr ,
'entPhysicalClass' => $entPhysicalClass ,
'entPhysicalName' => $entPhysicalName ,
'entPhysicalModelName' => $entPhysicalModelName ,
'entPhysicalSerialNum' => $entPhysicalSerialNum ,
'entPhysicalContainedIn' => $entPhysicalContainedIn ,
'entPhysicalMfgName' => $entPhysicalMfgName ,
'entPhysicalParentRelPos' => $entPhysicalParentRelPos ,
'entPhysicalVendorType' => $entPhysicalVendorType ,
'entPhysicalHardwareRev' => $entPhysicalHardwareRev ,
'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev ,
'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev ,
'entPhysicalIsFRU' => $entPhysicalIsFRU ,
'entPhysicalAlias' => $entPhysicalAlias ,
2015-07-13 20:10:26 +02:00
'entPhysicalAssetID' => $entPhysicalAssetID ,
);
dbUpdate ( $update_data , 'entPhysical' , 'device_id=? AND entPhysicalIndex=?' , array ( $device [ 'device_id' ], $entPhysicalIndex ));
echo '.' ;
}
else {
$insert_data = array (
2015-04-17 14:59:47 -04:00
'device_id' => $device [ 'device_id' ],
'entPhysicalIndex' => $entPhysicalIndex ,
'entPhysicalDescr' => $entPhysicalDescr ,
'entPhysicalClass' => $entPhysicalClass ,
'entPhysicalName' => $entPhysicalName ,
'entPhysicalModelName' => $entPhysicalModelName ,
'entPhysicalSerialNum' => $entPhysicalSerialNum ,
'entPhysicalContainedIn' => $entPhysicalContainedIn ,
'entPhysicalMfgName' => $entPhysicalMfgName ,
'entPhysicalParentRelPos' => $entPhysicalParentRelPos ,
'entPhysicalVendorType' => $entPhysicalVendorType ,
'entPhysicalHardwareRev' => $entPhysicalHardwareRev ,
'entPhysicalFirmwareRev' => $entPhysicalFirmwareRev ,
'entPhysicalSoftwareRev' => $entPhysicalSoftwareRev ,
'entPhysicalIsFRU' => $entPhysicalIsFRU ,
'entPhysicalAlias' => $entPhysicalAlias ,
2015-07-13 20:10:26 +02:00
'entPhysicalAssetID' => $entPhysicalAssetID ,
);
2015-04-17 14:59:47 -04:00
2015-07-13 20:10:26 +02:00
if ( ! empty ( $ifIndex )) {
$insert_data [ 'ifIndex' ] = $ifIndex ;
}
2015-04-17 14:59:47 -04:00
2015-07-13 20:10:26 +02:00
dbInsert ( $insert_data , 'entPhysical' );
echo '+' ;
} //end if
2015-04-17 14:59:47 -04:00
2015-11-20 13:03:01 +00:00
$valid [ $entPhysicalIndex ] = 1 ;
2015-07-13 20:10:26 +02:00
} //end if
} //end foreach
}
else {
echo 'Disabled!' ;
} //end if
2009-01-09 15:00:17 +00:00
2015-04-17 14:59:47 -04:00
$sql = " SELECT * FROM `entPhysical` WHERE `device_id` = ' " . $device [ 'device_id' ] . " ' " ;
foreach ( dbFetchRows ( $sql ) as $test ) {
2009-05-11 13:43:59 +00:00
$id = $test [ 'entPhysicalIndex' ];
2011-03-15 11:39:50 +00:00
if ( ! $valid [ $id ]) {
2015-07-13 20:10:26 +02:00
echo '-' ;
2015-04-17 14:59:47 -04:00
dbDelete ( 'entPhysical' , 'entPhysical_id = ?' , array ( $test [ 'entPhysical_id' ]));
2009-05-06 16:50:51 +00:00
}
2015-04-17 14:59:47 -04:00
}
2008-03-12 17:12:17 +00:00
2015-07-13 20:10:26 +02:00
echo " \n " ;