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-04-28 10:28:58 +00:00
$ents_cmd = $config [ 'snmpbulkwalk' ] . " -m ENTITY-MIB -O qn - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ '$port' ] . " " ;
2009-05-06 16:50:51 +00:00
$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 \" \" " ;
2008-03-12 17:12:17 +00:00
$ents = trim ( `$ents_cmd | grep -v o` );
2009-05-06 16:50:51 +00:00
foreach ( explode ( " \n " , $ents ) as $entPhysicalIndex ) {
2008-03-12 17:12:17 +00:00
2009-05-11 13:43:59 +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 .= " 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` );
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
$entPhysicalModelName = trim ( $entPhysicalModelName );
$entPhysicalSerialNum = trim ( $entPhysicalSerialNum );
$entPhysicalMfgName = trim ( $entPhysicalMfgName );
$entPhysicalVendorType = trim ( $entPhysicalVendorType );
if ( $entPhysicalVendorTypes [ $entPhysicalVendorType ] && ! $entPhysicalModelName ) {
$entPhysicalModelName = $entPhysicalVendorTypes [ $entPhysicalVendorType ];
}
2009-05-11 13:43:59 +00:00
$entPhysical_id = @ mysql_result ( mysql_query ( " SELECT entPhysical_id FROM `entPhysical` WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND entPhysicalIndex = ' $entPhysicalIndex ' " ), 0 );
2008-03-22 23:09:35 +00:00
2009-05-11 13:43:59 +00:00
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 .= " WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND entPhysicalIndex = ' $entPhysicalIndex ' " ;
mysql_query ( $sql );
2009-05-06 16:50:51 +00:00
echo ( " . " );
2008-03-12 17:12:17 +00:00
} else {
$sql = " INSERT INTO `entPhysical` ( `device_id` , `entPhysicalIndex` , `entPhysicalDescr` , `entPhysicalClass` , `entPhysicalName` , `entPhysicalModelName` , `entPhysicalSerialNum` , `entPhysicalContainedIn`, `entPhysicalMfgName`, `entPhysicalParentRelPos`, `entPhysicalVendorType`, `ifIndex` ) " ;
$sql .= " VALUES ( ' " . $device [ 'device_id' ] . " ', ' $entPhysicalIndex ', ' $entPhysicalDescr ', ' $entPhysicalClass ', ' $entPhysicalName ', ' $entPhysicalModelName ', ' $entPhysicalSerialNum ', ' $entPhysicalContainedIn ', ' $entPhysicalMfgName ',' $entPhysicalParentRelPos ' , ' $entPhysicalVendorType ', ' $ifIndex ') " ;
mysql_query ( $sql );
2008-03-22 23:09:35 +00:00
echo ( " + " );
2008-03-12 17:12:17 +00:00
}
2009-05-06 16:50:51 +00:00
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 " ;
2009-05-11 13:43:59 +00:00
$sensor_cmd .= " entSensorValueUpdateRate. $entPhysicalIndex entSensorMeasuredEntity. $entPhysicalIndex " ;
2009-05-06 16:50:51 +00:00
$sensor_data = shell_exec ( $sensor_cmd );
list ( $entSensorType , $entSensorScale , $entSensorPrecision , $entSensorValueUpdateRate , $entSensorMeasuredEntity ) = explode ( " \n " , $sensor_data );
2009-05-11 13:43:59 +00:00
if ( $entSensorMeasuredEntity ) {
2009-09-24 14:38:17 +00:00
#echo("M:$entSensorMeasuredEntity");
2009-05-11 13:43:59 +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 ( " ! $entSensorType " );
$sql = " UPDATE `entPhysical` SET entSensorType = '', entSensorScale = '', entSensorPrecision = '', entSensorMeasuredEntity = '' " ;
$sql .= " WHERE device_id = ' " . $device [ 'device_id' ] . " ' AND entPhysicalIndex = ' $entPhysicalIndex ' " ;
}
2009-05-06 16:50:51 +00:00
mysql_query ( $sql );
}
$valid [ $entPhysicalIndex ] = 1 ;
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
?>