diff --git a/plist b/plist index 9949a0b8f..aac106e4f 100644 --- a/plist +++ b/plist @@ -1268,7 +1268,6 @@ /usr/local/opnsense/scripts/system/status.php /usr/local/opnsense/scripts/system/swapinfo.py /usr/local/opnsense/scripts/system/sysctl.py -/usr/local/opnsense/scripts/system/temperature.sh /usr/local/opnsense/scripts/system/tls_groups.py /usr/local/opnsense/scripts/system/trigger_config_changed_events.py /usr/local/opnsense/scripts/system/update-crl-fetch.py diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/SystemController.php b/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/SystemController.php index 407ce9a0d..932c0bc26 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/SystemController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api/SystemController.php @@ -226,19 +226,29 @@ class SystemController extends ApiControllerBase public function systemTemperatureAction() { + $backend = new Backend(); $result = []; - foreach (explode("\n", (new Backend())->configdRun('system temp')) as $temp) { - $parts = explode('=', $temp); - if (count($parts) >= 2) { - $tempItem = array(); - $tempItem['device'] = $parts[0]; - $tempItem['device_seq'] = filter_var($tempItem['device'], FILTER_SANITIZE_NUMBER_INT); - $tempItem['temperature'] = trim(str_replace('C', '', $parts[1])); - $tempItem['type'] = strpos($tempItem['device'], 'hw.acpi') !== false ? 'zone' : 'cpu'; - $tempItem['type_translated'] = $tempItem['type'] == 'zone' ? gettext('Zone') : gettext('CPU'); - $result[] = $tempItem; + /* read temperatures individually from previously derived sensors */ + $sensors = explode("\n", $backend->configdRun('system sensors')); + $temps = json_decode($backend->configdpRun('system sysctl values', join(',', $sensors)), true); + + foreach ($temps as $name => $value) { + $tempItem = []; + $tempItem['device'] = $name; + $tempItem['device_seq'] = filter_var($tempItem['device'], FILTER_SANITIZE_NUMBER_INT); /* XXX too opportunistic */ + $tempItem['temperature'] = trim(str_replace('C', '', $value)); + $tempItem['type_translated'] = gettext('CPU'); + $tempItem['type'] = 'cpu'; + if (strpos($tempItem['device'], 'hw.acpi') !== false) { + $tempItem['type_translated'] = gettext('Zone'); + $tempItem['type'] = 'zone'; + /* XXX may or may not be a good idea */ + } elseif (strpos($tempItem['device'], 'dev.amdtemp') !== false) { + $tempItem['type_translated'] = gettext('AMD'); + $tempItem['type'] = 'amd'; } + $result[] = $tempItem; } return $result; diff --git a/src/opnsense/scripts/system/temperature.sh b/src/opnsense/scripts/system/temperature.sh deleted file mode 100755 index 4dfe35bce..000000000 --- a/src/opnsense/scripts/system/temperature.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2020 Franco Fichtner -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. - -# The grep is opportunistic and leads some people to believe -# their CPU runs hotter than it should. It's always been this -# way and it should be changed, but so far all simple ideas fail -# to address the fact that we don't know which temperature to -# read until we have asked the kernel. Caching this and unifying -# with RRD collection is a worthwile goal. No hackery in the -# meantime to avoid adding something we cannot get rid of later. -SYSCTLS=$(sysctl -aN | grep temperature) -if [ -n "${SYSCTLS}" ]; then - sysctl -e ${SYSCTLS} | sort -fi diff --git a/src/opnsense/service/conf/actions.d/actions_system.conf b/src/opnsense/service/conf/actions.d/actions_system.conf index 008d9f051..f68581f51 100644 --- a/src/opnsense/service/conf/actions.d/actions_system.conf +++ b/src/opnsense/service/conf/actions.d/actions_system.conf @@ -96,11 +96,12 @@ parameters: type:script message:Halt system -[temp] -command:/usr/local/opnsense/scripts/system/temperature.sh +[sensors] +command:sysctl -aF | awk -F ": " '$2 ~ "^IK" { print $1 }' | grep -v "\._" | sort parameters: type:script_output -message:Reading system temperature values +message:Probing system temperature sensor location +cache_ttl:86400 [ha_reconfigure_backup] command:/usr/local/bin/flock -n -E 0 -o /tmp/ha_reconfigure_backup.lock /usr/local/etc/rc.filter_synchronize pre_check_master restart_services