Documentation ¶
Index ¶
Constants ¶
const ( // MessageTypeKeepalive is the message type sent for keepalives--which are just an // event without a Check or Metrics section. MessageTypeKeepalive = "keepalive" // MessageTypeEvent is the message type string for events. MessageTypeEvent = "event" // HeaderKeyAgentName is the HTTP request header specifying the Agent name HeaderKeyAgentName = "Sensu-AgentName" // HeaderKeyNamespace is the HTTP request header specifying the Agent Namespace HeaderKeyNamespace = "Sensu-Namespace" // HeaderKeyUser is the HTTP request header specifying the Agent User HeaderKeyUser = "Sensu-User" // HeaderKeySubscriptions is the HTTP request header specifying the Agent Subscriptions HeaderKeySubscriptions = "Sensu-Subscriptions" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClosedError ¶
type ClosedError struct {
Message string
}
A ClosedError is returned when Receive or Send is called on a closed Transport.
func (ClosedError) Error ¶
func (e ClosedError) Error() string
type ConnectionError ¶
type ConnectionError struct {
Message string
}
A ConnectionError is returned when a Transport receives any unexpected error connecting to, sending to, or receiving from a backend.
func (ConnectionError) Error ¶
func (e ConnectionError) Error() string
type Message ¶
type Message struct { // Type is the type of the message (event, etc) Type string // Payload is the serialized message. Payload []byte // SendCallback is a callback that is executed after a Send operation. // The error value of Send is passed to the callback. SendCallback func(error) }
A Message is a tuple of a message type (i.e. channel) and a byte-array payload to be sent across the transport.
func NewMessage ¶
NewMessage creates a new Message.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server ...
type Transport ¶
type Transport interface { // Close will cleanly shutdown a sensu transport connection. Close() error // Closed returns true if the underlying connection is closed. Closed() bool // Receive is used to receive a message from the transport. It takes a context // and blocks until the next message is received from the transport. Receive() (*Message, error) // Send is used to send a message over the transport. It takes a message type // hint and a serialized payload. Send will block until the message has been // sent. Send is synchronous, returning nil if the write to the underlying // socket was successful and an error otherwise. Send(*Message) error }
The Transport interface defines the set of methods available to a connection between the Sensu backend and agent.
func Connect ¶
func Connect(wsServerURL string, tlsOpts *types.TLSOptions, requestHeader http.Header) (Transport, error)
Connect causes the transport Client to connect to a given websocket backend. This is a thin wrapper around a websocket connection that makes the connection safe for concurrent use by multiple goroutines.
func NewTransport ¶
NewTransport creates an initialized Transport and return its pointer.
type WebSocketTransport ¶
type WebSocketTransport struct { Connection *websocket.Conn // contains filtered or unexported fields }
A WebSocketTransport is a connection between sensu Agents and Backends over WebSocket.
func (*WebSocketTransport) Close ¶
func (t *WebSocketTransport) Close() error
Close attempts to send a "going away" message over the websocket connection. This will cause a Write over the websocket transport, which can cause a panic. We rescue potential panics and consider the connection closed, returning nil, because the connection _will_ be closed. Hay!
func (*WebSocketTransport) Closed ¶
func (t *WebSocketTransport) Closed() bool
Closed returns true if the underlying websocket connection has been closed.
func (*WebSocketTransport) Receive ¶
func (t *WebSocketTransport) Receive() (*Message, error)
Receive a message over the websocket connection. Like Send, returns either a ClosedError or a ConnectionError if unable to receive a message. Receive blocks until the connection has a message ready or a timeout is reached.
func (*WebSocketTransport) Send ¶
func (t *WebSocketTransport) Send(m *Message) (err error)
Send a message over the websocket connection. If the connection has been closed, returns a ClosedError. Returns a ConnectionError if the websocket connection returns an error while sending, but the connection is still open.