2010-07-29 20:34:31 +00:00
<? php
global $valid_sensor ;
2010-08-13 13:17:53 +00:00
echo ( " ENTITY-SENSOR " );
2010-07-29 20:34:31 +00:00
2011-03-15 11:24:35 +00:00
echo ( " \n Caching OIDs:" );
2010-08-11 17:08:56 +00:00
2011-03-15 11:24:35 +00:00
if ( ! is_array ( $entity_array ))
{
$entity_array = array ();
echo ( " entPhysicalDescr" );
$entity_array = snmpwalk_cache_multi_oid ( $device , "entPhysicalDescr" , $entity_array , "CISCO-ENTITY-SENSOR-MIB" );
echo ( " entPhysicalName" );
$entity_array = snmpwalk_cache_multi_oid ( $device , "entPhysicalName" , $entity_array , "CISCO-ENTITY-SENSOR-MIB" );
}
2010-08-11 17:08:56 +00:00
2011-03-15 11:24:35 +00:00
$oids = array ();
2010-08-11 17:08:56 +00:00
echo ( " entPhySensorType" );
2010-07-29 20:34:31 +00:00
$oids = snmpwalk_cache_multi_oid ( $device , "entPhySensorType" , $oids , "ENTITY-SENSOR-MIB" );
2010-08-11 17:08:56 +00:00
echo ( " entPhySensorScale" );
2010-07-29 20:34:31 +00:00
$oids = snmpwalk_cache_multi_oid ( $device , "entPhySensorScale" , $oids , "ENTITY-SENSOR-MIB" );
2010-08-11 17:08:56 +00:00
echo ( " entPhySensorPrecision" );
2010-07-29 20:34:31 +00:00
$oids = snmpwalk_cache_multi_oid ( $device , "entPhySensorPrecision" , $oids , "ENTITY-SENSOR-MIB" );
2010-08-11 17:08:56 +00:00
echo ( " entPhySensorValue" );
2010-07-29 20:34:31 +00:00
$oids = snmpwalk_cache_multi_oid ( $device , "entPhySensorValue" , $oids , "ENTITY-SENSOR-MIB" );
$entitysensor [ 'voltsDC' ] = "voltage" ;
$entitysensor [ 'voltsAC' ] = "voltage" ;
$entitysensor [ 'amperes' ] = "current" ;
$entitysensor [ 'watt' ] = "power" ;
$entitysensor [ 'hertz' ] = "freq" ;
$entitysensor [ 'percentRH' ] = "humidity" ;
$entitysensor [ 'rpm' ] = "fanspeed" ;
$entitysensor [ 'celsius' ] = "temperature" ;
2011-03-15 11:24:35 +00:00
if ( is_array ( $oids ))
2010-07-29 20:34:31 +00:00
{
2011-03-15 11:24:35 +00:00
foreach ( $oids as $index => $entry )
2010-07-29 20:34:31 +00:00
{
#echo("[" . $entry['entPhySensorType'] . "|" . $entry['entPhySensorValue']. "|" . $index . "]");
2011-03-15 11:24:35 +00:00
if ( $entitysensor [ $entry [ 'entPhySensorType' ]] && is_numeric ( $entry [ 'entPhySensorValue' ]) && is_numeric ( $index ))
2010-07-29 20:34:31 +00:00
{
$entPhysicalIndex = $index ;
$oid = ".1.3.6.1.2.1.99.1.1.1.4." . $index ;
$current = $entry [ 'entPhySensorValue' ];
#ENTITY-SENSOR-MIB::entPhySensorUnitsDisplay.11 = STRING: "C"
2010-08-11 17:08:56 +00:00
$descr = $entity_array [ $index ][ 'entPhysicalName' ];
2011-03-15 11:24:35 +00:00
if ( $descr || $device [ 'os' ] == "iosxr" )
2010-08-11 17:08:56 +00:00
{
$descr = rewrite_entity_descr ( $descr );
} else {
$descr = $entity_array [ $index ][ 'entPhysicalDescr' ];
$descr = rewrite_entity_descr ( $descr );
}
2010-07-30 14:50:09 +00:00
2010-07-30 14:59:44 +00:00
$valid = TRUE ;
2010-07-30 14:50:09 +00:00
2010-07-29 20:34:31 +00:00
$type = $entitysensor [ $entry [ 'entPhySensorType' ]];
2011-03-15 11:24:35 +00:00
2010-07-29 20:34:31 +00:00
### FIXME this stuff is foul
2011-03-27 10:21:19 +00:00
if ( $entry [ 'entPhySensorScale' ] == "nano" ) { $divisor = "1000000000" ; $multiplier = "1" ; }
if ( $entry [ 'entPhySensorScale' ] == "micro" ) { $divisor = "1000000" ; $multiplier = "1" ; }
if ( $entry [ 'entPhySensorScale' ] == "milli" ) { $divisor = "1000" ; $multiplier = "1" ; }
if ( $entry [ 'entPhySensorScale' ] == "units" ) { $divisor = "1" ; $multiplier = "1" ; }
if ( $entry [ 'entPhySensorScale' ] == "kilo" ) { $divisor = "1" ; $multiplier = "1000" ; }
if ( $entry [ 'entPhySensorScale' ] == "mega" ) { $divisor = "1" ; $multiplier = "1000000" ; }
if ( $entry [ 'entPhySensorScale' ] == "giga" ) { $divisor = "1" ; $multiplier = "1000000000" ; }
2010-07-30 14:59:44 +00:00
2011-03-15 11:24:35 +00:00
if ( is_numeric ( $entry [ 'entPhySensorPrecision' ]) && $entry [ 'entPhySensorPrecision' ] > "0" ) { $divisor = $divisor . str_pad ( '' , $entry [ 'entPhySensorPrecision' ], "0" ); }
2010-07-29 20:34:31 +00:00
$current = $current * $multiplier / $divisor ;
2011-03-15 11:24:35 +00:00
if ( $type == "temperature" ) { if ( $current > "200" ){ $valid = FALSE ; } $descr = preg_replace ( "/[T|t]emperature[|s]/" , "" , $descr ); }
2010-07-30 14:50:09 +00:00
2010-07-30 16:11:09 +00:00
#echo($descr . "|" . $index . "|" .$current . "|" . $multiplier . "|" . $divisor ."|" . $entry['entPhySensorScale'] . "|" . $entry['entPhySensorPrecision'] . "\n");
2010-07-30 14:50:09 +00:00
2011-03-15 11:24:35 +00:00
if ( $current == "-127" ) { $valid = FALSE ; }
2010-08-11 17:08:56 +00:00
2011-03-15 11:24:35 +00:00
if ( $valid && mysql_result ( mysql_query ( "SELECT COUNT(*) FROM `sensors` WHERE `device_id` = '" . $device [ 'device_id' ] . "' AND `sensor_class` = '" . $type . "' AND `sensor_type` = 'cisco-entity-sensor' AND `sensor_index` = '" . $index . "'" ), 0 ) == "0" )
2010-07-29 20:34:31 +00:00
## Check to make sure we've not already seen this sensor via cisco's entity sensor mib
{
discover_sensor ( $valid_sensor , $type , $device , $oid , $index , 'entity-sensor' , $descr , $divisor , $multiplier , NULL , NULL , NULL , NULL , $current );
}
}
}
}
2010-11-19 22:46:24 +00:00
echo ( " \n " );
2011-03-15 11:24:35 +00:00
?>