1<?php 2/** 3 * raritan-pdu.inc.php 4 * 5 * LibreNMS temperature sensor discovery module for Raritan 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <https://www.gnu.org/licenses/>. 19 * 20 * @link https://www.librenms.org 21 * @copyright 2017 Neil Lathwood 22 * @author Neil Lathwood <gh+n@laf.io> 23 */ 24$index = 'unitCpuTemp.0'; 25$oid = '.1.3.6.1.4.1.13742.4.1.3.1.5.0'; 26$descr = 'Processor Temp'; 27$divisor = 10; 28$raritan_data = snmp_get_multi_oid($device, ['unitCpuTemp.0', 'unitTempLowerWarning.0', 'unitTempLowerCritical.0', 'unitTempUpperWarning.0', 'unitTempUpperCritical.0'], '-OUQs', 'PDU-MIB'); 29if (is_array($raritan_data) && ! empty($raritan_data)) { 30 $low_limit = $raritan_data['unitTempLowerCritical.0']; 31 $low_warn_limit = $raritan_data['unitTempLowerWarning.0']; 32 $warn_limit = $raritan_data['unitTempUpperWarning.0']; 33 $high_limit = $raritan_data['unitTempUpperCritical.0']; 34 $current = $raritan_data['unitCpuTemp.0'] / $divisor; 35 discover_sensor($valid['sensor'], 'temperature', $device, $oid, $tmp_index, 'raritan', $descr, $divisor, 1, $low_limit, $low_limit, $warn_limit, $high_limit, $current); 36} else { 37 $multiplier = '1'; 38 foreach ($pre_cache['raritan_extSensorConfig'] as $index => $data) { 39 if ($data['externalSensorType'] == 'temperature') { 40 $descr = $data['externalSensorName']; 41 $oid = ".1.3.6.1.4.1.13742.6.5.5.3.1.4.$index"; 42 $low_limit = ($data['externalSensorLowerCriticalThreshold'] / $divisor); 43 $low_warn_limit = ($data['externalSensorLowerWarningThreshold'] / $divisor); 44 $high_limit = ($data['externalSensorUpperCriticalThreshold'] / $divisor); 45 $high_warn_limit = ($data['externalSensorUpperWarningThreshold'] / $divisor); 46 47 $measure_data = $pre_cache['raritan_extSensorMeasure'][$index]; 48 $current = ($measure_data['measurementsExternalSensorValue'] / $divisor); 49 $sensor_available = $measure_data['measurementsExternalSensorIsAvailable']; 50 $raritan_temp_scale = $data['externalSensorUnits']; 51 $user_func = null; 52 if ($raritan_temp_scale == 'degreeF') { 53 $low_warn_limit = fahrenheit_to_celsius($low_warn_limit, $raritan_temp_scale); 54 $low_limit = fahrenheit_to_celsius($low_limit, $raritan_temp_scale); 55 $high_warn_limit = fahrenheit_to_celsius($high_warn_limit, $raritan_temp_scale); 56 $high_limit = fahrenheit_to_celsius($high_limit, $raritan_temp_scale); 57 $current = fahrenheit_to_celsius($current, $raritan_temp_scale); 58 $user_func = 'fahrenheit_to_celsius'; 59 } 60 if (is_numeric($current) && $current >= 0 && $sensor_available === 'true') { 61 discover_sensor($valid['sensor'], 'temperature', $device, $oid, 'measurementsExternalSensorValue.' . $index, 'raritan', $descr, $divisor, $multiplier, $low_limit, $low_warn_limit, $high_warn_limit, $high_limit, $current, 'snmp', null, null, $user_func); 62 } 63 } 64 } 65} 66 67//Check for PDU MIB external Sensors 68$oids = snmpwalk_cache_multi_oid($device, 'externalSensorTable', [], 'PDU-MIB'); 69$offset = 0; 70foreach ($oids as $index => $sensor) { 71 if ($sensor['externalSensorType'] == 'temperature') { 72 $oid = ".1.3.6.1.4.1.13742.4.3.3.1.41.$index"; 73 $descr = $sensor['externalSensorName']; 74 $temp_current = $sensor['externalSensorValue']; 75 $temp_current = $temp_current / $divisor; 76 $limit_high = $sensor['externalSensorUpperWarningThreshold'] / $divisor; 77 $limit_low = $sensor['externalSensorLowerWarningThreshold'] / $divisor; 78 $limit_high_warn = $sensor['externalSensorUpperCriticalThreshold'] / $divisor; 79 $limit_low_warn = $sensor['externalSensorLowerCriticalThreshold'] / $divisor; 80 $offset++; 81 if (is_numeric($temp_current) && $temp_current >= 0) { 82 discover_sensor($valid['sensor'], 'temperature', $device, $oid, $offset, 'raritan', $descr, $divisor, 1, $limit_low, $limit_low_warn, $limit_high_warn, $limit_high, $temp_current); 83 } 84 } 85} 86