system: popular temperature topic changes

* Use priv-sep script to fetch values via configd
* Use grep on variable names only to avoid false positives
* Switch the RRD script read to unify temperature reads
* Use "=" in the script output to match sysctl input
This commit is contained in:
Franco Fichtner 2020-08-28 12:25:02 +02:00
parent 2de6e27083
commit 305d6b35cc
5 changed files with 48 additions and 5 deletions

1
plist
View File

@ -769,6 +769,7 @@
/usr/local/opnsense/scripts/system/list_interrupts.py
/usr/local/opnsense/scripts/system/rfc5246_cipher_suites.csv
/usr/local/opnsense/scripts/system/ssl_ciphers.py
/usr/local/opnsense/scripts/system/temperature.sh
/usr/local/opnsense/scripts/systemhealth/activity.py
/usr/local/opnsense/scripts/systemhealth/clearlog
/usr/local/opnsense/scripts/systemhealth/definitions/gateway-quality.xml

View File

@ -518,7 +518,7 @@ function rrd_configure($verbose = false)
}
/* the CPU Temperature gathering function */
$rrdupdatesh .= "CPUTEMP=`$sysctl -n dev.cpu.0.temperature | sed 's/C//g'`\n";
$rrdupdatesh .= "CPUTEMP=\$(/usr/local/opnsense/scripts/system/temperature.sh rrd)\n";
$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$cputemp N:\${CPUTEMP}\n";
/* end CPU Temp gathering */

View File

@ -0,0 +1,35 @@
#!/bin/sh
# Copyright (C) 2020 Franco Fichtner <franco@opnsense.org>
# 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.
CMD=${1}
if [ "${CMD}" = 'rrd' ]; then
sysctl -n dev.cpu.0.temperature | sed 's/C//g'
else
# The grep is opportunistic, but at least we only grep the
# variable names and not their content at the same time.
sysctl -e $(sysctl -aN | grep temperature) | sort
fi

View File

@ -54,3 +54,9 @@ command:/usr/local/etc/rc.halt
parameters:
type:script
message:Halt system
[temp]
command:/usr/local/opnsense/scripts/system/temperature.sh
parameters:%s
type:script_output
message:Reading system temperature values

View File

@ -32,9 +32,9 @@
function temperature_api()
{
$result = array();
exec("/sbin/sysctl -a | grep temperature", $sysctlOutput);
foreach ($sysctlOutput as $sysctl) {
$parts = explode(':', $sysctl);
foreach (explode("\n", configd_run('system temp')) as $sysctl) {
$parts = explode('=', $sysctl);
if (count($parts) >= 2) {
$tempItem = array();
$tempItem['device'] = $parts[0];
@ -45,8 +45,9 @@ function temperature_api()
$result[] = $tempItem;
}
}
usort($result, function ($item1, $item2) {
return strcmp(strtolower($item1['device']), strtolower($item2['device']));
return strcmp(strtolower($item1['device']), strtolower($item2['device']));
});
return $result;