Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 並停止容器。

## 先看懂它如何工作

Expand Down
10 changes: 9 additions & 1 deletion src/FanControlWithEsxiSmart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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}"
Expand Down
35 changes: 35 additions & 0 deletions tests/fan-control.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading