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: env overrides and OS-aware test improvements

rcourtman8412cc7ddbe6
diff --git a/internal/config/config.go b/internal/config/config.go
index 57a4f1509b..5399eb7e7c 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -830,6 +830,50 @@ func Load() (*Config, error) {
}
}
+ if intervalStr := utils.GetenvTrim("PBS_POLLING_INTERVAL"); intervalStr != "" {
+ if dur, err := time.ParseDuration(intervalStr); err == nil {
+ if dur < 10*time.Second {
+ log.Warn().Dur("interval", dur).Msg("Ignoring PBS_POLLING_INTERVAL below 10s from environment")
+ } else {
+ cfg.PBSPollingInterval = dur
+ cfg.EnvOverrides["PBS_POLLING_INTERVAL"] = true
+ log.Info().Dur("interval", dur).Msg("Overriding PBS polling interval from environment")
+ }
+ } else if seconds, err := strconv.Atoi(intervalStr); err == nil {
+ if seconds < 10 {
+ log.Warn().Int("seconds", seconds).Msg("Ignoring PBS_POLLING_INTERVAL below 10s from environment")
+ } else {
+ cfg.PBSPollingInterval = time.Duration(seconds) * time.Second
+ cfg.EnvOverrides["PBS_POLLING_INTERVAL"] = true
+ log.Info().Int("seconds", seconds).Msg("Overriding PBS polling interval (seconds) from environment")
+ }
+ } else {
+ log.Warn().Str("value", intervalStr).Msg("Invalid PBS_POLLING_INTERVAL value, expected duration or seconds")
+ }
+ }
+
+ if intervalStr := utils.GetenvTrim("PMG_POLLING_INTERVAL"); intervalStr != "" {
+ if dur, err := time.ParseDuration(intervalStr); err == nil {
+ if dur < 10*time.Second {
+ log.Warn().Dur("interval", dur).Msg("Ignoring PMG_POLLING_INTERVAL below 10s from environment")
+ } else {
+ cfg.PMGPollingInterval = dur
+ cfg.EnvOverrides["PMG_POLLING_INTERVAL"] = true
+ log.Info().Dur("interval", dur).Msg("Overriding PMG polling interval from environment")
+ }
+ } else if seconds, err := strconv.Atoi(intervalStr); err == nil {
+ if seconds < 10 {
+ log.Warn().Int("seconds", seconds).Msg("Ignoring PMG_POLLING_INTERVAL below 10s from environment")
+ } else {
+ cfg.PMGPollingInterval = time.Duration(seconds) * time.Second
+ cfg.EnvOverrides["PMG_POLLING_INTERVAL"] = true
+ log.Info().Int("seconds", seconds).Msg("Overriding PMG polling interval (seconds) from environment")
+ }
+ } else {
+ log.Warn().Str("value", intervalStr).Msg("Invalid PMG_POLLING_INTERVAL value, expected duration or seconds")
+ }
+ }
+
if enabledStr := utils.GetenvTrim("ENABLE_TEMPERATURE_MONITORING"); enabledStr != "" {
if enabled, err := strconv.ParseBool(enabledStr); err == nil {
cfg.TemperatureMonitoringEnabled = enabled
diff --git a/internal/config/detect_root_test.go b/internal/config/detect_root_test.go
index 06e365d4f0..e2fb326626 100644
--- a/internal/config/detect_root_test.go
+++ b/internal/config/detect_root_test.go
@@ -2,6 +2,7 @@ package config
import (
"os"
+ "path/filepath"
"testing"
)
@@ -93,7 +94,7 @@ func TestDetectAppRoot_Scenarios(t *testing.T) {
name: "Executable in temp, getwd error",
mockExec: os.TempDir() + "/go-build123/exe",
mockGetwdErr: os.ErrPermission,
- expectedResult: os.TempDir() + "/go-build123", // Falls back to exe dir
+ expectedResult: filepath.Join(os.TempDir(), "go-build123"), // Falls back to exe dir
},
{
name: "Executable error, getwd error",
diff --git a/internal/dockeragent/self_update_test.go b/internal/dockeragent/self_update_test.go
index 1f462ca50b..4641c23b6c 100644
--- a/internal/dockeragent/self_update_test.go
+++ b/internal/dockeragent/self_update_test.go
@@ -99,8 +99,12 @@ func TestResolveSymlink(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
- if got != target {
- t.Fatalf("expected %q, got %q", target, got)
+ expected, err := filepath.EvalSymlinks(target)
+ if err != nil {
+ t.Fatalf("eval symlinks target: %v", err)
+ }
+ if got != expected {
+ t.Fatalf("expected %q, got %q", expected, got)
}
if _, err := resolveSymlink(filepath.Join(dir, "missing")); err == nil {
diff --git a/internal/hostagent/agent_metrics_test.go b/internal/hostagent/agent_metrics_test.go
index cf73e28621..b764c05a75 100644
--- a/internal/hostagent/agent_metrics_test.go
+++ b/internal/hostagent/agent_metrics_test.go
@@ -3,6 +3,7 @@ package hostagent
import (
"context"
"errors"
+ "runtime"
"testing"
"time"
@@ -184,6 +185,12 @@ func TestBuildReport(t *testing.T) {
t.Fatalf("buildReport failed: %v", err)
}
+ if runtime.GOOS != "linux" {
+ if len(report.RAID) != 0 {
+ t.Errorf("Expected no RAID arrays on %s, got %d", runtime.GOOS, len(report.RAID))
+ }
+ return
+ }
if len(report.RAID) != 1 {
t.Errorf("Expected 1 RAID array, got %d", len(report.RAID))
} else if report.RAID[0].Name != "md0" {
@@ -270,6 +277,12 @@ func TestBuildReport(t *testing.T) {
}
// SMART data is attached to Sensors in the report
+ if runtime.GOOS != "linux" {
+ if len(report.Sensors.SMART) != 0 {
+ t.Errorf("Expected no SMART disks on %s, got %d", runtime.GOOS, len(report.Sensors.SMART))
+ }
+ return
+ }
if len(report.Sensors.SMART) != 1 {
t.Errorf("Expected 1 SMART disk, got %d", len(report.Sensors.SMART))
} else {
diff --git a/internal/hostagent/agent_new_test.go b/internal/hostagent/agent_new_test.go
index c3fb2f68a6..b0bd601842 100644
--- a/internal/hostagent/agent_new_test.go
+++ b/internal/hostagent/agent_new_test.go
@@ -172,6 +172,10 @@ func TestNew_FallsBackToHostnameWhenMachineIDAndMACEmpty(t *testing.T) {
}
func TestNew_FallsBackToMACWhenMachineIDEmpty(t *testing.T) {
+ if runtime.GOOS != "linux" {
+ t.Skip("MAC fallback is Linux-only")
+ }
+
originalHostInfo := hostInfoWithContext
originalReadFile := readFile
originalNetInterfaces := netInterfaces