beater

package
v5.4.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2017 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTarget

func AddTarget(target *targetConfig, privileged bool, ipv4 bool, ipv6 bool) pool.WorkFunc

AddTarget takes a target name and tag, fetches the IP addresses associated with it and adds them to the Pingbeat struct

func New

func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error)

New creates a new Pingbeat beater struct

func NewTargets

func NewTargets(cfg []*common.Config, privileged bool, ipv4 bool, ipv6 bool) map[string]Target

func RecvPings

func RecvPings(myID int, bt *Pingbeat, state *PingState, conn *icmp.PacketConn)

RecvPings listens for ICMP messages, decodes them into the right type and checks if they were sent by this Pingbeat, before processing them

func SendPing

func SendPing(conn *icmp.PacketConn, timeout time.Duration, seq int, addr net.Addr) pool.WorkFunc

SendPing sends an ICMP EchoRequest packet to with provided sequence number to the provided target through the given connection

Types

type PingInfo

type PingInfo struct {
	ID         int
	Seq        int
	Target     string
	Sent       time.Time
	Received   time.Time
	RTT        time.Duration
	Loss       bool
	LossReason string
}

PingInfo contains details about active ping requests/replies

type PingRecord

type PingRecord struct {
	Target string
	Sent   time.Time
}

PingRecord is used to hold when a EchoRequest was sent to a target

func NewPingRecord

func NewPingRecord(target string) *PingRecord

NewPingRecord creates a new PingRecord for the given target

type PingState

type PingState struct {
	MU      sync.RWMutex
	Pings   map[int]*PingRecord
	SeqNo   int
	Timeout time.Duration
}

PingState is used to keep track of active EchoRequests

func NewPingState

func NewPingState() *PingState

NewPingState initialises the PingState struct

func (*PingState) AddPing

func (p *PingState) AddPing(target string, seq int, sent time.Time) bool

AddPing adds a new request to PingState

func (*PingState) CalcPingRTT

func (p *PingState) CalcPingRTT(seq int, received time.Time) time.Duration

CalcPingRTT calculates the time since a request was sent, e.g., the RTT

func (*PingState) CleanPings

func (p *PingState) CleanPings(timeout time.Duration)

CleanPings reaps requests in PingState that have timed out (i.e., no response received before Pingbeat global timeout)

func (*PingState) DelPing

func (p *PingState) DelPing(seq int) pool.WorkFunc

DelPing removes a request from PingState

func (*PingState) GetSeqNo

func (p *PingState) GetSeqNo() int

GetSeqNo generates a new unique sequence number for an EchoRequest

type Pingbeat

type Pingbeat struct {
	// contains filtered or unexported fields
}

Pingbeat contains configuration details

func (*Pingbeat) ProcessPing

func (bt *Pingbeat) ProcessPing(ping *PingInfo)

ProcessPing fetches the details of this ping from the current state and then creates an ping event to be published

func (*Pingbeat) Run

func (bt *Pingbeat) Run(b *beat.Beat) error

Run is the main loop which sends/recieves ICMP messages and cleans up stale requests

func (*Pingbeat) Stop

func (bt *Pingbeat) Stop()

Stop cleans up Pingbeat

type Target

type Target struct {
	Addr net.Addr
	Name string
	Tags []string
	Desc string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL