Skip to content

Commit

Permalink
task292 - modified the script and add more information in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad Nateghi committed Sep 5, 2024
1 parent ae46807 commit b662f2e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 33 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,23 @@ Sample output:

### check cputemp

in order to work this check properly, the amdtemp should be selected under the System > Settings > Miscellaneous > Thermal Sensors > amdtemp
Make sure you configure your OPNsense router as follows:

Modify the /boot/loader.conf file and add the following entries:

coretemp_load="YES" or amdtemp_load="YES"
It's also acceptable to have both entries in your configuration.

In some cases, if the script does not recognize the thermal sensor, you can manually switch it to either amdtemp or coretemp via the GUI.

To do this, navigate to: System > Settings > Miscellaneous > Thermal Sensors > Hardware

Alternatively, you can set this configuration using the OPNsense role under general settings:
opn_general:
system/webgui/thermal_hardware: "amdtemp"

Troubleshoot the functionality of your thermal sensors by using this command on your opnsense:
sysctl -a | grep temperature

## Plugins
The role includes some (optional) plugins
Expand Down
65 changes: 33 additions & 32 deletions files/cputemp.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
#!/usr/local/bin/bash

declare -i ECODE=0
declare STATUS="OK"
declare TXT=""
declare temp_warn=60
declare temp_crit=80

# Read the temperature from sysctl
if sysctl -a | grep -q dev.amdtemp.0.core0.sensor0; then
temp="$(sysctl -a | grep dev.amdtemp.0.core0.sensor0 | awk '{print $2}' | sed 's/.$//')"
STATUS="$temp°C"
else
# If no temperature is found
STATUS="UNKNOWN"
ECODE=3
TXT="Cannot measure temperature"
fi
# Function to display temperatures for all found sensors of a specific type
display_temps() {
local sensor_pattern=$1
local description=$2

# Convert temperature to integer for comparison, if needed
temp_int=$(echo "$temp" | awk '{printf "%.0f", $1}')
# Collect all relevant sensor readings
sysctl -a | grep -E "$sensor_pattern" | while read sensor_data; do
local sensor_id=$(echo $sensor_data | awk '{print $1}')
local temp=$(echo $sensor_data | awk '{print $2}' | sed 's/C//') # Removing 'C' from '44.0C'
local temp_int=$(echo "$temp" | awk '{printf "%.0f", $1}')
local ECODE=0
local TXT="CPU Temp normal"

# Debug output
echo "Temperature read: $temp_float"
echo "Warning threshold: $temp_warn"
echo "Critical threshold: $temp_crit"

# Use bc for floating-point comparisons
if (( $(echo "$temp >= $temp_crit" | bc -l) )); then
ECODE=2
TXT="CPU Temp critical"
elif (( $(echo "$temp >= $temp_warn" | bc -l) )); then
ECODE=1
TXT="CPU Temp warning"
# Determine status based on temperature thresholds
if (( $(echo "$temp >= $temp_crit" | bc -l) )); then
ECODE=2
TXT="CPU Temp critical"
elif (( $(echo "$temp >= $temp_warn" | bc -l) )); then
ECODE=1
TXT="CPU Temp warning"
fi
echo "$ECODE CPUTEMP - temperature is $temp°C - $TXT"
done
}
# Main script execution to check different sensor types
# Check AMD temperature sensors
if sysctl -a | grep -q 'dev.amdtemp.0.core0.sensor0'; then
display_temps 'dev.amdtemp.[0-9]+.core[0-1].sensor[0-1]' "AMD CPU Sensor"
# Check Intel CPU temperature sensors
elif sysctl -a | grep -q 'dev.cpu.0.temperature'; then
display_temps 'dev.cpu.[0-9]+.temperature' "Intel CPU Sensor"
# Check PCH temperature sensors, if any
elif sysctl -a | grep -q 'dev.pchtherm.0.temperature'; then
display_temps 'dev.pchtherm.[0-9]+.temperature' "PCH Sensor"
else
TXT="CPU Temp normal"
echo "3 CPUTEMP - UNKNOWN - No thermal sensors found or active"
fi

# Output result and exit with appropriate code
echo "$ECODE CPUTEMP - $STATUS - $TXT"
exit $ECODE

0 comments on commit b662f2e

Please sign in to comment.