Documentation
¶
Index ¶
- type AgentConn
- type AgentHandler
- type BrowserConn
- type BrowserHandler
- type Hub
- func (h *Hub) AgentHasCapability(serverID, cap string) bool
- func (h *Hub) Broadcast(msg *models.Message)
- func (h *Hub) BroadcastToBrowsers(action string, payload any)
- func (h *Hub) ConnectedCount() int
- func (h *Hub) HandleResult(result *models.CommandResult)
- func (h *Hub) IsConnected(serverID string) bool
- func (h *Hub) PendingCommandIDs() []string
- func (h *Hub) PendingCount() int
- func (h *Hub) Register(serverID string) *AgentConn
- func (h *Hub) RegisterBrowser(clientID string) *BrowserConn
- func (h *Hub) Send(serverID string, msg *models.Message) error
- func (h *Hub) SendCommand(serverID string, msg *models.Message, timeout time.Duration) (*models.CommandResult, error)
- func (h *Hub) SetAgentCapabilities(serverID string, caps []string)
- func (h *Hub) StartHealthCheck(timeoutFn func() time.Duration)
- func (h *Hub) Stop()
- func (h *Hub) Unregister(serverID string)
- func (h *Hub) UnregisterBrowser(clientID string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentConn ¶
type AgentConn struct {
ServerID string
SendCh chan []byte
// contains filtered or unexported fields
}
AgentConn represents an active agent WebSocket connection.
func (*AgentConn) HasCapability ¶ added in v0.3.87
HasCapability reports whether the agent advertised the given capability.
func (*AgentConn) LastHeartbeat ¶
LastHeartbeat returns the time of the last heartbeat.
func (*AgentConn) SetCapabilities ¶ added in v0.3.87
SetCapabilities records the capabilities the agent reported in agent.info.
func (*AgentConn) UpdateHeartbeat ¶
func (ac *AgentConn) UpdateHeartbeat()
UpdateHeartbeat records the latest heartbeat time.
type AgentHandler ¶
type AgentHandler struct {
// contains filtered or unexported fields
}
AgentHandler handles WebSocket connections from agents.
func NewAgentHandler ¶
func NewAgentHandler(hub *Hub, serverStore *store.ServerStore, nodeStore *store.NodeStore, metricsStore *store.MetricsStore, versionStore *store.VersionHistoryStore, geoResolver *dashboard.GeoIPResolver) *AgentHandler
NewAgentHandler creates a new WebSocket handler for agent connections.
func (*AgentHandler) HandleUpgrade ¶
func (h *AgentHandler) HandleUpgrade(w http.ResponseWriter, r *http.Request)
HandleUpgrade upgrades an HTTP connection to WebSocket and runs the agent message loop.
type BrowserConn ¶
BrowserConn represents an active browser WebSocket connection.
type BrowserHandler ¶
type BrowserHandler struct {
// contains filtered or unexported fields
}
BrowserHandler handles WebSocket connections from browser clients.
func NewBrowserHandler ¶
func NewBrowserHandler(hub *Hub) *BrowserHandler
NewBrowserHandler creates a new WebSocket handler for browser connections.
func (*BrowserHandler) HandleUpgrade ¶
func (h *BrowserHandler) HandleUpgrade(w http.ResponseWriter, r *http.Request)
HandleUpgrade upgrades an HTTP connection to WebSocket for browser clients.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub manages all active agent connections.
func NewHub ¶
func NewHub(serverStore *store.ServerStore, nodeStore *store.NodeStore) *Hub
NewHub creates a new connection hub.
func (*Hub) AgentHasCapability ¶ added in v0.3.87
AgentHasCapability reports whether the connected agent advertised the given capability. Returns false for an unknown/disconnected agent — so callers transparently fall back to the pre-capability behavior (backward compatible).
func (*Hub) BroadcastToBrowsers ¶
BroadcastToBrowsers sends a JSON event to all connected browser clients.
func (*Hub) ConnectedCount ¶
ConnectedCount returns the number of connected agents.
func (*Hub) HandleResult ¶
func (h *Hub) HandleResult(result *models.CommandResult)
HandleResult processes a command result from an agent. Matches the result to a pending command by command ID.
func (*Hub) IsConnected ¶
IsConnected checks if an agent is currently connected.
func (*Hub) PendingCommandIDs ¶
PendingCommandIDs returns the IDs of all pending commands (for testing).
func (*Hub) PendingCount ¶
PendingCount returns the number of commands awaiting responses.
func (*Hub) RegisterBrowser ¶
func (h *Hub) RegisterBrowser(clientID string) *BrowserConn
RegisterBrowser adds a browser client connection.
func (*Hub) SendCommand ¶
func (h *Hub) SendCommand(serverID string, msg *models.Message, timeout time.Duration) (*models.CommandResult, error)
SendCommand sends a command to an agent and waits for the result. Returns the result or an error if the agent is offline or the command times out.
func (*Hub) SetAgentCapabilities ¶ added in v0.3.87
SetAgentCapabilities records the capabilities reported by a connected agent.
func (*Hub) StartHealthCheck ¶
StartHealthCheck starts the background heartbeat monitor. Marks agents as offline if no heartbeat received within the timeout. timeoutFn is called on every tick so the timeout can be changed at runtime (e.g. from the Settings page) without restarting the dashboard.
func (*Hub) Unregister ¶
Unregister removes an agent connection from the hub.
func (*Hub) UnregisterBrowser ¶
UnregisterBrowser removes a browser client connection.