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.

refactor: simplify temperature monitoring after sensor proxy removal

rcourtman7049f5b43ced
diff --git a/cmd/pulse/config.go b/cmd/pulse/config.go
index 92ded588c1..88e67a5bf4 100644
--- a/cmd/pulse/config.go
+++ b/cmd/pulse/config.go
@@ -46,7 +46,7 @@ var configInfoCmd = &cobra.Command{
fmt.Println(" - email.enc : Encrypted email settings")
fmt.Println(" - system.json : System settings (polling interval, etc)")
fmt.Println(" - alerts.json : Alert rules and thresholds")
- fmt.Println(" - webhooks.json : Webhook configurations")
+ fmt.Println(" - webhooks.enc : Webhook configurations")
fmt.Println()
fmt.Println("To configure Pulse, use the Settings tab in the web UI.")
return nil
diff --git a/internal/config/config.go b/internal/config/config.go
index 84dc5256dc..f22ebf6f58 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -108,7 +108,6 @@ type Config struct {
BackupPollingInterval time.Duration `envconfig:"BACKUP_POLLING_INTERVAL"`
EnableBackupPolling bool `envconfig:"ENABLE_BACKUP_POLLING" default:"true"`
TemperatureMonitoringEnabled bool `json:"temperatureMonitoringEnabled"`
- EnableSensorProxy bool `envconfig:"PULSE_ENABLE_SENSOR_PROXY" default:"false" json:"-"` // Legacy pulse-sensor-proxy support (deprecated, opt-in)
WebhookBatchDelay time.Duration `envconfig:"WEBHOOK_BATCH_DELAY" default:"10s"`
AdaptivePollingEnabled bool `envconfig:"ADAPTIVE_POLLING_ENABLED" default:"false"`
AdaptivePollingBaseInterval time.Duration `envconfig:"ADAPTIVE_POLLING_BASE_INTERVAL" default:"10s"`
@@ -437,12 +436,6 @@ type PVEInstance struct {
TemperatureMonitoringEnabled *bool // Monitor temperature via SSH (nil = use global setting, true/false = override)
SSHPort int // SSH port for temperature monitoring (0 = use global default)
- // Temperature proxy configuration (for external PVE hosts)
- TemperatureProxyURL string // Optional HTTPS URL to pulse-sensor-proxy (e.g., https://pve1.lan:8443)
- TemperatureProxyToken string // Bearer token for proxy authentication
- // Control-plane token for socket-mode proxies (Pulse -> proxy sync)
- TemperatureProxyControlToken string
-
// Cluster support
IsCluster bool // True if this is a cluster
ClusterName string // Cluster name if applicable
@@ -468,8 +461,6 @@ type ClusterEndpoint struct {
LastPulseCheck *time.Time // Last time Pulse checked connectivity
PulseError string // Last error Pulse encountered connecting to this endpoint
- // Per-node temperature proxy tokens (for clusters with sensor-proxy on each node)
- TemperatureProxyControlToken string // Control-plane token for this specific node
}
// EffectiveIP returns the IP to use for this endpoint, preferring IPOverride if set
@@ -610,7 +601,6 @@ func Load() (*Config, error) {
DiscoverySubnet: "auto",
TemperatureMonitoringEnabled: true,
MaxPollTimeout: 3 * time.Minute, // Default max poll timeout for large clusters
- EnableSensorProxy: false,
EnvOverrides: make(map[string]bool),
AgentConnectURL: "",
OIDC: NewOIDCConfig(),
@@ -867,22 +857,6 @@ func Load() (*Config, error) {
}
}
- if enabledStr := utils.GetenvTrim("PULSE_ENABLE_SENSOR_PROXY"); enabledStr != "" {
- if enabled, err := strconv.ParseBool(enabledStr); err == nil {
- cfg.EnableSensorProxy = enabled
- cfg.EnvOverrides["PULSE_ENABLE_SENSOR_PROXY"] = true
- if enabled {
- log.Warn().Msg("Legacy pulse-sensor-proxy support enabled via PULSE_ENABLE_SENSOR_PROXY (deprecated, unsupported)")
- } else {
- log.Info().Msg("Legacy pulse-sensor-proxy support disabled via PULSE_ENABLE_SENSOR_PROXY")
- }
- } else {
- log.Warn().
- Str("value", enabledStr).
- Msg("Invalid PULSE_ENABLE_SENSOR_PROXY value, ignoring")
- }
- }
-
if hideLocalLoginStr := utils.GetenvTrim("PULSE_AUTH_HIDE_LOCAL_LOGIN"); hideLocalLoginStr != "" {
if hide, err := strconv.ParseBool(hideLocalLoginStr); err == nil {
cfg.HideLocalLogin = hide
@@ -1331,9 +1305,7 @@ func Load() (*Config, error) {
log.Info().Str("url", agentConnectURL).Msg("Using dedicated agent connect URL from environment")
}
- // REMOVED: Update channel, auto-update, connection timeout, and allowed origins env vars
- // These settings now ONLY come from system.json to prevent confusion
- // Only keeping essential deployment/infrastructure env vars
+ // Update settings are system.json-only; legacy env vars remain ignored.
// Normalize PVE user fields for password authentication
for i := range cfg.PVEInstances {
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index 1ac6ef1184..c29b8afcfd 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -31,7 +31,6 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/notifications"
"github.com/rcourtman/pulse-go-rewrite/internal/resources"
"github.com/rcourtman/pulse-go-rewrite/internal/system"
- "github.com/rcourtman/pulse-go-rewrite/internal/tempproxy"
"github.com/rcourtman/pulse-go-rewrite/internal/types"
"github.com/rcourtman/pulse-go-rewrite/internal/websocket"
agentsdocker "github.com/rcourtman/pulse-go-rewrite/pkg/agents/docker"
@@ -3318,41 +3317,6 @@ func (m *Monitor) GetConnectionStatuses() map[string]bool {
return statuses
}
-// HasSocketTemperatureProxy reports whether the local unix socket proxy is available.
-func (m *Monitor) HasSocketTemperatureProxy() bool {
- // Always check the real socket path first so we reflect the actual runtime state
- // even if the temperature collector hasn't latched onto the proxy yet.
- if tempproxy.NewClient().IsAvailable() {
- return true
- }
-
- if m == nil {
- return false
- }
-
- m.mu.RLock()
- collector := m.tempCollector
- m.mu.RUnlock()
-
- if collector == nil {
- return false
- }
- return collector.SocketProxyDetected()
-}
-
-// SocketProxyHostDiagnostics exposes per-host proxy cooldown state for diagnostics.
-func (m *Monitor) SocketProxyHostDiagnostics() []ProxyHostDiagnostics {
- m.mu.RLock()
- collector := m.tempCollector
- m.mu.RUnlock()
-
- if collector == nil {
- return nil
- }
-
- return collector.ProxyHostDiagnostics()
-}
-
// checkContainerizedTempMonitoring logs a security warning if Pulse is running
// in a container with SSH-based temperature monitoring enabled
func checkContainerizedTempMonitoring() {
diff --git a/internal/monitoring/temperature.go b/internal/monitoring/temperature.go
index e93da6ba2d..f940577e6b 100644
--- a/internal/monitoring/temperature.go
+++ b/internal/monitoring/temperature.go
@@ -11,54 +11,22 @@ import (
"path/filepath"
"strconv"
"strings"
- "sync"
"sync/atomic"
"time"
"github.com/rcourtman/pulse-go-rewrite/internal/models"
"github.com/rcourtman/pulse-go-rewrite/internal/ssh/knownhosts"
"github.com/rcourtman/pulse-go-rewrite/internal/system"
- "github.com/rcourtman/pulse-go-rewrite/internal/tempproxy"
"github.com/rs/zerolog/log"
)
-const (
- proxyFailureThreshold = 3
- proxyRetryInterval = 5 * time.Minute
-)
-
-type temperatureProxy interface {
- IsAvailable() bool
- GetTemperature(nodeHost string) (string, error)
-}
-
// TemperatureCollector handles SSH-based temperature collection from Proxmox nodes
type TemperatureCollector struct {
- sshUser string // SSH user (typically "root" or "pulse-monitor")
- sshKeyPath string // Path to SSH private key
- sshPort int // SSH port (default 22)
- proxyClient temperatureProxy // Optional: unix socket client for proxy
- useProxy bool // Whether to use proxy for temperature collection
- hostKeys knownhosts.Manager
- proxyMu sync.Mutex
- proxyFailures int
- proxyCooldownUntil time.Time
- proxyHostStates map[string]*proxyHostState
- missingKeyWarned atomic.Bool
-}
-
-type proxyHostState struct {
- failures int
- cooldownUntil time.Time
- lastError string
-}
-
-// ProxyHostDiagnostics describes the proxy transport state for a host.
-type ProxyHostDiagnostics struct {
- Host string
- Failures int
- CooldownUntil time.Time
- LastError string
+ sshUser string // SSH user (typically "root" or "pulse-monitor")
+ sshKeyPath string // Path to SSH private key
+ sshPort int // SSH port (default 22)
+ hostKeys knownhosts.Manager
+ missingKeyWarned atomic.Bool
}
// NewTemperatureCollectorWithPort creates a new temperature collector with custom SSH port
@@ -68,10 +36,9 @@ func NewTemperatureCollectorWithPort(sshUser, sshKeyPath string, sshPort int) *T
}
tc := &TemperatureCollector{
- sshUser: sshUser,
- sshKeyPath: sshKeyPath,
- sshPort: sshPort,
- proxyHostStates: make(map[string]*proxyHostState),
+ sshUser: sshUser,
+ sshKeyPath: sshKeyPath,
+ sshPort: sshPort,
}
homeDir := os.Getenv("HOME")
@@ -85,143 +52,75 @@ func NewTemperatureCollectorWithPort(sshUser, sshKeyPath string, sshPort int) *T
tc.hostKeys = manager
}
- // Always keep a proxy client so we can detect the socket later even if it
- // isn't present during startup. Without this, containerized deployments that
- // mount the socket after Pulse starts never re-enable the hardened proxy.
- proxyClient := tempproxy.NewClient()
- tc.proxyClient = proxyClient
- if proxyClient.IsAvailable() {
- log.Info().Msg("Temperature proxy detected - using secure host-side bridge")
- tc.useProxy = true
- } else {
- log.Debug().Msg("Temperature proxy not available yet - falling back to SSH until socket appears")
- tc.useProxy = false
- }
-
return tc
}
// CollectTemperature collects temperature data from a node via SSH
func (tc *TemperatureCollector) CollectTemperature(ctx context.Context, nodeHost, nodeName string) (*models.Temperature, error) {
- return tc.CollectTemperatureWithProxy(ctx, nodeHost, nodeName, "", "")
-}
-
-// CollectTemperatureWithProxy collects temperature data with optional HTTP proxy configuration
-func (tc *TemperatureCollector) CollectTemperatureWithProxy(ctx context.Context, nodeHost, nodeName, proxyURL, proxyToken string) (*models.Temperature, error) {
// Extract hostname/IP from the host URL (might be https://hostname:8006)
host := extractHostname(nodeHost)
- var output string
- var err error
+ // SECURITY: Block SSH fallback when running in containers (unless dev mode)
+ // Container compromise = SSH key compromise = root access to infrastructure
+ devModeAllowSSH := os.Getenv("PULSE_DEV_ALLOW_CONTAINER_SSH") == "true"
+ isContainer := os.Getenv("PULSE_DOCKER") == "true" || system.InContainer()
- // Try HTTP proxy first if configured for this instance
- if proxyURL != "" && proxyToken != "" {
- httpClient := tempproxy.NewHTTPClient(proxyURL, proxyToken)
- if httpClient.IsAvailable() {
- // Use nodeName for HTTP proxy (sensor-proxy needs short hostname, not IP)
- output, err = httpClient.GetTemperature(nodeName)
- if err != nil {
- log.Debug().
- Str("node", nodeName).
- Str("host", host).
- Str("proxy_url", proxyURL).
- Err(err).
- Msg("Failed to collect temperature data via HTTP proxy")
- // Don't fall back to socket/SSH for HTTP proxy failures
- // If HTTP proxy is configured, it's the intended method
- return &models.Temperature{Available: false}, nil
- }
- // HTTP proxy succeeded
- goto parseOutput
- }
+ if isContainer && devModeAllowSSH {
+ // Log when dev override is active so operators understand the security posture
+ log.Info().
+ Str("node", nodeName).
+ Msg("Temperature collection using direct SSH (dev mode override active - not for production)")
}
- // Use Unix socket proxy if available (local deployment)
- if tc.isProxyEnabled() {
- if tc.shouldSkipProxyHost(host) {
- log.Debug().
- Str("node", nodeName).
- Str("host", host).
- Msg("Skipping temperature proxy request while host is in cooldown")
- return &models.Temperature{Available: false}, nil
- }
-
- output, err = tc.proxyClient.GetTemperature(host)
- if err != nil {
- tc.handleProxyFailure(host, err)
- log.Debug().
- Str("node", nodeName).
- Str("host", host).
- Err(err).
- Msg("Failed to collect temperature data via proxy")
- return &models.Temperature{Available: false}, nil
- }
- tc.handleProxySuccess()
- tc.handleProxyHostSuccess(host)
- } else {
- // SECURITY: Block SSH fallback when running in containers (unless dev mode)
- // Container compromise = SSH key compromise = root access to infrastructure
- devModeAllowSSH := os.Getenv("PULSE_DEV_ALLOW_CONTAINER_SSH") == "true"
- isContainer := os.Getenv("PULSE_DOCKER") == "true" || system.InContainer()
-
- if isContainer && devModeAllowSSH {
- // Log when dev override is active so operators understand the security posture
- log.Info().
- Str("node", nodeName).
- Msg("Temperature collection using direct SSH (dev mode override active - not for production)")
- }
+ if isContainer && !devModeAllowSSH {
+ // Warn but allow if key is present (legacy behavior restoration)
+ // We don't return here, allowing the code to fall through to the SSH key check
+ log.Warn().
+ Str("node", nodeName).
+ Msg("Temperature collection using direct SSH from container. This is insecure for production deployments.")
+ }
- if isContainer && !devModeAllowSSH {
- // Warn but allow if key is present (legacy behavior restoration)
- // We don't return here, allowing the code to fall through to the SSH key check
- log.Warn().
- Str("node", nodeName).
- Msg("Temperature collection using direct SSH from container. This is insecure. Recommend using pulse-sensor-proxy.")
- }
+ if strings.TrimSpace(tc.sshKeyPath) == "" {
+ tc.logMissingSSHKey(nil)
+ return &models.Temperature{Available: false}, nil
+ }
- if strings.TrimSpace(tc.sshKeyPath) == "" {
- tc.logMissingSSHKey(nil)
- return &models.Temperature{Available: false}, nil
- }
+ if _, keyErr := os.Stat(tc.sshKeyPath); keyErr != nil {
+ tc.logMissingSSHKey(keyErr)
+ return &models.Temperature{Available: false}, nil
+ }
- if _, keyErr := os.Stat(tc.sshKeyPath); keyErr != nil {
- tc.logMissingSSHKey(keyErr)
+ // Direct SSH (legacy method for non-containerized deployments)
+ // Try sensors first, fall back to Raspberry Pi method if that fails
+ // sensors exits non-zero when optional subfeatures fail; "|| true" keeps the JSON for parsing (#600)
+ output, err := tc.runSSHCommand(ctx, host, "sensors -j 2>/dev/null || true")
+ if err != nil || strings.TrimSpace(output) == "" {
+ if tc.disableLegacySSHOnAuthFailure(err, nodeName, host) {
return &models.Temperature{Available: false}, nil
}
- // Direct SSH (legacy method for non-containerized deployments)
- // Try sensors first, fall back to Raspberry Pi method if that fails
- // sensors exits non-zero when optional subfeatures fail; "|| true" keeps the JSON for parsing (#600)
- output, err = tc.runSSHCommand(ctx, host, "sensors -j 2>/dev/null || true")
- if err != nil || strings.TrimSpace(output) == "" {
- if tc.disableLegacySSHOnAuthFailure(err, nodeName, host) {
- return &models.Temperature{Available: false}, nil
- }
-
- // Try Raspberry Pi temperature method
- output, err = tc.runSSHCommand(ctx, host, "cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null")
- if err == nil && strings.TrimSpace(output) != "" {
- // Parse RPi temperature format
- temp, parseErr := tc.parseRPiTemperature(output)
- if parseErr == nil {
- return temp, nil
- }
- }
-
- if tc.disableLegacySSHOnAuthFailure(err, nodeName, host) {
- return &models.Temperature{Available: false}, nil
+ // Try Raspberry Pi temperature method
+ output, err = tc.runSSHCommand(ctx, host, "cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null")
+ if err == nil && strings.TrimSpace(output) != "" {
+ // Parse RPi temperature format
+ temp, parseErr := tc.parseRPiTemperature(output)
+ if parseErr == nil {
+ return temp, nil
}
+ }
- log.Debug().
- Str("node", nodeName).
- Str("host", host).
- Err(err).
- Msg("Failed to collect temperature data via SSH (tried both lm-sensors and RPi methods)")
+ if tc.disableLegacySSHOnAuthFailure(err, nodeName, host) {
return &models.Temperature{Available: false}, nil
}
+
+ log.Debug().
+ Str("node", nodeName).
+ Str("host", host).
+ Err(err).
+ Msg("Failed to collect temperature data via SSH (tried both lm-sensors and RPi methods)")
+ return &models.Temperature{Available: false}, nil
}
-parseOutput:
// Parse sensors JSON output
temp, err := tc.parseSensorsJSON(output)
if err != nil {
@@ -241,7 +140,6 @@ parseOutput:
return temp, nil
}
-// runSSHCommand executes a command on a remote node via SSH
func (tc *TemperatureCollector) runSSHCommand(ctx context.Context, host, command string) (string, error) {
if strings.TrimSpace(tc.sshKeyPath) != "" {
if _, err := os.Stat(tc.sshKeyPath); err != nil {
@@ -878,191 +776,3 @@ func (tc *TemperatureCollector) ensureHostKey(ctx context.Context, host string)
}
return tc.hostKeys.EnsureWithPort(ctx, host, tc.sshPort)
}
-
-func (tc *TemperatureCollector) isProxyEnabled() bool {
- if tc.proxyClient == nil {
- return false
- }
-
- tc.proxyMu.Lock()
- restored := false
- if !tc.useProxy {
- now := time.Now()
- if now.After(tc.proxyCooldownUntil) {
- if tc.proxyClient.IsAvailable() {
- tc.useProxy = true
- tc.proxyFailures = 0
- tc.proxyCooldownUntil = time.Time{}
- restored = true
- } else {
- tc.proxyCooldownUntil = now.Add(proxyRetryInterval)
- }
- }
- }
- useProxy := tc.useProxy
- tc.proxyMu.Unlock()
-
- if restored {
- log.Info().Msg("Temperature proxy connection restored; resuming proxy collection")
- }
-
- return useProxy
-}
-
-func (tc *TemperatureCollector) shouldSkipProxyHost(host string) bool {
- host = strings.TrimSpace(host)
- if host == "" {
- return false
- }
-
- tc.proxyMu.Lock()
- defer tc.proxyMu.Unlock()
- state, ok := tc.proxyHostStates[host]
- if !ok || state == nil {
- return false
- }
-
- now := time.Now()
- if state.cooldownUntil.IsZero() || now.After(state.cooldownUntil) {
- // Cooldown expired; reset state so we can retry this host.
- state.cooldownUntil = time.Time{}
- state.failures = 0
- if state.cooldownUntil.IsZero() && state.failures == 0 {
- delete(tc.proxyHostStates, host)
- }
- return false
- }
-
- return true
-}
-
-// SocketProxyAvailable reports whether the unix socket proxy can currently be used.
-func (tc *TemperatureCollector) SocketProxyAvailable() bool {
- return tc != nil && tc.isProxyEnabled()
-}
-
-// SocketProxyDetected reports whether the proxy socket exists (regardless of cooldown status).
-func (tc *TemperatureCollector) SocketProxyDetected() bool {
- if tc == nil || tc.proxyClient == nil {
- return false
- }
- return tc.proxyClient.IsAvailable()
-}
-
-func (tc *TemperatureCollector) handleProxySuccess() {
- if tc.proxyClient == nil {
- return
- }
- tc.proxyMu.Lock()
- tc.proxyFailures = 0
- tc.proxyMu.Unlock()
-}
-
-func (tc *TemperatureCollector) handleProxyHostSuccess(host string) {
- host = strings.TrimSpace(host)
- if host == "" {
- return
- }
- tc.proxyMu.Lock()
- delete(tc.proxyHostStates, host)
- tc.proxyMu.Unlock()
-}
-
-func (tc *TemperatureCollector) handleProxyFailure(host string, err error) {
- if tc.proxyClient == nil {
- return
- }
-
- if tc.shouldDisableProxy(err) {
- tc.proxyMu.Lock()
- tc.proxyFailures++
- disable := tc.proxyFailures >= proxyFailureThreshold && tc.useProxy
- if disable {
- tc.useProxy = false
- tc.proxyCooldownUntil = time.Now().Add(proxyRetryInterval)
- tc.proxyFailures = 0
- }
- tc.proxyMu.Unlock()
-
- if disable {
- log.Warn().
- Err(err).
- Dur("cooldown", proxyRetryInterval).
- Msg("Temperature proxy disabled after repeated failures; will retry later")
- }
- return
- }
-
- tc.handleProxyHostFailure(host, err)
-}
-
-func (tc *TemperatureCollector) handleProxyHostFailure(host string, err error) {
- host = strings.TrimSpace(host)
- if host == "" {
- return
- }
-
- tc.proxyMu.Lock()
- state, ok := tc.proxyHostStates[host]
- if !ok || state == nil {
- state = &proxyHostState{}
- tc.proxyHostStates[host] = state
- }
- state.failures++
- state.lastError = strings.TrimSpace(err.Error())
- trip := state.failures >= proxyFailureThreshold
- if trip {
- state.failures = 0
- state.cooldownUntil = time.Now().Add(proxyRetryInterval)
- }
- tc.proxyMu.Unlock()
-
- if trip {
- log.Warn().
- Err(err).
- Str("host", host).
- Dur("cooldown", proxyRetryInterval).
- Msg("Temperature proxy host in cooldown after repeated failures")
- }
-}
-
-func (tc *TemperatureCollector) shouldDisableProxy(err error) bool {
- var proxyErr *tempproxy.ProxyError
- if errors.As(err, &proxyErr) {
- switch proxyErr.Type {
- case tempproxy.ErrorTypeTransport, tempproxy.ErrorTypeTimeout:
- return true
- default:
- return false
- }
- }
- return true
-}
-
-// ProxyHostDiagnostics returns a snapshot of per-host proxy error state.
-func (tc *TemperatureCollector) ProxyHostDiagnostics() []ProxyHostDiagnostics {
- if tc == nil {
- return nil
- }
-
- tc.proxyMu.Lock()
- defer tc.proxyMu.Unlock()
-
- if len(tc.proxyHostStates) == 0 {
- return nil
- }
-
- result := make([]ProxyHostDiagnostics, 0, len(tc.proxyHostStates))
- for host, state := range tc.proxyHostStates {
- if state == nil {
- continue
- }
- result = append(result, ProxyHostDiagnostics{
- Host: host,
- Failures: state.failures,
- CooldownUntil: state.cooldownUntil,
- LastError: state.lastError,
- })
- }
- return result
-}