2010-07-29 20:34:31 +00:00
< ? php
2020-04-17 17:37:56 -05:00
use Illuminate\Support\Str ;
2012-04-09 10:53:55 +00:00
echo ' ENTITY-SENSOR: ' ;
2012-04-09 23:00:31 +00:00
echo 'Caching OIDs:' ;
2017-12-02 14:23:56 -06:00
if ( empty ( $entity_array )) {
2019-03-04 17:31:17 +00:00
$entity_array = [];
2011-03-15 11:24:35 +00:00
echo ' entPhysicalDescr' ;
2018-08-27 11:11:16 +02:00
$entity_array = snmpwalk_cache_multi_oid ( $device , 'entPhysicalDescr' , $entity_array , 'ENTITY-MIB' );
2017-12-02 17:18:45 -06:00
if ( ! empty ( $entity_array )) {
echo ' entPhysicalName' ;
2018-08-27 11:11:16 +02:00
$entity_array = snmpwalk_cache_multi_oid ( $device , 'entPhysicalName' , $entity_array , 'ENTITY-MIB' );
2017-12-02 17:18:45 -06:00
}
2011-03-15 11:24:35 +00:00
}
2017-12-02 17:18:45 -06:00
if ( ! empty ( $entity_array )) {
echo ' entPhySensorType' ;
2018-07-13 17:08:00 -05:00
$entity_oids = snmpwalk_cache_multi_oid ( $device , 'entPhySensorType' , [], 'ENTITY-SENSOR-MIB' );
2017-12-02 17:18:45 -06:00
echo ' entPhySensorScale' ;
2018-07-13 17:08:00 -05:00
$entity_oids = snmpwalk_cache_multi_oid ( $device , 'entPhySensorScale' , $entity_oids , 'ENTITY-SENSOR-MIB' );
2017-12-02 17:18:45 -06:00
echo ' entPhySensorPrecision' ;
2018-07-13 17:08:00 -05:00
$entity_oids = snmpwalk_cache_multi_oid ( $device , 'entPhySensorPrecision' , $entity_oids , 'ENTITY-SENSOR-MIB' );
2017-12-02 17:18:45 -06:00
echo ' entPhySensorValue' ;
2018-07-13 17:08:00 -05:00
$entity_oids = snmpwalk_cache_multi_oid ( $device , 'entPhySensorValue' , $entity_oids , 'ENTITY-SENSOR-MIB' );
2017-12-02 17:18:45 -06:00
if ( $device [ 'os' ] === 'arista_eos' ) {
2018-07-17 10:54:19 -05:00
$entity_oids = snmpwalk_cache_oid ( $device , 'aristaEntSensorThresholdTable' , $entity_oids , 'ARISTA-ENTITY-SENSOR-MIB' );
2017-12-02 17:18:45 -06:00
}
2023-11-21 23:51:16 +01:00
if ( $device [ 'os' ] === 'xos' ) {
echo ' XOS:entPhysicalContainedIn' ;
$entity_oids = snmpwalk_cache_oid ( $device , 'entPhysicalContainedIn' , $entity_oids , 'ENTITY-MIB' );
echo ' XOS:entAliasMappingIdentifier' ;
$entity_oids = snmpwalk_cache_oid ( $device , 'entAliasMappingIdentifier' , $entity_oids , 'ENTITY-MIB' );
echo ' XOS:ifName' ;
$xos_ifname = snmpwalk_cache_oid ( $device , 'ifName' , [], 'IF-MIB' );
}
2018-08-27 11:11:16 +02:00
echo ' entPhySensorOperStatus' ;
$entity_oids = snmpwalk_cache_multi_oid ( $device , 'entPhySensorOperStatus' , $entity_oids , 'ENTITY-SENSOR-MIB' );
2017-09-07 14:49:32 +01:00
}
2017-12-02 17:18:45 -06:00
2018-07-13 17:08:00 -05:00
if ( ! empty ( $entity_oids )) {
2019-03-04 17:31:17 +00:00
$entitysensor = [
2024-01-05 05:39:12 +01:00
'voltsDC' => 'voltage' ,
'voltsAC' => 'voltage' ,
'amperes' => 'current' ,
'watts' => 'power' ,
'hertz' => 'freq' ,
2017-12-02 17:18:45 -06:00
'percentRH' => 'humidity' ,
2024-01-05 05:39:12 +01:00
'rpm' => 'fanspeed' ,
'celsius' => 'temperature' ,
'dBm' => 'dbm' ,
2019-03-04 17:31:17 +00:00
];
2017-12-02 17:18:45 -06:00
2018-07-13 17:08:00 -05:00
foreach ( $entity_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 ;
2022-10-25 19:27:28 +02:00
$group = null ;
$type = null ;
$oid = null ;
$descr = null ;
$divisor = null ;
$multiplier = null ;
$current = null ;
$entPhysicalIndex = null ;
2017-09-07 14:49:32 +01:00
2017-06-06 23:46:29 +02:00
// Fix for Cisco ASR920, 15.5(2)S
2020-04-17 17:37:56 -05:00
if ( $entry [ 'entPhySensorType' ] == 'other' && Str :: contains ( $entity_array [ $index ][ 'entPhysicalName' ], [ 'Rx Power Sensor' , 'Tx Power Sensor' ])) {
2017-06-06 23:46:29 +02:00
$entitysensor [ 'other' ] = 'dbm' ;
}
2022-10-18 13:30:42 +02:00
if ( isset ( $entitysensor [ $entry [ 'entPhySensorType' ]]) && is_numeric ( $entry [ 'entPhySensorValue' ]) && is_numeric ( $index )) {
2011-03-27 10:21:19 +00:00
$entPhysicalIndex = $index ;
2018-08-27 11:11:16 +02:00
$oid = '.1.3.6.1.2.1.99.1.1.1.4.' . $index ;
2010-07-29 20:34:31 +00:00
$current = $entry [ 'entPhySensorValue' ];
2018-08-27 11:11:16 +02:00
if ( $device [ 'os' ] === 'arris-d5' ) {
$card = str_split ( $index );
if ( count ( $card ) === 3 ) {
$card = $card [ 0 ] . '00' ;
} elseif ( count ( $card ) === 4 ) {
$card = $card [ 0 ] . $card [ 1 ] . '00' ;
}
2022-10-25 19:27:28 +02:00
$descr = ucwords ( $entity_array [ $card ][ 'entPhysicalName' ] ? ? '' ) . ' ' . ucwords ( $entity_array [ $index ][ 'entPhysicalDescr' ] ? ? '' );
2023-11-21 23:51:16 +01:00
} elseif ( $device [ 'os' ] === 'xos' && str_starts_with ( $entity_oids [ $entity_oids [ $index ][ 'entPhysicalContainedIn' ] . '.0' ][ 'entAliasMappingIdentifier' ], 'mib-2.2.2.1.1.' )) {
$xos_ifindex = end ( explode ( '.' , $entity_oids [ $entity_oids [ $index ][ 'entPhysicalContainedIn' ] . '.0' ][ 'entAliasMappingIdentifier' ]));
$xos_portname = $xos_ifname [ $xos_ifindex ][ 'ifName' ];
$descr = ucwords ( $xos_portname . ' ' . str_replace ( ' Sensor' , '' , $entity_array [ $index ][ 'entPhysicalDescr' ]));
2018-08-27 11:11:16 +02:00
} else {
$descr = ucwords ( $entity_array [ $index ][ 'entPhysicalName' ]);
}
2011-12-05 15:18:18 +00:00
if ( $descr ) {
2010-07-29 20:34:31 +00:00
$descr = rewrite_entity_descr ( $descr );
2016-08-28 12:32:58 -05:00
} else {
2020-08-18 15:36:14 +02:00
// Better sensor names for Arista EOS. Remove some redundancy and improve them so they reflect to which unit they belong.
if ( $device [ 'os' ] === 'arista_eos' ) {
$descr = $entity_array [ $index ][ 'entPhysicalDescr' ];
if ( preg_match ( '/(Input|Output) (voltage|current) sensor/i' , $descr ) || Str :: startsWith ( $descr , 'Power supply' ) || preg_match ( '/^(Power Supply|Hotspot|Inlet|Board)/i' , $descr )) {
2023-03-13 22:32:22 +01:00
$descr = ucwords ( $entity_array [ substr_replace ( $index , '000' , - 3 )][ 'entPhysicalDescr' ] ? ? '' )
2022-10-25 19:27:28 +02:00
. ' '
. preg_replace (
2023-03-13 22:32:22 +01:00
'/(Voltage|Current|Power Supply) Sensor$/i' ,
'' ,
ucwords ( $entity_array [ $index ][ 'entPhysicalDescr' ])
);
2020-08-18 15:36:14 +02:00
}
if ( preg_match ( '/(temp|temperature) sensor$/i' , $descr )) {
$descr = preg_replace ( '/(temp|temperature) sensor$/i' , '' , $descr );
}
}
// End better sensor names for Arista EOS.
2011-12-05 15:18:18 +00:00
$descr = rewrite_entity_descr ( $descr );
2015-07-13 20:10:26 +02:00
}
2015-12-07 03:02:06 +00:00
$valid_sensor = check_entity_sensor ( $descr , $device );
2010-08-11 17:08:56 +00:00
$type = $entitysensor [ $entry [ 'entPhySensorType' ]];
2024-10-01 16:51:40 +01:00
// Try to handle the scale
[ $divisor , $multiplier ] = match ( $entry [ 'entPhySensorScale' ]) {
'zepto' => [ 1000000000000000000 , 1 ],
'nano' => [ 1000000000 , 1 ],
'micro' => [ 1000000 , 1 ],
'milli' => [ 1000 , 1 ],
'units' => [ 1 , 1 ],
'kilo' => [ 1 , 1000 ],
'mega' => [ 1 , 1000000 ],
'giga' => [ 1 , 1000000000 ],
'yocto' => [ 1 , 1 ],
default => [ 1 , 1 ],
};
if ( is_numeric ( $entry [ 'entPhySensorPrecision' ]) && $entry [ 'entPhySensorPrecision' ] > 0 ) {
$divisor .= str_pad ( '' , $entry [ 'entPhySensorPrecision' ], '0' );
2015-07-13 20:10:26 +02:00
}
2017-09-07 14:49:32 +01:00
$current = ( $current * $multiplier / $divisor );
2011-09-20 14:37:54 +00: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 );
2011-09-20 14:37:54 +00:00
}
2024-03-05 00:11:04 +01:00
// Fix for FortiSwitch - ALL FortiSwitches as of 14/2/2024 output fan speeds as percentages while entPhySensorType is RPM.
if ( $device [ 'os' ] == 'fortiswitch' && $entry [ 'entPhySensorType' ] == 'rpm' ) {
$type = 'percent' ;
$divisor = 1 ;
$current = $current * 10 ;
}
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 ;
}
}
2022-10-18 13:30:42 +02:00
if ( $current == '-127' || ( $device [ 'os' ] == 'asa' && is_string ( $device [ 'hardware' ]) && Str :: endsWith ( $device [ 'hardware' ], 'sc' ))) {
2015-12-07 03:02:06 +00:00
$valid_sensor = false ;
2011-05-04 13:22:41 +00:00
}
2018-08-27 11:11:16 +02:00
// Check for valid sensors
2023-11-21 23:51:16 +01:00
if ( isset ( $entry [ 'entPhySensorOperStatus' ]) && ( $entry [ 'entPhySensorOperStatus' ] === 'unavailable' || $entry [ 'entPhySensorOperStatus' ] === 'nonoperational' )) {
2018-08-27 11:11:16 +02:00
$valid_sensor = false ;
}
2024-09-02 21:44:29 -05:00
if ( $entry [ 'entPhySensorValue' ] == '-1000000000' ) {
$valid_sensor = false ;
}
2019-03-04 17:31:17 +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` = ? " , [ $device [ 'device_id' ], $type , $index ]) == '0' ) {
2012-05-25 12:24:34 +00: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 ;
}
}
2020-08-18 15:36:14 +02:00
// Grouping sensors
$group = null ;
if ( preg_match ( '/DOM /i' , $descr )) {
$group = 'SFPs' ;
} elseif ( preg_match ( '/PwrCon/' , $descr )) {
$string = explode ( ' ' , $descr );
if ( preg_match ( '/PwrCon[0-9]/' , $string [ 0 ])) {
$group = $string [ 0 ];
} else {
$group = preg_replace ( '/PwrCon/i' , '' , $string [ 0 ]);
}
$descr = preg_replace ( '/^.*?(PwrCon)[0-9]*/i' , '' , $descr );
} elseif ( preg_match ( '/^(Trident.*|Jericho[0-9]|FM6000)/i' , $descr )) {
// I only know replies for Trident|Jericho|FM6000 platform. If you have another please add to the preg_match
$group = 'Platform' ;
} elseif ( preg_match ( '/^(Power|PSU)/i' , $descr )) {
$group = 'PSUs' ;
} else {
$group = 'System' ;
$descr = Str :: replaceLast ( 'temp sensor' , '' , $descr );
}
// End grouping sensors
2017-09-07 14:49:32 +01:00
}
2022-10-11 19:50:38 +02:00
$descr = trim ( $descr );
2024-09-03 21:04:34 -05:00
discover_sensor ( null , $type , $device , $oid , $index , 'entity-sensor' , $descr , $divisor , $multiplier , $low_limit , $low_warn_limit , $warn_limit , $high_limit , $current , 'snmp' , $entPhysicalIndex , $entry [ 'entSensorMeasuredEntity' ] ? ? null , null , $group );
2010-07-29 20:34:31 +00:00
}
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
2010-11-19 22:46:24 +00:00
echo " \n " ;