Improve temperature proxy detection
This commit is contained in:
parent
91dbe31ea5
commit
54c47fe2f5
3 changed files with 59 additions and 5 deletions
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"github.com/rcourtman/pulse-go-rewrite/internal/models"
|
"github.com/rcourtman/pulse-go-rewrite/internal/models"
|
||||||
"github.com/rcourtman/pulse-go-rewrite/internal/notifications"
|
"github.com/rcourtman/pulse-go-rewrite/internal/notifications"
|
||||||
"github.com/rcourtman/pulse-go-rewrite/internal/system"
|
"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/types"
|
||||||
"github.com/rcourtman/pulse-go-rewrite/internal/websocket"
|
"github.com/rcourtman/pulse-go-rewrite/internal/websocket"
|
||||||
agentsdocker "github.com/rcourtman/pulse-go-rewrite/pkg/agents/docker"
|
agentsdocker "github.com/rcourtman/pulse-go-rewrite/pkg/agents/docker"
|
||||||
|
|
@ -3459,17 +3460,24 @@ func (m *Monitor) GetConnectionStatuses() map[string]bool {
|
||||||
|
|
||||||
// HasSocketTemperatureProxy reports whether the local unix socket proxy is available.
|
// HasSocketTemperatureProxy reports whether the local unix socket proxy is available.
|
||||||
func (m *Monitor) HasSocketTemperatureProxy() bool {
|
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 {
|
if m == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
m.mu.RLock()
|
m.mu.RLock()
|
||||||
defer m.mu.RUnlock()
|
collector := m.tempCollector
|
||||||
|
m.mu.RUnlock()
|
||||||
|
|
||||||
if m.tempCollector == nil {
|
if collector == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return m.tempCollector.SocketProxyDetected()
|
return collector.SocketProxyDetected()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SocketProxyHostDiagnostics exposes per-host proxy cooldown state for diagnostics.
|
// SocketProxyHostDiagnostics exposes per-host proxy cooldown state for diagnostics.
|
||||||
|
|
|
||||||
23
internal/monitoring/monitor_proxy_test.go
Normal file
23
internal/monitoring/monitor_proxy_test.go
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
package monitoring
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMonitorHasSocketTemperatureProxyDetectsEnvSocket(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
socketPath := filepath.Join(dir, "pulse-sensor-proxy.sock")
|
||||||
|
|
||||||
|
if err := os.WriteFile(socketPath, []byte("socket-placeholder"), 0o600); err != nil {
|
||||||
|
t.Fatalf("failed to create fake socket: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Setenv("PULSE_SENSOR_PROXY_SOCKET", socketPath)
|
||||||
|
|
||||||
|
monitor := &Monitor{}
|
||||||
|
if !monitor.HasSocketTemperatureProxy() {
|
||||||
|
t.Fatalf("expected monitor to detect proxy socket at %s", socketPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1520,17 +1520,40 @@ write_control_plane_token() {
|
||||||
ensure_control_plane_config() {
|
ensure_control_plane_config() {
|
||||||
local pulse_url="$1"
|
local pulse_url="$1"
|
||||||
local refresh="$2"
|
local refresh="$2"
|
||||||
|
local config_file="/etc/pulse-sensor-proxy/config.yaml"
|
||||||
|
|
||||||
if [[ -z "$pulse_url" ]]; then
|
if [[ -z "$pulse_url" ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if [[ -z "$refresh" ]]; then
|
if [[ -z "$refresh" ]]; then
|
||||||
refresh=60
|
refresh=60
|
||||||
fi
|
fi
|
||||||
if grep -q "^pulse_control_plane:" /etc/pulse-sensor-proxy/config.yaml 2>/dev/null; then
|
|
||||||
|
if grep -q "^pulse_control_plane:" "$config_file" 2>/dev/null; then
|
||||||
|
# Re-write the existing control-plane block with the latest URL/token path.
|
||||||
|
local tmp
|
||||||
|
tmp=$(mktemp)
|
||||||
|
awk -v url="$pulse_url" -v refresh="$refresh" '
|
||||||
|
BEGIN { in_block = 0 }
|
||||||
|
/^pulse_control_plane:/ {
|
||||||
|
print "pulse_control_plane:"
|
||||||
|
print " url: " url
|
||||||
|
print " token_file: /etc/pulse-sensor-proxy/.pulse-control-token"
|
||||||
|
print " refresh_interval: " refresh
|
||||||
|
print ""
|
||||||
|
in_block = 1
|
||||||
|
next
|
||||||
|
}
|
||||||
|
# Exit the replacement block when we hit a non-indented line
|
||||||
|
in_block && /^[^[:space:]]/ { in_block = 0 }
|
||||||
|
in_block { next }
|
||||||
|
{ print }
|
||||||
|
' "$config_file" > "$tmp"
|
||||||
|
mv "$tmp" "$config_file"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat >> /etc/pulse-sensor-proxy/config.yaml << EOF
|
cat >> "$config_file" << EOF
|
||||||
|
|
||||||
# Pulse control plane configuration (auto-generated)
|
# Pulse control plane configuration (auto-generated)
|
||||||
pulse_control_plane:
|
pulse_control_plane:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue