2010-07-29 20:34:31 +00:00
< ? php
2015-07-13 20:10:26 +02:00
echo ' ENTITY-SENSOR: ' ;
echo 'Caching OIDs:' ;
2017-12-02 14:23:56 -06:00
if ( empty ( $entity_array )) {
2015-07-13 20:10:26 +02:00
$entity_array = array ();
echo ' entPhysicalDescr' ;
$entity_array = snmpwalk_cache_multi_oid ( $device , 'entPhysicalDescr' , $entity_array , 'CISCO-ENTITY-SENSOR-MIB' );
2017-12-02 17:18:45 -06:00
if ( ! empty ( $entity_array )) {
echo ' entPhysicalName' ;
$entity_array = snmpwalk_cache_multi_oid ( $device , 'entPhysicalName' , $entity_array , 'CISCO-ENTITY-SENSOR-MIB' );
}
2011-03-15 11:24:35 +00:00
}
2017-12-02 17:18:45 -06:00
if ( ! empty ( $entity_array )) {
$oids = array ();
echo ' entPhySensorType' ;
$oids = snmpwalk_cache_multi_oid ( $device , 'entPhySensorType' , $oids , 'ENTITY-SENSOR-MIB' );
echo ' entPhySensorScale' ;
$oids = snmpwalk_cache_multi_oid ( $device , 'entPhySensorScale' , $oids , 'ENTITY-SENSOR-MIB' );
echo ' entPhySensorPrecision' ;
$oids = snmpwalk_cache_multi_oid ( $device , 'entPhySensorPrecision' , $oids , 'ENTITY-SENSOR-MIB' );
echo ' entPhySensorValue' ;
$oids = snmpwalk_cache_multi_oid ( $device , 'entPhySensorValue' , $oids , 'ENTITY-SENSOR-MIB' );
if ( $device [ 'os' ] === 'arista_eos' ) {
require 'includes/discovery/sensors/misc/arista-eos-limits.inc.php' ;
}
2017-09-07 14:49:32 +01:00
}
2017-12-02 17:18:45 -06:00
if ( ! empty ( $oids )) {
$entitysensor = array (
'voltsDC' => 'voltage' ,
'voltsAC' => 'voltage' ,
'amperes' => 'current' ,
'watts' => 'power' ,
'hertz' => 'freq' ,
'percentRH' => 'humidity' ,
'rpm' => 'fanspeed' ,
'celsius' => 'temperature' ,
'dBm' => 'dbm' ,
);
2015-07-13 20:10:26 +02:00
foreach ( $oids as $index => $entry ) {
2017-09-07 14:49:32 +01:00
$low_limit = null ;
$low_warn_limit = null ;
$warn_limit = null ;
$high_limit = null ;
2017-06-06 23:46:29 +02:00
// Fix for Cisco ASR920, 15.5(2)S
if ( $entry [ 'entPhySensorType' ] == 'other' && str_contains ( $entity_array [ $index ][ 'entPhysicalName' ], array ( 'Rx Power Sensor' , 'Tx Power Sensor' ))) {
$entitysensor [ 'other' ] = 'dbm' ;
}
2015-07-13 20:10:26 +02:00
if ( $entitysensor [ $entry [ 'entPhySensorType' ]] && is_numeric ( $entry [ 'entPhySensorValue' ]) && is_numeric ( $index )) {
$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"
2017-06-06 23:46:29 +02:00
$descr = ucwords ( $entity_array [ $index ][ 'entPhysicalName' ]);
2015-07-13 20:10:26 +02:00
// if ($descr || $device['os'] == "iosxr")
if ( $descr ) {
$descr = rewrite_entity_descr ( $descr );
2016-08-28 12:32:58 -05:00
} else {
2015-07-13 20:10:26 +02:00
$descr = $entity_array [ $index ][ 'entPhysicalDescr' ];
$descr = rewrite_entity_descr ( $descr );
}
2015-12-07 03:02:06 +00:00
$valid_sensor = check_entity_sensor ( $descr , $device );
2015-07-13 20:10:26 +02:00
$type = $entitysensor [ $entry [ 'entPhySensorType' ]];
// FIXME this stuff is foul
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' ;
}
if ( $entry [ 'entPhySensorScale' ] == 'yocto' ) {
$divisor = '1' ;
$multiplier = '1' ;
}
if ( is_numeric ( $entry [ 'entPhySensorPrecision' ]) && $entry [ 'entPhySensorPrecision' ] > '0' ) {
$divisor = $divisor . str_pad ( '' , $entry [ 'entPhySensorPrecision' ], '0' );
}
2017-09-07 14:49:32 +01:00
if ( $device [ 'os' ] === 'arista_eos' ) {
if ( $entry [ 'entPhySensorScale' ] == 'milli' && $entry [ 'entPhySensorType' ] == 'amperes' ) {
$divisor = '1' ;
$multiplier = '1' ;
}
}
2015-07-13 20:10:26 +02:00
2017-09-07 14:49:32 +01:00
$current = ( $current * $multiplier / $divisor );
2015-07-13 20:10:26 +02:00
if ( $type == 'temperature' ) {
if ( $current > '200' ) {
2015-12-07 03:02:06 +00:00
$valid_sensor = false ;
2017-09-07 14:49:32 +01:00
}
$descr = preg_replace ( '/[T|t]emperature[|s]/' , '' , $descr );
2015-07-13 20:10:26 +02:00
}
2017-07-13 19:23:55 +02:00
if ( $device [ 'os' ] == 'rittal-lcp' ) {
if ( $type == 'voltage' ) {
$divisor = 1000 ;
}
if ( $descr == 'Temperature.Value' ) {
$divisor = 1000 ;
}
if ( $descr == 'System.Temperature.Value' ) {
$divisor = 1000 ;
}
if ( $type == 'humidity' && $current == '0' ) {
$valid_sensor = false ;
}
}
2015-07-13 20:10:26 +02:00
// echo($descr . "|" . $index . "|" .$current . "|" . $multiplier . "|" . $divisor ."|" . $entry['entPhySensorScale'] . "|" . $entry['entPhySensorPrecision'] . "\n");
2016-11-19 15:42:49 +02:00
if ( $current == '-127' || ( $device [ 'os' ] == 'asa' && str_contains ( $device [ 'hardware' ], 'sc' ))) {
2015-12-07 03:02:06 +00:00
$valid_sensor = false ;
2015-07-13 20:10:26 +02:00
}
2015-12-07 03:02:06 +00:00
if ( $valid_sensor && dbFetchCell ( " SELECT COUNT(*) FROM `sensors` WHERE device_id = ? AND `sensor_class` = ? AND `sensor_type` = 'cisco-entity-sensor' AND `sensor_index` = ? " , array ( $device [ 'device_id' ], $type , $index )) == '0' ) {
2015-07-13 20:10:26 +02:00
// Check to make sure we've not already seen this sensor via cisco's entity sensor mib
2017-02-05 19:46:13 +00:00
if ( $type == " power " && $device [ 'os' ] == " arista_eos " && preg_match ( " /DOM (R|T)x Power/i " , $descr )) {
$type = " dbm " ;
2017-06-02 13:29:49 +01:00
$current = round ( 10 * log10 ( $entry [ 'entPhySensorValue' ] / 10000 ), 3 );
2017-02-05 19:46:13 +00:00
$multiplier = 1 ;
$divisor = 1 ;
}
2017-09-07 14:49:32 +01:00
if ( $device [ 'os' ] === 'arista_eos' ) {
if ( $entry [ 'aristaEntSensorThresholdLowWarning' ] != '-1000000000' ) {
if ( $entry [ 'entPhySensorScale' ] == 'milli' && $entry [ 'entPhySensorType' ] == 'watts' ) {
$temp_low_warn_limit = $entry [ 'aristaEntSensorThresholdLowWarning' ] / 10000 ;
$low_warn_limit = round ( 10 * log10 ( $temp_low_warn_limit ), 2 );
} else {
$low_warn_limit = $entry [ 'aristaEntSensorThresholdLowWarning' ] / $divisor ;
}
}
if ( $entry [ 'aristaEntSensorThresholdLowCritical' ] != '-1000000000' ) {
if ( $entry [ 'entPhySensorScale' ] == 'milli' && $entry [ 'entPhySensorType' ] == 'watts' ) {
$temp_low_limit = $entry [ 'aristaEntSensorThresholdLowCritical' ] / 10000 ;
$low_limit = round ( 10 * log10 ( $temp_low_limit ), 2 );
} else {
$low_limit = $entry [ 'aristaEntSensorThresholdLowCritical' ] / $divisor ;
}
}
if ( $entry [ 'aristaEntSensorThresholdHighWarning' ] != '1000000000' ) {
if ( $entry [ 'entPhySensorScale' ] == 'milli' && $entry [ 'entPhySensorType' ] == 'watts' ) {
$temp_warn_limit = $entry [ 'aristaEntSensorThresholdHighWarning' ] / 10000 ;
$warn_limit = round ( 10 * log10 ( $temp_warn_limit ), 2 );
} else {
$warn_limit = $entry [ 'aristaEntSensorThresholdHighWarning' ] / $divisor ;
}
}
if ( $entry [ 'aristaEntSensorThresholdHighCritical' ] != '1000000000' ) {
if ( $entry [ 'entPhySensorScale' ] == 'milli' && $entry [ 'entPhySensorType' ] == 'watts' ) {
$temp_high_limit = $entry [ 'aristaEntSensorThresholdHighCritical' ] / 10000 ;
$high_limit = round ( 10 * log10 ( $temp_high_limit ), 2 );
} else {
$high_limit = $entry [ 'aristaEntSensorThresholdHighCritical' ] / $divisor ;
}
}
}
discover_sensor ( $valid [ 'sensor' ], $type , $device , $oid , $index , 'entity-sensor' , $descr , $divisor , $multiplier , $low_limit , $low_warn_limit , $warn_limit , $high_limit , $current , 'snmp' , $entPhysicalIndex , $entry [ 'entSensorMeasuredEntity' ]);
2015-07-13 20:10:26 +02:00
}
} //end if
} //end foreach
2017-02-08 04:54:30 +00:00
unset (
$entity_array
);
2015-07-13 20:10:26 +02:00
} //end if
echo " \n " ;