From 4044144a8e9efaf4a9a97e51bd392e3dd144f7e0 Mon Sep 17 00:00:00 2001 From: Catalina Date: Thu, 24 Sep 2026 23:55:18 +0800 Subject: [PATCH] fix: reject implausible temperature readings Restore the R730xd/iDRAC 8 hardware disclaimer, reject unsafe telemetry before fan decisions, and restore Dell automatic control after a partial IPMI write failure. --- README.md | 2 +- README.zh-TW.md | 2 +- src/FanControlWithEsxiSmart.sh | 10 +++++++++- tests/fan-control.test.sh | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e314cc0..86b24e5 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ A fan controller for Dell PowerEdge servers. It sets the fan duty cycle through iDRAC IPMI OEM raw commands, then selects a fan-curve level from pluggable temperature sources: ESXi NVMe SMART, iDRAC sensors, local Linux disks, and local or remote NVIDIA GPUs. > [!CAUTION] -> This program temporarily overrides Dell's automatic fan control. During initial setup, keep the iDRAC Web UI or a physical console available. Verify `manual`, `restore`, and `diagnose` before running `auto` for an extended period. If the server overheats, readings become unreliable, or behavior is abnormal, run `restore` immediately and stop the container. +> This project has been tested on only my Dell PowerEdge R730xd with iDRAC 8. Other server models and iDRAC firmware versions are untested and must not be assumed compatible. This program temporarily overrides Dell's automatic fan control; use it at your own risk. During initial setup, keep the iDRAC Web UI or a physical console available. Verify `manual`, `restore`, and `diagnose` on your own hardware before running `auto` for an extended period. If the server overheats, readings become unreliable, or behavior is abnormal, run `restore` immediately and stop the container. ## How it works diff --git a/README.zh-TW.md b/README.zh-TW.md index f7870f5..d90b73e 100644 --- a/README.zh-TW.md +++ b/README.zh-TW.md @@ -9,7 +9,7 @@ 這是一個給 Dell PowerEdge 使用的風扇控制器。它透過 iDRAC 的 IPMI OEM raw command 設定 fan duty cycle,再以可插拔溫度來源決定風扇曲線:ESXi NVMe SMART、iDRAC sensor、本機 Linux 磁碟,以及本機或遠端 NVIDIA GPU。 > [!CAUTION] -> 這個程式會暫時覆寫 Dell 原廠風扇控制。第一次設定請保留 iDRAC Web UI 或實體主控台,先用 `manual`、`restore`、`diagnose` 驗證,再讓 `auto` 長時間執行。任何過熱、讀值不可信或行為異常時,立即執行 `restore` 並停止容器。 +> 本專案只在我自己的 Dell PowerEdge R730xd(iDRAC 8)上實機測試過;其他伺服器型號與 iDRAC 韌體版本均未驗證,不應假設相容。這個程式會暫時覆寫 Dell 原廠風扇控制,使用風險由使用者自行承擔。第一次設定請保留 iDRAC Web UI 或實體主控台,務必先在自己的硬體上用 `manual`、`restore`、`diagnose` 驗證,再讓 `auto` 長時間執行。任何過熱、讀值不可信或行為異常時,立即執行 `restore` 並停止容器。 ## 先看懂它如何工作 diff --git a/src/FanControlWithEsxiSmart.sh b/src/FanControlWithEsxiSmart.sh index c4e3f1a..bb18c1c 100755 --- a/src/FanControlWithEsxiSmart.sh +++ b/src/FanControlWithEsxiSmart.sh @@ -496,7 +496,11 @@ set_fan_speed() { log "INFO" "Setting fan speed to ${fan_speed}% (0x${hex_speed})" run_ipmitool raw 0x30 0x30 0x01 0x00 || return 1 - run_ipmitool raw 0x30 0x30 0x02 0xff "0x${hex_speed}" + if ! run_ipmitool raw 0x30 0x30 0x02 0xff "0x${hex_speed}"; then + log "ERROR" "Fan speed command failed after manual control was enabled; attempting to restore Dell automatic control" + restore_auto_control || log "ERROR" "Emergency restore of Dell automatic fan control failed" + return 1 + fi } restore_auto_control() { @@ -901,6 +905,10 @@ calculate_decision_temperature() { while IFS=$'\t' read -r source label temp; do [[ -z "${source:-}" || -z "${temp:-}" ]] && continue is_integer "$temp" || continue + if (( temp < -20 || temp > 150 )); then + log "WARN" "Temperature source '${source}' returned an implausible reading for ${label}: ${temp}C" + continue + fi if ! adjusted="$(temperature_source_method "$source" adjust "$temp")" || ! is_integer "$adjusted"; then log "WARN" "Temperature source '${source}' returned an invalid adjusted value for ${label}" diff --git a/tests/fan-control.test.sh b/tests/fan-control.test.sh index 5c5c17d..00ef328 100755 --- a/tests/fan-control.test.sh +++ b/tests/fan-control.test.sh @@ -81,6 +81,25 @@ test_hex_formatting() { assert_eq "05" "$(fan_speed_to_hex 5)" "pads single digit fan speeds for IPMI raw command" } +test_fan_speed_failure_restores_automatic_control() { + local -a commands=() + local original_run_ipmitool + + original_run_ipmitool="$(declare -f run_ipmitool)" + DRY_RUN=false + run_ipmitool() { + commands+=("$*") + [[ "$*" != "raw 0x30 0x30 0x02 0xff 0x23" ]] + } + + set_fan_speed 35 >/dev/null 2>&1 && fail "set_fan_speed should fail when the duty command fails" + assert_eq "raw 0x30 0x30 0x01 0x00" "${commands[0]}" "enables manual control first" + assert_eq "raw 0x30 0x30 0x02 0xff 0x23" "${commands[1]}" "attempts the requested duty cycle" + assert_eq "raw 0x30 0x30 0x01 0x01" "${commands[2]}" "restores Dell automatic control after a partial failure" + eval "$original_run_ipmitool" + DRY_RUN=true +} + test_remote_quote_handles_single_quotes() { assert_eq "'abc'\\''def'" "$(remote_quote "abc'def")" "quotes ESXi device IDs for remote shell" } @@ -163,6 +182,20 @@ test_decision_temperature_uses_max_adjusted_source() { assert_contains "gpu:gpu0=90C(adjusted=75C)" "$decision" "records adjusted GPU detail" } +test_decision_temperature_rejects_implausible_readings() { + local decision + + LINUX_DISK_TEMP_OFFSET=0 + REMOTE_GPU_TEMP_OFFSET=15 + decision="$(calculate_decision_temperature $'linux_disk\tnvme0\t11759\nremote_gpu\tgpu-vm/gpu0\t49')" + + assert_contains $'34\t' "$decision" "ignores an implausible SMART temperature" + if [[ "$decision" == *"11759"* ]]; then + fail "implausible readings must not appear in the accepted decision details" + fi + pass +} + test_linux_disk_source_collects_multiple_devices_and_accepts_smart_warning_status() { local output @@ -523,12 +556,14 @@ test_diagnose_reports_read_only_source_and_preview() { test_normalize_sources test_temperature_sources_share_complete_interface test_hex_formatting +test_fan_speed_failure_restores_automatic_control test_remote_quote_handles_single_quotes test_esxi_password_is_not_in_process_arguments test_temperature_levels test_hysteresis_only_delays_downshift test_idrac_sensor_parsing test_decision_temperature_uses_max_adjusted_source +test_decision_temperature_rejects_implausible_readings test_linux_disk_source_collects_multiple_devices_and_accepts_smart_warning_status test_smartctl_json_parser_supports_nvme_and_generic_temperature test_remote_gpu_source_collects_multiple_hosts