mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-05-19 07:54:10 +00:00
Improve temperature proxy detection
This commit is contained in:
parent
9d6f32a56d
commit
1abff55feb
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/notifications"
|
||||
"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"
|
||||
|
|
@ -3459,17 +3460,24 @@ func (m *Monitor) GetConnectionStatuses() map[string]bool {
|
|||
|
||||
// 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()
|
||||
defer m.mu.RUnlock()
|
||||
collector := m.tempCollector
|
||||
m.mu.RUnlock()
|
||||
|
||||
if m.tempCollector == nil {
|
||||
if collector == nil {
|
||||
return false
|
||||
}
|
||||
return m.tempCollector.SocketProxyDetected()
|
||||
return collector.SocketProxyDetected()
|
||||
}
|
||||
|
||||
// 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() {
|
||||
local pulse_url="$1"
|
||||
local refresh="$2"
|
||||
local config_file="/etc/pulse-sensor-proxy/config.yaml"
|
||||
|
||||
if [[ -z "$pulse_url" ]]; then
|
||||
return
|
||||
fi
|
||||
if [[ -z "$refresh" ]]; then
|
||||
refresh=60
|
||||
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
|
||||
fi
|
||||
|
||||
cat >> /etc/pulse-sensor-proxy/config.yaml << EOF
|
||||
cat >> "$config_file" << EOF
|
||||
|
||||
# Pulse control plane configuration (auto-generated)
|
||||
pulse_control_plane:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue