Documentation
¶
Overview ¶
Package agent provides Agent communication functionality.
Package agent provides Agent communication functionality.
Index ¶
- Constants
- type AgentConfigEntry
- type AgentConnection
- type AgentHealth
- type AuthPayload
- type Client
- type CommandPayload
- type ContainerData
- type ErrorPayload
- type InboundListener
- type Message
- type MessageType
- type QueryPayload
- type ReportPayload
- type ResponsePayload
- type Server
- func (s *Server) ConnectToInboundAgents(ctx context.Context)
- func (s *Server) GetConnectedAgents() []string
- func (s *Server) IsAgentConnected(agentID string) bool
- func (s *Server) SendCommand(agentID string, action string) error
- func (s *Server) SendQuery(agentID string, action string) error
- func (s *Server) Start(ctx context.Context) error
Constants ¶
const ( QueryActionGetContainers = "get_containers" QueryActionGetIP = "get_ip" QueryActionGetHealth = "get_health" )
QueryAction defines query actions.
const ( CommandActionRefresh = "refresh" CommandActionReconnect = "reconnect" )
CommandAction defines command actions.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentConfigEntry ¶
AgentConfigEntry holds agent configuration entry.
type AgentConnection ¶
type AgentConnection struct {
ID string
Name string
Conn *websocket.Conn
DefaultTunnel string
// contains filtered or unexported fields
}
AgentConnection represents a connected agent.
func (*AgentConnection) IsConnected ¶
func (c *AgentConnection) IsConnected() bool
IsConnected reports whether the agent is currently connected.
type AgentHealth ¶
type AgentHealth struct {
DockerConnected bool `json:"docker_connected"`
UptimeSeconds int64 `json:"uptime_seconds"`
LastError string `json:"last_error,omitempty"`
}
AgentHealth represents agent health status.
type AuthPayload ¶
type AuthPayload struct {
AgentID string `json:"agent_id"`
Token string `json:"token"`
Version string `json:"version,omitempty"`
}
AuthPayload is the authentication message payload.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the WebSocket client for agent outbound mode. Agent dials Main's WebSocket server.
func (*Client) IsConnected ¶
IsConnected returns whether the client is connected.
type CommandPayload ¶
type CommandPayload struct {
Action string `json:"action"`
}
CommandPayload is the command message payload.
type ContainerData ¶
type ContainerData struct {
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
Status string `json:"status"`
Labels map[string]string `json:"labels"`
Networks map[string]string `json:"networks,omitempty"`
Created time.Time `json:"created"`
Started time.Time `json:"started,omitempty"`
}
ContainerData represents container data sent by agent.
func ContainerDataFromInfo ¶
func ContainerDataFromInfo(info *types.ContainerInfo) *ContainerData
ContainerDataFromInfo converts ContainerInfo to ContainerData.
func (*ContainerData) ConvertToContainerInfo ¶
func (c *ContainerData) ConvertToContainerInfo() *types.ContainerInfo
ConvertToContainerInfo converts ContainerData to ContainerInfo.
type ErrorPayload ¶
ErrorPayload is an error message payload.
type InboundListener ¶
type InboundListener struct {
// contains filtered or unexported fields
}
InboundListener is the WebSocket server for agent inbound mode. Agent listens and waits for Main to connect.
func NewInboundListener ¶
func NewInboundListener(cfg *config.Config, prov provider.Provider) *InboundListener
NewInboundListener creates a new agent inbound listener.
func (*InboundListener) IsConnected ¶
func (l *InboundListener) IsConnected() bool
IsConnected returns whether the listener has an active connection.
type Message ¶
type Message struct {
Type MessageType `json:"type"`
RequestID string `json:"request_id,omitempty"`
Payload json.RawMessage `json:"payload,omitempty"`
}
Message is the WebSocket message envelope.
func NewMessage ¶
func NewMessage(msgType MessageType, payload interface{}) (*Message, error)
NewMessage creates a new message with the given type and payload.
func NewMessageWithID ¶
func NewMessageWithID(msgType MessageType, requestID string, payload interface{}) (*Message, error)
NewMessageWithID creates a new message with request ID.
func (*Message) ParsePayload ¶
ParsePayload parses the payload into the given type.
type MessageType ¶
type MessageType string
MessageType defines the type of WebSocket message.
const ( // MessageTypeAuth is sent by agent to authenticate. MessageTypeAuth MessageType = "auth" // MessageTypeReport is sent by agent to report data. MessageTypeReport MessageType = "report" // MessageTypeQuery is sent by main to query agent. MessageTypeQuery MessageType = "query" // MessageTypeCommand is sent by main to send commands. MessageTypeCommand MessageType = "command" // MessageTypeResponse is a response to query/command. MessageTypeResponse MessageType = "response" // MessageTypeAck is an acknowledgment message. MessageTypeAck MessageType = "ack" // MessageTypeError is an error message. MessageTypeError MessageType = "error" // MessageTypeHeartbeat is a heartbeat/ping message. MessageTypeHeartbeat MessageType = "heartbeat" )
type QueryPayload ¶
type QueryPayload struct {
Action string `json:"action"`
}
QueryPayload is the query message payload.
type ReportPayload ¶
type ReportPayload struct {
AgentID string `json:"agent_id"`
Timestamp time.Time `json:"timestamp"`
PublicIP string `json:"public_ip,omitempty"`
Containers []*ContainerData `json:"containers"`
Health *AgentHealth `json:"health"`
}
ReportPayload is the data report message payload.
type ResponsePayload ¶
type ResponsePayload struct {
Success bool `json:"success"`
Data json.RawMessage `json:"data,omitempty"`
Error string `json:"error,omitempty"`
}
ResponsePayload is a generic response payload.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the WebSocket server for agent connections.
func NewServer ¶
func NewServer(cfg *config.AgentServerConfig, agentConfigs map[string]*AgentConfigEntry, rec *reconciler.Reconciler, store storage.Storage, labelPrefix string) *Server
NewServer creates a new agent server.
func (*Server) ConnectToInboundAgents ¶
ConnectToInboundAgents starts goroutines to connect to all agents that have ConnectTo configured (inbound mode). Each connection runs in its own goroutine with automatic reconnection.
func (*Server) GetConnectedAgents ¶
GetConnectedAgents returns list of connected agents.
func (*Server) IsAgentConnected ¶
IsAgentConnected checks if an agent is connected.
func (*Server) SendCommand ¶
SendCommand sends a command to an agent.