Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

feat(agent): collect Windows CPU temperatures via LHM

[email protected]5226e3292af5
diff --git a/docs/TEMPERATURE_MONITORING.md b/docs/TEMPERATURE_MONITORING.md
index 0b31a74121..c7435ce4d6 100644
--- a/docs/TEMPERATURE_MONITORING.md
+++ b/docs/TEMPERATURE_MONITORING.md
@@ -21,16 +21,30 @@ Notes:
- Temperatures appear automatically once the agent reports.
- When a Proxmox host has recent usable agent temperature data, Pulse treats the agent as the source of truth and does not also try SSH temperature collection for that host.
-## Windows NVIDIA GPU temperatures
+## Windows temperatures
On Windows hosts with an NVIDIA driver, the unified agent uses the driver's
`nvidia-smi` executable to report GPU temperature, utilization, and VRAM
usage. No extra Pulse configuration is required; `nvidia-smi.exe` must be
available on the agent service's `PATH`.
-Windows does not provide a dependable built-in API for CPU, motherboard, or
-storage temperature sensors. Pulse does not report those readings on Windows
-unless and until a qualified driver-backed provider is available.
+Supported physical disks are read separately through Windows Storage
+reliability counters. Missing counters or unsupported devices are simply
+omitted.
+
+Windows does not provide a dependable built-in API for CPU or motherboard
+temperatures. For those readings, install and run
+[LibreHardwareMonitor](https://github.com/LibreHardwareMonitor/LibreHardwareMonitor)
+as Administrator, leave its port at `8085`, and enable
+**Options → Remote Web Server → Run**. Do not allow inbound network access to
+port `8085` in Windows Firewall; Pulse reads only the local
+`http://127.0.0.1:8085/data.json` endpoint. Web authentication must be disabled
+for this loopback integration.
+
+Pulse accepts only bounded CPU and motherboard Celsius readings from that
+endpoint. It ignores LibreHardwareMonitor disk and GPU nodes so the native
+Windows Storage and `nvidia-smi` providers remain authoritative. If the helper
+is absent or unavailable, the rest of the Windows report is unaffected.
## SSH-Based Collection (Fallback)
diff --git a/docs/UNIFIED_AGENT.md b/docs/UNIFIED_AGENT.md
index f4110e4457..5f81e8025d 100644
--- a/docs/UNIFIED_AGENT.md
+++ b/docs/UNIFIED_AGENT.md
@@ -115,6 +115,30 @@ successful inventory while normal host metrics continue to report.
This local integration covers one XCP-ng pool. Multi-pool deployments that
need a central Xen Orchestra connection remain a separate integration surface.
+### Windows CPU and motherboard temperatures
+
+Windows does not expose dependable built-in CPU or motherboard temperature
+readings. The Unified Agent can import those readings from
+[LibreHardwareMonitor](https://github.com/LibreHardwareMonitor/LibreHardwareMonitor),
+which supplies the required driver-backed hardware access:
+
+1. Run LibreHardwareMonitor as Administrator on the Windows host.
+2. Keep its HTTP port at the default `8085`.
+3. Select **Options → Remote Web Server → Run**.
+4. Do not permit inbound network access to port `8085` in Windows Firewall.
+ Pulse connects only to `http://127.0.0.1:8085/data.json`.
+
+LibreHardwareMonitor's web authentication must remain disabled for this
+loopback-only integration. Pulse uses a fixed local URL, follows no redirects,
+and accepts only bounded, validated CPU and motherboard Celsius readings.
+If LibreHardwareMonitor is stopped, unavailable, or returns unsupported data,
+the rest of the Windows host report continues normally.
+
+Native Windows Storage reliability counters remain the source for supported
+physical-disk temperatures. NVIDIA GPU telemetry continues to come directly
+from `nvidia-smi`; Pulse deliberately ignores LibreHardwareMonitor GPU and
+storage nodes to avoid duplicate or ambiguously correlated readings.
+
## External Probes (Pro)
With the Pro `external_probe` entitlement, availability checks configured in
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 98b150a2e4..5a85756547 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -1504,7 +1504,22 @@ the intentionally sparse public response.
counters, malformed output, and unsupported devices omit that telemetry
without failing the host report. This path must not use ACPI thermal zones,
infer disk health, execute server-authored PowerShell, or imply support for
- CPU or motherboard temperatures. The report must keep typed GPU readings in
+ CPU or motherboard temperatures.
+ Windows CPU and motherboard Celsius readings may come only from the
+ explicitly qualified, driver-backed LibreHardwareMonitor path in
+ `internal/hostagent/windows_librehardwaremonitor.go`. Production collection
+ must issue one unauthenticated two-second GET to the fixed loopback
+ `http://127.0.0.1:8085/data.json` endpoint, bypass proxies, reject redirects
+ and non-success responses, and cap the body at one MiB. Parsing must bound
+ node count, tree depth, sensor count, and key length; accept only finite
+ direct Celsius values in the supported range from CPU or motherboard
+ hardware identifiers; and ignore GPU, storage, unknown, malformed, or
+ unclassified nodes. An absent, stopped, authenticated, or incompatible
+ helper must omit these readings without failing the host report. The agent
+ must not poll a server-authored address, accept ACPI thermal zones as a
+ substitute, expose LibreHardwareMonitor lifecycle or hardware-control
+ authority, or displace the native Windows Storage and NVIDIA providers.
+ The report must keep typed GPU readings in
`sensors.gpu` while mapping only direct `temperature.gpu` readings into
existing `sensors.temperatureCelsius` `gpu_nvidia_<index>` keys for
compatibility.
@@ -5720,3 +5735,14 @@ text fields. Dataset collection does not broaden registration, token,
configuration, update, or command authority. Servers validate and copy the
optional evidence during normal authenticated host-report ingest; agents that
do not send it remain wire-compatible.
+
+### Windows CPU and motherboard temperatures require a local qualified provider
+
+Windows Unified Agents now supplement native Storage reliability counters and
+direct NVIDIA telemetry with CPU and motherboard Celsius readings from a
+running local LibreHardwareMonitor instance. The integration is optional and
+read-only: it polls only the fixed loopback `data.json` endpoint, admits only
+bounded and classified temperature nodes, and leaves the host report intact
+when the helper is absent or incompatible. It does not treat Windows ACPI
+thermal zones as hardware sensor evidence, accept remote provider locations,
+or grant Pulse hardware-control authority.
diff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.go
index ced33f634c..d775bc2721 100644
--- a/internal/hostagent/agent.go
+++ b/internal/hostagent/agent.go
@@ -168,6 +168,9 @@ type Agent struct {
availability *availabilityProbeModule
reportStreamID string
reportSequence atomic.Uint64
+ // libreHardwareMonitorEndpoint is an unexported test seam. Production
+ // collection always uses the fixed loopback URL when this is empty.
+ libreHardwareMonitorEndpoint string
// lastAuthFailureLog throttles the actionable 401 error so a permanently
// rejected token does not spam the log every report interval. Only touched
@@ -1578,8 +1581,9 @@ func (a *Agent) collectTemperatures(ctx context.Context) agentshost.Sensors {
return a.collectFreeBSDTemperatures(ctx)
case "windows":
// Windows has no reliable built-in CPU or motherboard temperature API.
- // Its Storage module does expose device-reported physical-disk
- // reliability temperatures, and NVIDIA's driver supplies nvidia-smi.
+ // Pulse accepts those readings only from a local driver-backed
+ // LibreHardwareMonitor instance. The native Storage module supplies
+ // physical-disk temperatures, and NVIDIA's driver supplies nvidia-smi.
return a.collectWindowsTemperatureSensors(ctx)
default:
return agentshost.Sensors{}
diff --git a/internal/hostagent/agent_metrics_test.go b/internal/hostagent/agent_metrics_test.go
index 6e2cd06cbf..86eaa043db 100644
--- a/internal/hostagent/agent_metrics_test.go
+++ b/internal/hostagent/agent_metrics_test.go
@@ -3,6 +3,8 @@ package hostagent
import (
"context"
"errors"
+ "net/http"
+ "net/http/httptest"
"os"
"testing"
"time"
@@ -575,6 +577,30 @@ func TestBuildReportIncludesNVIDIASMITemperaturesWhenLMSensorsUnavailable(t *tes
}
func TestBuildReportIncludesNVIDIASMITelemetryOnWindows(t *testing.T) {
+ libreHardwareMonitor := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
+ if request.URL.Path != "/data.json" {
+ t.Fatalf("LibreHardwareMonitor path = %q, want /data.json", request.URL.Path)
+ }
+ _, _ = response.Write([]byte(`{
+ "Children": [{
+ "HardwareId": "/intelcpu/0",
+ "Children": [{
+ "SensorId": "/intelcpu/0/temperature/0",
+ "Type": "Temperature",
+ "RawValue": 51
+ }]
+ }, {
+ "HardwareId": "/lpc/nct6798d/0",
+ "Children": [{
+ "SensorId": "/lpc/nct6798d/0/temperature/1",
+ "Type": "Temperature",
+ "RawValue": 36
+ }]
+ }]
+ }`))
+ }))
+ t.Cleanup(libreHardwareMonitor.Close)
+
mc := &mockCollector{
goos: "windows",
nowFn: func() time.Time { return time.Date(2026, 7, 30, 18, 0, 0, 0, time.UTC) },
@@ -627,6 +653,7 @@ func TestBuildReportIncludesNVIDIASMITelemetryOnWindows(t *testing.T) {
if err != nil {
t.Fatalf("New() failed: %v", err)
}
+ agent.libreHardwareMonitorEndpoint = libreHardwareMonitor.URL + "/data.json"
report, err := agent.buildReport(context.Background())
if err != nil {
@@ -639,6 +666,12 @@ func TestBuildReportIncludesNVIDIASMITelemetryOnWindows(t *testing.T) {
if report.Sensors.TemperatureCelsius["gpu_nvidia_0"] != 57 {
t.Fatalf("Windows NVIDIA GPU temp = %v, want 57", report.Sensors.TemperatureCelsius["gpu_nvidia_0"])
}
+ if report.Sensors.TemperatureCelsius["cpu_lhm_intelcpu_0_temperature_0"] != 51 {
+ t.Fatalf("Windows CPU temperature = %+v, want LibreHardwareMonitor reading", report.Sensors.TemperatureCelsius)
+ }
+ if report.Sensors.TemperatureCelsius["motherboard_lhm_lpc_nct6798d_0_temperature_1"] != 36 {
+ t.Fatalf("Windows motherboard temperature = %+v, want LibreHardwareMonitor reading", report.Sensors.TemperatureCelsius)
+ }
if len(report.Sensors.GPU) != 1 {
t.Fatalf("Windows GPU stats = %d, want 1: %+v", len(report.Sensors.GPU), report.Sensors.GPU)
}
diff --git a/internal/hostagent/windows_librehardwaremonitor.go b/internal/hostagent/windows_librehardwaremonitor.go
new file mode 100644
index 0000000000..dd8471f7d3
--- /dev/null
+++ b/internal/hostagent/windows_librehardwaremonitor.go
@@ -0,0 +1,241 @@
+package hostagent
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "io"
+ "math"
+ "net/http"
+ "strings"
+ "time"
+
+ agentshost "github.com/rcourtman/pulse-go-rewrite/pkg/agents/host"
+)
+
+const (
+ libreHardwareMonitorDataURL = "http://127.0.0.1:8085/data.json"
+ libreHardwareMonitorQueryTimeout = 2 * time.Second
+ libreHardwareMonitorMaxOutputBytes = 1024 * 1024
+ libreHardwareMonitorMaxNodes = 2048
+ libreHardwareMonitorMaxDepth = 16
+ libreHardwareMonitorMaxSensors = 256
+ libreHardwareMonitorMaxKeyLength = 128
+)
+
+type libreHardwareMonitorNode struct {
+ Text string `json:"Text"`
+ SensorID string `json:"SensorId"`
+ Type string `json:"Type"`
+ RawValue *float64 `json:"RawValue"`
+ HardwareID string `json:"HardwareId"`
+ Children []libreHardwareMonitorNode `json:"Children"`
+}
+
+type libreHardwareMonitorTraversal struct {
+ node *libreHardwareMonitorNode
+ hardwareID string
+ depth int
+}
+
+func (a *Agent) mergeLibreHardwareMonitorTemperatures(ctx context.Context, result *agentshost.Sensors) {
+ endpoint := a.libreHardwareMonitorEndpoint
+ if endpoint == "" {
+ endpoint = libreHardwareMonitorDataURL
+ }
+
+ temperatures, err := collectLibreHardwareMonitorTemperatures(ctx, endpoint)
+ if err != nil {
+ a.logger.Debug().Err(err).Msg("Failed to collect LibreHardwareMonitor temperatures")
+ return
+ }
+ if len(temperatures) == 0 {
+ return
+ }
+
+ if result.TemperatureCelsius == nil {
+ result.TemperatureCelsius = make(map[string]float64, len(temperatures))
+ }
+ for key, value := range temperatures {
+ result.TemperatureCelsius[key] = value
+ }
+
+ a.logger.Debug().
+ Int("sensorCount", len(temperatures)).
+ Msg("Collected LibreHardwareMonitor CPU and motherboard temperatures")
+}
+
+func collectLibreHardwareMonitorTemperatures(ctx context.Context, endpoint string) (map[string]float64, error) {
+ queryCtx, cancel := context.WithTimeout(ctx, libreHardwareMonitorQueryTimeout)
+ defer cancel()
+
+ request, err := http.NewRequestWithContext(queryCtx, http.MethodGet, endpoint, nil)
+ if err != nil {
+ return nil, fmt.Errorf("create local LibreHardwareMonitor request: %w", err)
+ }
+ request.Header.Set("Accept", "application/json")
+
+ client := &http.Client{
+ Timeout: libreHardwareMonitorQueryTimeout,
+ Transport: &http.Transport{
+ Proxy: nil,
+ DisableKeepAlives: true,
+ },
+ CheckRedirect: func(*http.Request, []*http.Request) error {
+ return http.ErrUseLastResponse
+ },
+ }
+ response, err := client.Do(request)
+ if err != nil {
+ return nil, fmt.Errorf("query local LibreHardwareMonitor: %w", err)
+ }
+ defer response.Body.Close()
+
+ if response.StatusCode != http.StatusOK {
+ return nil, fmt.Errorf("local LibreHardwareMonitor returned %s", response.Status)
+ }
+ if response.ContentLength > libreHardwareMonitorMaxOutputBytes {
+ return nil, fmt.Errorf(
+ "LibreHardwareMonitor response exceeds %d bytes",
+ libreHardwareMonitorMaxOutputBytes,
+ )
+ }
+
+ body, err := io.ReadAll(io.LimitReader(response.Body, libreHardwareMonitorMaxOutputBytes+1))
+ if err != nil {
+ return nil, fmt.Errorf("read local LibreHardwareMonitor response: %w", err)
+ }
+ if len(body) > libreHardwareMonitorMaxOutputBytes {
+ return nil, fmt.Errorf(
+ "LibreHardwareMonitor response exceeds %d bytes",
+ libreHardwareMonitorMaxOutputBytes,
+ )
+ }
+
+ temperatures, err := parseLibreHardwareMonitorTemperatures(body)
+ if err != nil {
+ return nil, fmt.Errorf("parse local LibreHardwareMonitor response: %w", err)
+ }
+ return temperatures, nil
+}
+
+func parseLibreHardwareMonitorTemperatures(body []byte) (map[string]float64, error) {
+ var root libreHardwareMonitorNode
+ if err := json.Unmarshal(body, &root); err != nil {
+ return nil, err
+ }
+
+ result := make(map[string]float64)
+ stack := []libreHardwareMonitorTraversal{{node: &root}}
+ nodeCount := 0
+
+ for len(stack) > 0 {
+ last := len(stack) - 1
+ current := stack[last]
+ stack = stack[:last]
+
+ nodeCount++
+ if nodeCount > libreHardwareMonitorMaxNodes {
+ return nil, fmt.Errorf("LibreHardwareMonitor tree exceeds %d nodes", libreHardwareMonitorMaxNodes)
+ }
+ if current.depth > libreHardwareMonitorMaxDepth {
+ return nil, fmt.Errorf("LibreHardwareMonitor tree exceeds depth %d", libreHardwareMonitorMaxDepth)
+ }
+
+ hardwareID := current.hardwareID
+ if candidate := strings.TrimSpace(current.node.HardwareID); candidate != "" {
+ hardwareID = candidate
+ }
+
+ if strings.EqualFold(strings.TrimSpace(current.node.Type), "Temperature") &&
+ current.node.RawValue != nil &&
+ !math.IsNaN(*current.node.RawValue) &&
+ !math.IsInf(*current.node.RawValue, 0) &&
+ *current.node.RawValue > 0 &&
+ *current.node.RawValue <= 150 {
+ if category := classifyLibreHardwareMonitorTemperature(hardwareID); category != "" {
+ key := normalizeLibreHardwareMonitorTemperatureKey(
+ category,
+ current.node.SensorID,
+ )
+ if key != "" {
+ result[key] = *current.node.RawValue
+ if len(result) > libreHardwareMonitorMaxSensors {
+ return nil, fmt.Errorf(
+ "LibreHardwareMonitor response exceeds %d supported temperature sensors",
+ libreHardwareMonitorMaxSensors,
+ )
+ }
+ }
+ }
+ }
+
+ for index := len(current.node.Children) - 1; index >= 0; index-- {
+ stack = append(stack, libreHardwareMonitorTraversal{
+ node: &current.node.Children[index],
+ hardwareID: hardwareID,
+ depth: current.depth + 1,
+ })
+ }
+ }
+
+ if len(result) == 0 {
+ return nil, nil
+ }
+ return result, nil
+}
+
+func classifyLibreHardwareMonitorTemperature(hardwareID string) string {
+ hardwareID = "/" + strings.Trim(strings.ToLower(strings.TrimSpace(hardwareID)), "/") + "/"
+ switch {
+ case strings.Contains(hardwareID, "/intelcpu/"),
+ strings.Contains(hardwareID, "/amdcpu/"),
+ strings.Contains(hardwareID, "/cpu/"):
+ return "cpu"
+ case strings.Contains(hardwareID, "/lpc/"),
+ strings.Contains(hardwareID, "/motherboard/"),
+ strings.Contains(hardwareID, "/superio/"),
+ strings.Contains(hardwareID, "/embeddedcontroller/"):
+ return "motherboard"
+ default:
+ return ""
+ }
+}
+
+func normalizeLibreHardwareMonitorTemperatureKey(category, sensorID string) string {
+ identity := strings.TrimSpace(sensorID)
+ if identity == "" {
+ return ""
+ }
+
+ var normalized strings.Builder
+ normalized.Grow(len(identity))
+ lastUnderscore := false
+ for _, char := range strings.ToLower(identity) {
+ isAlphaNumeric := (char >= 'a' && char <= 'z') || (char >= '0' && char <= '9')
+ if isAlphaNumeric {
+ normalized.WriteRune(char)
+ lastUnderscore = false
+ continue
+ }
+ if !lastUnderscore {
+ normalized.WriteByte('_')
+ lastUnderscore = true
+ }
+ }
+
+ suffix := strings.Trim(normalized.String(), "_")
+ if suffix == "" {
+ return ""
+ }
+ prefix := category + "_lhm_"
+ key := prefix + suffix
+ if len(key) > libreHardwareMonitorMaxKeyLength {
+ hash := sha256.Sum256([]byte(identity))
+ hashSuffix := fmt.Sprintf("_%x", hash[:4])
+ suffixLength := libreHardwareMonitorMaxKeyLength - len(prefix) - len(hashSuffix)
+ key = prefix + strings.TrimRight(suffix[:suffixLength], "_") + hashSuffix
+ }
+ return key
+}
diff --git a/internal/hostagent/windows_librehardwaremonitor_test.go b/internal/hostagent/windows_librehardwaremonitor_test.go
new file mode 100644
index 0000000000..86b2f15215
--- /dev/null
+++ b/internal/hostagent/windows_librehardwaremonitor_test.go
@@ -0,0 +1,166 @@
+package hostagent
+
+import (
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+)
+
+func TestParseLibreHardwareMonitorTemperaturesAcceptsOnlyCPUAndMotherboard(t *testing.T) {
+ body := []byte(`{
+ "id": 0,
+ "Text": "Sensor",
+ "Children": [{
+ "id": 1,
+ "Text": "Test computer",
+ "Children": [{
+ "id": 2,
+ "Text": "AMD Ryzen 9",
+ "HardwareId": "/amdcpu/0",
+ "Children": [{
+ "id": 3,
+ "Text": "Temperatures",
+ "Children": [
+ {"id": 4, "Text": "Core (Tctl/Tdie)", "SensorId": "/amdcpu/0/temperature/0", "Type": "Temperature", "RawValue": 62.75},
+ {"id": 5, "Text": "Invalid", "SensorId": "/amdcpu/0/temperature/1", "Type": "Temperature", "RawValue": 151},
+ {"id": 6, "Text": "Load", "SensorId": "/amdcpu/0/load/0", "Type": "Load", "RawValue": 31}
+ ]
+ }]
+ }, {
+ "id": 7,
+ "Text": "Nuvoton NCT6798D",
+ "HardwareId": "/lpc/nct6798d/0",
+ "Children": [{
+ "id": 8,
+ "Text": "Motherboard",
+ "SensorId": "/lpc/nct6798d/0/temperature/2",
+ "Type": "Temperature",
+ "RawValue": 37
+ }]
+ }, {
+ "id": 9,
+ "Text": "NVIDIA GPU",
+ "HardwareId": "/gpu-nvidia/0",
+ "Children": [{
+ "id": 10,
+ "Text": "GPU Core",
+ "SensorId": "/gpu-nvidia/0/temperature/0",
+ "Type": "Temperature",
+ "RawValue": 55
+ }]
+ }, {
+ "id": 11,
+ "Text": "NVMe",
+ "HardwareId": "/nvme/0",
+ "Children": [{
+ "id": 12,
+ "Text": "Temperature",
+ "SensorId": "/nvme/0/temperature/0",
+ "Type": "Temperature",
+ "RawValue": 42
+ }]
+ }]
+ }]
+ }`)
+
+ got, err := parseLibreHardwareMonitorTemperatures(body)
+ if err != nil {
+ t.Fatalf("parseLibreHardwareMonitorTemperatures returned error: %v", err)
+ }
+ if len(got) != 2 {
+ t.Fatalf("temperatures = %+v, want exactly CPU and motherboard readings", got)
+ }
+ if got["cpu_lhm_amdcpu_0_temperature_0"] != 62.75 {
+ t.Fatalf("CPU temperature = %+v, want 62.75", got)
+ }
+ if got["motherboard_lhm_lpc_nct6798d_0_temperature_2"] != 37 {
+ t.Fatalf("motherboard temperature = %+v, want 37", got)
+ }
+}
+
+func TestParseLibreHardwareMonitorTemperaturesRejectsMalformedAndBoundedTrees(t *testing.T) {
+ if _, err := parseLibreHardwareMonitorTemperatures([]byte("{")); err == nil {
+ t.Fatal("expected malformed JSON error")
+ }
+
+ root := libreHardwareMonitorNode{}
+ current := &root
+ for depth := 0; depth <= libreHardwareMonitorMaxDepth; depth++ {
+ current.Children = []libreHardwareMonitorNode{{}}
+ current = &current.Children[0]
+ }
+ body, err := json.Marshal(root)
+ if err != nil {
+ t.Fatalf("marshal deep tree: %v", err)
+ }
+ if _, err := parseLibreHardwareMonitorTemperatures(body); err == nil {
+ t.Fatal("expected deep tree error")
+ }
+
+ root = libreHardwareMonitorNode{
+ Children: make([]libreHardwareMonitorNode, libreHardwareMonitorMaxNodes),
+ }
+ body, err = json.Marshal(root)
+ if err != nil {
+ t.Fatalf("marshal wide tree: %v", err)
+ }
+ if _, err := parseLibreHardwareMonitorTemperatures(body); err == nil {
+ t.Fatal("expected oversized node tree error")
+ }
+}
+
+func TestCollectLibreHardwareMonitorTemperaturesUsesBoundedNoRedirectHTTP(t *testing.T) {
+ handler := http.NewServeMux()
+ handler.HandleFunc("/data.json", func(response http.ResponseWriter, request *http.Request) {
+ if request.Header.Get("Accept") != "application/json" {
+ t.Fatalf("Accept header = %q, want application/json", request.Header.Get("Accept"))
+ }
+ _, _ = response.Write([]byte(`{
+ "Children": [{
+ "HardwareId": "/intelcpu/0",
+ "Children": [{
+ "SensorId": "/intelcpu/0/temperature/0",
+ "Type": "Temperature",
+ "RawValue": 48
+ }]
+ }]
+ }`))
+ })
+ handler.HandleFunc("/redirect", func(response http.ResponseWriter, request *http.Request) {
+ http.Redirect(response, request, "/data.json", http.StatusFound)
+ })
+ server := httptest.NewServer(handler)
+ t.Cleanup(server.Close)
+
+ got, err := collectLibreHardwareMonitorTemperatures(
+ context.Background(),
+ server.URL+"/data.json",
+ )
+ if err != nil {
+ t.Fatalf("collectLibreHardwareMonitorTemperatures returned error: %v", err)
+ }
+ if got["cpu_lhm_intelcpu_0_temperature_0"] != 48 {
+ t.Fatalf("HTTP temperatures = %+v, want CPU reading", got)
+ }
+
+ if _, err := collectLibreHardwareMonitorTemperatures(
+ context.Background(),
+ server.URL+"/redirect",
+ ); err == nil {
+ t.Fatal("expected redirect rejection")
+ }
+
+ oversized := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, _ *http.Request) {
+ _, _ = response.Write([]byte(strings.Repeat("x", libreHardwareMonitorMaxOutputBytes+1)))
+ }))
+ t.Cleanup(oversized.Close)
+ if _, err := collectLibreHardwareMonitorTemperatures(
+ context.Background(),
+ oversized.URL,
+ ); err == nil {
+ t.Fatal("expected oversized response rejection")
+ }
+}
diff --git a/internal/hostagent/windows_storage_sensors.go b/internal/hostagent/windows_storage_sensors.go
index e5a094aa81..81f02d6078 100644
--- a/internal/hostagent/windows_storage_sensors.go
+++ b/internal/hostagent/windows_storage_sensors.go
@@ -62,6 +62,7 @@ type windowsStorageTemperatureReading struct {
func (a *Agent) collectWindowsTemperatureSensors(ctx context.Context) agentshost.Sensors {
result := a.collectWindowsStorageTemperatures(ctx)
+ a.mergeLibreHardwareMonitorTemperatures(ctx, &result)
a.mergeNVIDIATemperatures(ctx, &result)
return result
}