feat(sensors): labeled per-zone thermal layer in lmsensors-extend [#736]

Hosts opt in via /etc/snmp/lmsensors-zone-types (one zone type per
line, e.g. Jetson GPU-therm); each type renders its own zone-<type>
chip block so HA templates anchor on the chip name. Default behavior
unchanged; no snmpd restarts (extend re-execs per poll).
This commit is contained in:
2026-09-02 21:16:34 -05:00
parent c71d66e129
commit 6414fee6ec
@@ -134,6 +134,32 @@ format_sysfs_block() {
done <<<"$input" done <<<"$input"
} }
# Labeled per-zone temps (e.g. Jetson GPU-therm) [#736]. Hosts opt in by
# listing zone types (one per line) in /etc/snmp/lmsensors-zone-types; no
# snmpd.conf change or restart needed (extend re-execs per poll). Each type
# renders its own chip block so HA templates can anchor on the chip name.
ZONE_TYPES_FILE="${ZONE_TYPES_FILE:-/etc/snmp/lmsensors-zone-types}"
format_labeled_zones() {
local z type mc want signed
[[ -r "$ZONE_TYPES_FILE" ]] || return 1
while IFS= read -r want; do
want="${want%%#*}"; want="${want//[[:space:]]/}"
[[ -n "$want" ]] || continue
for z in "$SYSFS_THERMAL_ROOT"/thermal_zone[0-9]*; do
[[ -r "$z/type" && -r "$z/temp" ]] || continue
[[ "$(<"$z/type")" == "$want" ]] || continue
mc="$(<"$z/temp")"
[[ "$mc" =~ ^-?[0-9]+$ ]] || continue
signed="$(awk -v mc="$mc" 'BEGIN { printf "%.1f", mc / 1000 }')"
signed="${signed#+}"
[[ "$signed" == -* ]] || signed="+$signed"
printf 'zone-%s-virtual-0\nAdapter: Virtual device\ntemp1: %s°C\n\n' "$want" "$signed"
done
done <"$ZONE_TYPES_FILE"
return 0
}
main() { main() {
local out="" block internal external native="" sysinput local out="" block internal external native="" sysinput
if native="$(run_native_sensors)" && [[ -n "$native" ]]; then if native="$(run_native_sensors)" && [[ -n "$native" ]]; then
@@ -155,6 +181,9 @@ main() {
&& block="$(format_sysfs_block "$sysinput")"; then && block="$(format_sysfs_block "$sysinput")"; then
out+="$block"$'\n' out+="$block"$'\n'
fi fi
if block="$(format_labeled_zones)" && [[ -n "$block" ]]; then
out+="$block"$'\n'
fi
[[ -n "$out" ]] || { [[ -n "$out" ]] || {
echo "error: no sensor sources available (lm-sensors pkg? TEMPer venv? sysfs thermal?)" >&2 echo "error: no sensor sources available (lm-sensors pkg? TEMPer venv? sysfs thermal?)" >&2
return 1 return 1