Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Keep non-temperature sensor inputs out of Celsius readings
pulse-triage[bot]66fa10fd1a10
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 9abaf7ef0b..bbe09d599c 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -17,6 +17,26 @@## Purpose+### Sensor units come from native subfeature keys++Only `tempN_input` keys (one or more ASCII digits) supply Celsius in the shared+Linux agent parser and the server's direct/SSH temperature parser. Arbitrary+feature labels, fan RPM, voltage, current, power, energy, frequency and humidity+inputs cannot become temperatures. Mixed feature maps keep their real+`tempN_input` regardless of iteration order. The existing numeric/string and+millidegree handling, CPU/core/GPU/NVMe identity, additional-temperature filters,+fan RPM and missing-data semantics are unchanged. No sensor selection, thresholds,+History, hardware probe or permission is added.++`internal/sensors/temperature_input.go` owns the shared unit discriminator used+by `internal/sensors/parser.go` and `internal/monitoring/temperature.go`.+`temperature_input_test.go`, `parser_units_test.go`, `temperature_test.go` and+`TestAgentMixedSensorUnitsReachReportWithoutFalseTemperatures` cover rejected+units (including misleading CPU/GPU labels), accepted mixed measurements and a+complete report from the real parser/agent path. The inferred #3565 sensor+fixture is not an original JSON export or installed-host recovery. Consuming+proof must use the complete emitted report, not a selected-value subset.+### Background backup scans belong to their configured connectionPVE tasks, storage backups and guest snapshots share one in-flight owner perdiff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.jsonindex 7bc276c1ee..9984f6cfb6 100644--- a/docs/release-control/v6/internal/subsystems/registry.json+++ b/docs/release-control/v6/internal/subsystems/registry.json@@ -6407,6 +6407,8 @@"internal/models/models_frontend.go","internal/models/proxmox_guest_state.go","internal/proxmoxidentity/backup_identity.go",+ "internal/sensors/parser.go",+ "internal/sensors/temperature_input.go","pkg/agents/docker/report.go","pkg/agents/host/report.go","pkg/agents/kubernetes/report.go",@@ -6426,6 +6428,24 @@"exact_files": [],"require_explicit_path_policy_coverage": true,"path_policies": [+ {+ "id": "temperature-input-units",+ "label": "native lm-sensors unit admission and complete host report proof",+ "match_prefixes": [],+ "match_files": [+ "internal/monitoring/temperature.go",+ "internal/sensors/parser.go",+ "internal/sensors/temperature_input.go"+ ],+ "allow_same_subsystem_tests": false,+ "test_prefixes": [],+ "exact_files": [+ "internal/hostagent/agent_sensors_test.go",+ "internal/monitoring/temperature_test.go",+ "internal/sensors/parser_units_test.go",+ "internal/sensors/temperature_input_test.go"+ ]+ },{"id": "pve-backup-poll-ownership","label": "connection-scoped single-flight backup scan and late publication proof",diff --git a/internal/hostagent/agent_sensors_test.go b/internal/hostagent/agent_sensors_test.goindex a4b9919cee..0b2fd7fcd7 100644--- a/internal/hostagent/agent_sensors_test.go+++ b/internal/hostagent/agent_sensors_test.go@@ -2,12 +2,15 @@ package hostagentimport ("context"+ "encoding/json""errors""os""os/exec"+ "reflect""testing""github.com/rcourtman/pulse-go-rewrite/internal/sensors"+ agentshost "github.com/rcourtman/pulse-go-rewrite/pkg/agents/host""github.com/rs/zerolog")@@ -431,3 +434,31 @@ dev.cpu.3.temperature: 55.0Ct.Fatalf("expected cpu_core_3=55.0, got %v", got.TemperatureCelsius["cpu_core_3"])}}++func TestAgentMixedSensorUnitsReachReportWithoutFalseTemperatures(t *testing.T) {+ input, err := os.ReadFile("../sensors/testdata/mixed_sensor_units.json")+ if err != nil {+ t.Fatal(err)+ }+ mc := &mockCollector{+ goos: "linux",+ sensorsLocalFn: func(context.Context) (string, error) { return string(input), nil },+ sensorsParseFn: sensors.Parse,+ }+ got := (&Agent{logger: zerolog.Nop(), collector: mc}).collectTemperatures(context.Background())+ want := agentshost.Sensors{+ TemperatureCelsius: map[string]float64{"cpu_package": 91, "cpu_core_0": 87, "nvme0": 36.9, "amdgpu-pci-0300_edge": 58},+ FanRPM: map[string]float64{"applesmc_left_side": 6152, "applesmc_right_side": 5699},+ Additional: map[string]float64{"applesmc_tb0t": 34.2, "applesmc_tb1t": 29.2, "applesmc_th1h": 44.5},+ }+ if !reflect.DeepEqual(want, got) {+ t.Fatalf("full sensor report = %+v, want %+v", got, want)+ }+ if os.Getenv("PULSE_SENSOR_UNITS_FRAME") == "1" {+ data, err := json.Marshal(got)+ if err != nil {+ t.Fatal(err)+ }+ t.Log("SENSOR_UNITS_FRAME=" + string(data))+ }+}diff --git a/internal/monitoring/temperature.go b/internal/monitoring/temperature.goindex 3d0546018e..51d87ad680 100644--- a/internal/monitoring/temperature.go+++ b/internal/monitoring/temperature.go@@ -17,6 +17,7 @@ import ("time""github.com/rcourtman/pulse-go-rewrite/internal/models"+ "github.com/rcourtman/pulse-go-rewrite/internal/sensors""github.com/rcourtman/pulse-go-rewrite/internal/system""github.com/rs/zerolog/log")@@ -1009,7 +1010,7 @@ func (tc *TemperatureCollector) parseNouveauGPUTemps(chipName string, chipMap mafunc extractTempInput(sensorMap map[string]interface{}) float64 {// Look for temp*_input fieldsfor key, val := range sensorMap {- if strings.HasSuffix(key, "_input") {+ if sensors.IsTemperatureInput(key) {switch v := val.(type) {case float64:return vdiff --git a/internal/monitoring/temperature_test.go b/internal/monitoring/temperature_test.goindex 55d4efeeff..56fc844f34 100644--- a/internal/monitoring/temperature_test.go+++ b/internal/monitoring/temperature_test.go@@ -4,6 +4,7 @@ import ("context""errors""fmt"+ "math""os""os/exec""strings"@@ -311,3 +312,31 @@ func buildExitErrorWithStderr(t *testing.T, stderr string) error {return err}++func TestExtractTempInputKeepsSensorUnits(t *testing.T) {+ for _, key := range []string{"fan1_input", "in1_input", "curr1_input", "power1_input", "freq1_input", "energy1_input", "temperature_input"} {+ for _, value := range []any{6152.0, 45, "+45.0°C"} {+ assert.True(t, math.IsNaN(extractTempInput(map[string]any{key: value})), "%s must not become Celsius", key)+ }+ }+ for range 32 {+ assert.Equal(t, 34.2, extractTempInput(map[string]any{"fan1_input": 6152.0, "in1_input": 12.1, "temp12_input": 34.2}))+ }+}++func TestTemperatureCollectorNonTemperatureInputIsNotTypedTemperature(t *testing.T) {+ for _, input := range []string{+ `{"coretemp-isa-0000":{"Package id 0":{"fan1_input":6152},"Core 0":{"in1_input":12.1}}}`,+ `{"nvme-pci-0200":{"Composite":{"power1_input":45}}}`,+ `{"amdgpu-pci-0300":{"edge":{"curr1_input":2.5}}}`,+ `{"nouveau-pci-0400":{"GPU core":{"freq1_input":2400}}}`,+ } {+ got, err := (&TemperatureCollector{}).parseSensorsJSON(input)+ require.NoError(t, err)+ assert.Zero(t, got.CPUPackage)+ assert.Zero(t, got.CPUMax)+ assert.Empty(t, got.Cores)+ assert.Empty(t, got.NVMe)+ assert.Empty(t, got.GPU)+ }+}diff --git a/internal/sensors/parser.go b/internal/sensors/parser.goindex d5f521cb5f..7f0eca4da5 100644--- a/internal/sensors/parser.go+++ b/internal/sensors/parser.go@@ -273,7 +273,7 @@ func parseGPUTemps(chipName string, chipMap map[string]interface{}, data *Temperfunc extractTempInput(sensorMap map[string]interface{}) float64 {// Look for temp*_input field (the actual temperature reading)for key, value := range sensorMap {- if strings.HasSuffix(key, "_input") {+ if IsTemperatureInput(key) {switch v := value.(type) {case float64:return normalizeTemperatureValue(v)diff --git a/internal/sensors/parser_units_test.go b/internal/sensors/parser_units_test.gonew file mode 100644index 0000000000..3bb9a9f21a--- /dev/null+++ b/internal/sensors/parser_units_test.go@@ -0,0 +1,79 @@+package sensors++import (+ "encoding/json"+ "math"+ "os"+ "testing"++ "github.com/stretchr/testify/require"+)++func TestExtractTempInputKeepsUnits(t *testing.T) {+ for _, key := range []string{"fan1_input", "in1_input", "curr1_input", "power1_input", "freq1_input", "energy1_input", "humidity1_input", "temperature_input"} {+ for _, value := range []any{6152.0, 45, "+45.0°C"} {+ require.True(t, math.IsNaN(extractTempInput(map[string]any{key: value})), "%s must not become Celsius", key)+ }+ }+ // The true subfeature, not map iteration order or a displayed label,+ // supplies the value when a feature includes measurements in other units.+ for range 32 {+ require.Equal(t, 34.2, extractTempInput(map[string]any{"fan1_input": 6152.0, "in1_input": 12.1, "temp12_input": 34.2}))+ }+}++func TestParseMixedSensorUnits(t *testing.T) {+ // Inferred lm-sensors JSON based on #3565's human-readable output, with+ // explicit non-temperature controls. This is not an original host export.+ input, err := os.ReadFile("testdata/mixed_sensor_units.json")+ require.NoError(t, err)+ got, err := Parse(string(input))+ require.NoError(t, err)+ require.Equal(t, &TemperatureData{+ CPUPackage: 91, CPUMax: 91, Available: true,+ Cores: map[string]float64{"Core 0": 87},+ NVMe: map[string]float64{"nvme0": 36.9},+ GPU: map[string]float64{"amdgpu-pci-0300_edge": 58},+ Fans: map[string]float64{"applesmc_left_side": 6152, "applesmc_right_side": 5699},+ Other: map[string]float64{"applesmc_tb0t": 34.2, "applesmc_tb1t": 29.2, "applesmc_th1h": 44.5},+ }, got, "compare the complete report, not only selected expected readings")+}++func TestParseNonTemperatureInputsCannotImpersonateTypedReadings(t *testing.T) {+ for _, chip := range []struct{ name, label string }{+ {"coretemp-isa-0000", "Package id 0"},+ {"coretemp-isa-0000", "Core 0"},+ {"k10temp-pci-00c3", "Tctl"},+ {"nvme-pci-0200", "Composite"},+ {"amdgpu-pci-0300", "edge"},+ {"nouveau-pci-0400", "edge"},+ {"applesmc-isa-0300", "TB0T"},+ } {+ for _, key := range []string{"fan1_input", "in1_input", "curr1_input", "power1_input", "freq1_input"} {+ t.Run(chip.name+"/"+chip.label+"/"+key, func(t *testing.T) {+ input, err := json.Marshal(map[string]any{chip.name: map[string]any{chip.label: map[string]any{key: 45.0}}})+ require.NoError(t, err)+ got, err := Parse(string(input))+ require.NoError(t, err)+ require.Zero(t, got.CPUPackage)+ require.Zero(t, got.CPUMax)+ require.Empty(t, got.Cores)+ require.Empty(t, got.NVMe)+ require.Empty(t, got.GPU)+ require.Empty(t, got.Other)+ })+ }+ }+}++func TestParseNonTemperatureOnlyKeepsMissingDataSemantics(t *testing.T) {+ got, err := Parse(`{"board-isa-0000":{"Supply":{"in1_input":12.1},"Power":{"power1_input":45}}}`)+ require.NoError(t, err)+ require.False(t, got.Available, "non-temperature inputs must not invent temperature availability")+ got, err = Parse(`{"board-isa-0000":{"Fan":{"fan1_input":6152}}}`)+ require.NoError(t, err)+ require.True(t, got.Available, "existing fan-only availability stays supported")+ require.Equal(t, map[string]float64{"board_fan": 6152}, got.Fans)+ require.Empty(t, got.Other)+ require.Zero(t, got.CPUPackage, "fan-only output must not invent a CPU source")+}diff --git a/internal/sensors/temperature_input.go b/internal/sensors/temperature_input.gonew file mode 100644index 0000000000..d358fc9f45--- /dev/null+++ b/internal/sensors/temperature_input.go@@ -0,0 +1,19 @@+package sensors++import "strings"++// IsTemperatureInput identifies an lm-sensors temperature subfeature by its+// native tempN_input key. The displayed feature label can be arbitrary; a+// fan, voltage, current or power input does not acquire Celsius units from it.+func IsTemperatureInput(key string) bool {+ index := strings.TrimSuffix(strings.TrimPrefix(key, "temp"), "_input")+ if index == "" || key != "temp"+index+"_input" {+ return false+ }+ for _, digit := range index {+ if digit < '0' || digit > '9' {+ return false+ }+ }+ return true+}diff --git a/internal/sensors/temperature_input_test.go b/internal/sensors/temperature_input_test.gonew file mode 100644index 0000000000..7d64a8abb4--- /dev/null+++ b/internal/sensors/temperature_input_test.go@@ -0,0 +1,16 @@+package sensors++import "testing"++func TestIsTemperatureInput(t *testing.T) {+ for _, key := range []string{"temp1_input", "temp12_input", "temp999_input"} {+ if !IsTemperatureInput(key) {+ t.Errorf("temperature key %q rejected", key)+ }+ }+ for _, key := range []string{"", "fan1_input", "in1_input", "curr1_input", "power1_input", "freq1_input", "energy1_input", "humidity1_input", "temp1_max", "temp1_crit", "temp1_label", "temp_input", "temperature_input", "temp-1_input", "temp1_input", "Temp1_input", "temp1_input_extra", "prefix_temp1_input"} {+ if IsTemperatureInput(key) {+ t.Errorf("non-temperature key %q admitted as Celsius", key)+ }+ }+}diff --git a/internal/sensors/testdata/mixed_sensor_units.json b/internal/sensors/testdata/mixed_sensor_units.jsonnew file mode 100644index 0000000000..03f03c22b9--- /dev/null+++ b/internal/sensors/testdata/mixed_sensor_units.json@@ -0,0 +1,24 @@+{+ "applesmc-isa-0300": {+ "Adapter": "ISA adapter",+ "TB0T": {"temp1_input": 34.2},+ "TB1T": {"temp2_input": 29.2},+ "Th1H": {"temp3_input": 44.5},+ "TG1D": {"temp4_input": -127},+ "TCMc": {"temp5_input": 0},+ "Left side": {"fan1_input": 6152, "fan1_min": 2160, "fan1_max": 6156},+ "Right side": {"fan2_input": 5699, "fan2_min": 2000, "fan2_max": 5700},+ "Supply": {"in1_input": 12.1},+ "Battery current": {"curr1_input": 2.5},+ "Battery power": {"power1_input": 45},+ "Clock": {"freq1_input": 2400},+ "Energy": {"energy1_input": 42000},+ "Humidity": {"humidity1_input": 40}+ },+ "coretemp-isa-0000": {+ "Package id 0": {"temp1_input": 91},+ "Core 0": {"temp2_input": 87}+ },+ "nvme-pci-0200": {"Composite": {"temp1_input": 36.9}},+ "amdgpu-pci-0300": {"edge": {"temp1_input": 58}}+}