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.

Fix TrueNAS fractional uptime decoding

rcourtmanf0ad7f128413
diff --git a/internal/truenas/client.go b/internal/truenas/client.go
index 8f71cba9e1..db0185ce57 100644
--- a/internal/truenas/client.go
+++ b/internal/truenas/client.go
@@ -171,7 +171,7 @@ func (c *Client) GetSystemInfo(ctx context.Context) (*SystemInfo, error) {
Hostname: strings.TrimSpace(response.Hostname),
Version: strings.TrimSpace(response.Version),
Build: build,
- UptimeSeconds: response.UptimeSeconds,
+ UptimeSeconds: response.UptimeSeconds.Int64(),
Healthy: true,
MachineID: machineID,
CPUCount: cpuCount,
@@ -2868,15 +2868,15 @@ func normalizeFingerprint(fingerprint string) (string, error) {
}
type systemInfoResponse struct {
- Hostname string `json:"hostname"`
- Version string `json:"version"`
- BuildTime textResponseField `json:"buildtime"`
- UptimeSeconds int64 `json:"uptime_seconds"`
- SystemSerial string `json:"system_serial"`
- SystemVendor string `json:"system_manufacturer"`
- Cores int `json:"cores"`
- PhysicalCores int `json:"physical_cores"`
- Physmem int64 `json:"physmem"`
+ Hostname string `json:"hostname"`
+ Version string `json:"version"`
+ BuildTime textResponseField `json:"buildtime"`
+ UptimeSeconds int64ResponseField `json:"uptime_seconds"`
+ SystemSerial string `json:"system_serial"`
+ SystemVendor string `json:"system_manufacturer"`
+ Cores int `json:"cores"`
+ PhysicalCores int `json:"physical_cores"`
+ Physmem int64 `json:"physmem"`
}
type textResponseField string
@@ -2894,6 +2894,26 @@ func (f *textResponseField) UnmarshalJSON(data []byte) error {
return nil
}
+type int64ResponseField int64
+
+func (f int64ResponseField) Int64() int64 {
+ return int64(f)
+}
+
+func (f *int64ResponseField) UnmarshalJSON(data []byte) error {
+ trimmed := bytes.TrimSpace(data)
+ if len(trimmed) == 0 || bytes.Equal(trimmed, []byte("null")) {
+ *f = 0
+ return nil
+ }
+ value, err := parseInt64FromAny(trimmed)
+ if err != nil {
+ return fmt.Errorf("parse int64 response field: %w", err)
+ }
+ *f = int64ResponseField(value)
+ return nil
+}
+
type poolResponse struct {
ID int64 `json:"id"`
Name string `json:"name"`
diff --git a/internal/truenas/client_test.go b/internal/truenas/client_test.go
index 0e0798b1dd..530d11c81b 100644
--- a/internal/truenas/client_test.go
+++ b/internal/truenas/client_test.go
@@ -190,6 +190,24 @@ func TestGetSystemInfoAcceptsStructuredBuildTime(t *testing.T) {
}
}
+func TestGetSystemInfoAcceptsFractionalUptimeSeconds(t *testing.T) {
+ server := newMockServer(t, map[string]apiResponse{
+ "/api/v2.0/system/info": {
+ body: `{"hostname":"nas","version":"TrueNAS-SCALE-25.10.3.1","buildtime":{"$date":"2026-05-14T18:24:01+02:00"},"uptime_seconds":360144.629139547}`,
+ },
+ }, nil)
+ t.Cleanup(server.Close)
+
+ client := mustClientForServer(t, server.URL, ClientConfig{APIKey: "test-key"})
+ system, err := client.GetSystemInfo(context.Background())
+ if err != nil {
+ t.Fatalf("GetSystemInfo() error = %v", err)
+ }
+ if system.UptimeSeconds != 360144 {
+ t.Fatalf("UptimeSeconds = %d, want truncated fractional uptime", system.UptimeSeconds)
+ }
+}
+
func TestTestConnectionSuccessAndFailure(t *testing.T) {
successServer := newMockServer(t, map[string]apiResponse{
"/api/v2.0/system/info": {body: `{"hostname":"nas","version":"v","buildtime":"b","uptime_seconds":1}`},