online

package
v0.0.0-...-3fea41a Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check interface {
	Execute(timeout time.Duration) Result
}

Check describes the interface of anything that can checked to be online

type CheckGroup

type CheckGroup struct {
	Checks  []Check
	Results []Result
}

Group combines multiple checks together and stores the results

func (*CheckGroup) Execute

func (g *CheckGroup) Execute(timeout time.Duration) Result

Execute runs all checks concurrently and groups the result:

- Result.Done is set to the end of the last check. - Result.Took is set to the longest check time. - Result.Okay is true if all checks passed.

type ICMPCheck

type ICMPCheck struct {
	Host string
}

Checks the availabilty of a host using `ping`

func (ICMPCheck) Execute

func (c ICMPCheck) Execute(timeout time.Duration) Result

type Printer

type Printer struct {
	Output              io.Writer
	Verbose             bool
	ConsecutiveFailures int
	Streak              map[string]*Streak
}

Printer provides snazzy result printing

func (*Printer) Print

func (p *Printer) Print(r Result)

Print outputs the current state

func (*Printer) Summary

func (p *Printer) Summary()

Summary outputs a total summary

type Result

type Result struct {
	// Time denotes the time the check completed
	Done time.Time

	// Took contains how long it took
	Took time.Duration

	// Okay is true if the check succeeded
	Okay bool

	// Consecutive is the number of results that came before with the same
	// result, including this one (i.e., it starts at 1).
	Consecutive int

	// Duration since the last time the result changed to ok, or from ok.
	Duration time.Duration

	// Hints contains a textual representation of the result
	Hints []string

	// Target identifies the target this result was run on
	Target *Target
}

Result contains the details of a check

func (Result) ShortText

func (o Result) ShortText() string

Text shows the result as single character

type Streak

type Streak struct {
	LongestOutage        time.Duration
	LongestFailureStreak int
}

Streak tracks how long something was online or offline

type TCPCheck

type TCPCheck struct {
	Host string
	Port uint16
}

Checks if a TCP handshake can be made

func (TCPCheck) Execute

func (c TCPCheck) Execute(timeout time.Duration) Result

type Target

type Target struct {

	// ID is the unique name or address of the target
	ID string

	// Label is an optional identifier
	Label string

	// Address points at the address of the host
	Host string

	// Check that determines whether the target is online
	Check Check
}

Target points at a single host that needs to be checked for packetloss

func (*Target) Title

func (t *Target) Title() string

type Watch

type Watch struct {
	Targets  []string
	NoTCP    bool
	NoICMP   bool
	Verbose  bool
	Timeout  int
	Interval int
	Port     int
}

func (*Watch) ParseAddress

func (w *Watch) ParseAddress(host string) (string, uint16, error)

ParseAddress takes a target without label, and returns the host and the port it includes, if given.

func (*Watch) ParseTargets

func (w *Watch) ParseTargets() ([]Target, error)

func (*Watch) Run

func (w *Watch) Run(ctx context.Context, results chan<- Result) error

Run starts the workers watching the targets and returns once they are started. Results are then pushed out through the results channel.

To stop the workers from running, cancel the given context.

Returns an error if the targets could not be parsed

Jump to

Keyboard shortcuts

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