Documentation ¶
Overview ¶
Package woodwatch provides a server for monitoring peers by ICMP echo request keepalives.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoPeerName is returned from PeerConfig.Valid() when the PeerConfig doesn't // have a Name. ErrNoPeerName = errors.New("All PeerConfigs must have a Name") // ErrNoPeerNetwork is returned from PeerConfig.Valid() when the PeerConfig // doesn't have a Network. ErrNoPeerNetwork = errors.New("All PeerConfigs must have a Network") )
var ( // ErrServerAlreadyListening is returned from Server.Listen when the Server is // already listening. ErrServerAlreadyListening = errors.New("Listen() can only be called once") // ErrServerNotListening is returned from Server.Close when the Server is not // listening. ErrServerNotListening = errors.New("Close() must be called after Listen()") // ErrEmptyListenAddress is returned from Server.Listen when the Server's // listen address is empty. ErrEmptyListenAddress = errors.New("Listen address must not be empty") // ErrTooFewPeers is returned from NewServer when there aren't enough // peers provided. ErrTooFewPeers = errors.New("One or more Peers must be configured") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // UpThreshold is how many cycles a peer needs to be sending ICMP echo // requests without timeout before it is considered up. Individual PeerConfigs // may set their own UpThreshold. UpThreshold uint // DownThreshold is how many cycles a peer needs to miss sending ICMP echo // requests before it is considered down. Individual PeerConfigs may set their // own DownThreshold. DownThreshold uint // MonitorCycle is a mandatory string describing the duration between checking // if a Peer has sent ICMP echo requests within the PeerTimeout. E.g. "4s", // "1m". MonitorCycle string // PeerTimeout is a mandatory string describing the duration within a Peer // must have sent ICMP echo requests to be considered seen recently during // a monitor cycle. E.g. "8s", "2m". PeerTimeout string // Webhook is an optional webhook URL to be POSTed for events. Individual // PeerConfigs may set their own Webhook. Webhook string // Peers is one or more PeerConfigs describing a peer to be monitored. Peers []PeerConfig }
Config describes the global woodwatch configuration and the peers to be monitored.
func LoadConfig ¶
LoadConfig loads a woodwatch.Config from the given data bytes.
func LoadConfigFile ¶
LoadConfigFile reads the data bytes from the file located at the provided filename and uses LoadConfig to return a woodwatch.Config from the file bytes.
func (Config) Valid ¶
Valid checks that a woodwatch Config is valid. If no peers are specified ErrTooFewPeers is returned. Each of the Peers specified will have their PeerConfig.Valid() function called and any errors will be returned. The MonitorCycle and PeerTimeout will both be parsed as time.Duration instances and any errors will be returned.
type PeerConfig ¶
type PeerConfig struct { // Name is the name of the peer. Supports :slack: emoji! Name string // Network is the string representation of a CIDR network. To be considered up // the peer must periodically send ICMP echo requests from a host within this // CIDR network. E.g. "192.168.1.0/24". Network string // UpThreshold is how many cycles the peer needs to be sending ICMP echo // requests without timeout before it is considered up. If zero the global // UpThreshold is used. UpThreshold uint // DownThreshold is how many cycles the peer needs to miss sending ICMP echo // requests before it is considered down. If zero the global DownThreshold is // used. DownThreshold uint // Webhook is an optional webhook to be POSTed for events. If not provided the // global Webhook is used. Webhook string }
PeerConfig is a struct holding configuration related to monitoring a Peer.
func (PeerConfig) Valid ¶
func (pc PeerConfig) Valid() error
Valid checks that a PeerConfig has a Name and Network or returns ErrNoPeerName/ErrNoPeerNetwork if the PeerConfig is not valid.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a struct for monitoring peers for keepalives received on a icmp.PacketConn.
func NewServer ¶
NewServer constructs a woodwatch.Server for the given arguments and config or returns an error. The Server will not be running and listening for ICMP messages until it is explicitly started by calling Server.Listen()
func (*Server) Close ¶
Close closes the Server's PacketConn and stops listening for ICMP messages on the Server's listen address. If Close is called before Listen it will return ErrServerNotListening.
func (*Server) Listen ¶
Listen opens a PacketConn for the Server's listen address that will listen for ICMP packets. If Listen is called on a Server with an empty listen address it will return ErrEmptyListeningAddress. If Listen is called more than once it will return ErrServerAlreadyListening for all calls after the first.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
woodwatch
Package main provides the `woodwatch` binary.
|
Package main provides the `woodwatch` binary. |
internal
|
|
states
Package states provides peer state tracking.
|
Package states provides peer state tracking. |
webhook
Package webhook describes woodwatch events and webhook URLs they can be POSTed to.
|
Package webhook describes woodwatch events and webhook URLs they can be POSTed to. |