From b908418058332d206a8b2935ddbb13c8a1fb763d Mon Sep 17 00:00:00 2001 From: crcro Date: Tue, 11 Oct 2016 09:37:47 +0300 Subject: [PATCH] refactor: Rewrite for qnap fanspeeds (#4590) --- .../discovery/sensors/fanspeeds/qnap.inc.php | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/includes/discovery/sensors/fanspeeds/qnap.inc.php b/includes/discovery/sensors/fanspeeds/qnap.inc.php index 3a60c54769..c49cb65860 100644 --- a/includes/discovery/sensors/fanspeeds/qnap.inc.php +++ b/includes/discovery/sensors/fanspeeds/qnap.inc.php @@ -1,24 +1,33 @@ + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ if ($device['os'] == 'qnap') { echo 'QNAP: '; - $oids = snmpwalk_cache_multi_oid($device, 'SystemFanTable', array(), 'NAS-MIB'); - // Turbo NAS Fanspeed - $fan_speed_oid = '.1.3.6.1.4.1.24681.1.2.15.1.3.'; + $fan_descr_oid = '.1.3.6.1.4.1.24681.1.2.15.1.2'; + $fan_speed_oid = '.1.3.6.1.4.1.24681.1.2.15.1.3'; + $descr_oid = '24681.1.2.15.1.2.'; + $speed_oid = '24681.1.2.15.1.3.'; - // Parse all fans in the device to get the speed - if (is_array($oids)) { - foreach ($oids as $fan_number => $entry) { - // Get the fan speed full oid - $fan_oid = $fan_speed_oid.$fan_number; - // Get the fan speed - $fan_speed = $entry['SysFanSpeed']; - // Getting the fan information - $fan_information = $entry['SysFanDescr']; - // Save the temperature for the disk - discover_sensor($valid['sensor'], 'fanspeed', $device, $fan_oid, $fan_number, 'snmp', $fan_information, '1', '1', null, null, null, null, $fan_speed); + + $fans_descr = snmpwalk_cache_multi_oid($device, $fan_descr_oid, array()); + $fans_speed = snmpwalk_cache_multi_oid($device, $fan_speed_oid, array()); + + if (is_array($fans_speed) && !empty($fans_speed)) { + foreach ($fans_speed as $index => $entry) { + $index = str_replace($speed_oid, '', $index); + $fan_speed = $entry['enterprises']; + $fan_serial = str_replace('"', '', $fans_descr[$descr_oid . $index]['enterprises']); + discover_sensor($valid['sensor'], 'fanspeed', $device, $fan_speed_oid.$index, $index, 'snmp', $fan_serial, '1', '1', null, null, null, null, $fan_speed); } } -}//end if +}