checker

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package checker implements the checkers and probers for the various protocols.

For any checker it is required that the type implements the Checker interface.

Further, a checker can be used to either just validate the check input using the validate method:

if err := checker.Validate(checkConfig); err != nil {
	// handle error
}

NewControllerOpts can be used to create a controller options from the check config which can be paired with a controller which executes checker at regular intervals of time.

This package also contains some helpers which are common to use among checkers, such as, regex for checking if the address is valid or not or if the err is timeout.

Index

Constants

View Source
const MaxMessageSize = 65536

MaxMessageSize is the maximum size of the message that can be sent or received.

Variables

View Source
var (
	ErrValidation   = fmt.Errorf("validation error")
	ErrProvisioning = fmt.Errorf("provisioning error")
)

Various errors thrown by a checker.

View Source
var AddressRegex *regexp.Regexp

AddressRegex is the regex pattern that is needs to be matched by an address.

Functions

func ErrIsTimeout

func ErrIsTimeout(err error) bool

ErrIsTimeout returns true for a timeout error.

func NewControllerOpts

func NewControllerOpts(check Check) (*controller.Opts, error)

NewControllerOpts creates controller options for the check.

func Register

func Register(name string, fn newFunc)

Register adds a new checker to the package. This does not throw an error, rather panics if the checker with the same name is already registered, hence a checker should be registered inside the init method of the package.

func Validate

func Validate(check Check) error

Validate validates the check config. This method is meant to be used only when needed to validate if the check conf is correct.

func ValidateComponent

func ValidateComponent(c Component, m map[string]validateComponentFunc) error

ValidateComponent takes a map of types and validation of their values function and validates the component.

Types

type Check

type Check interface {
	GetID() string   // Returns the ID.
	GetName() string // Returns the name.

	GetInterval() time.Duration // Returns the interval after which check is run.
	GetTimeout() time.Duration  // Returns the timeout.

	GetInput() Component      // Returns the input.
	GetOutput() Component     // Returns the output.
	GetTarget() Component     // Returns the target.
	GetPayloads() []Component // Returns the payloads.
}

Check is the interface which every check that needs to be processed here should implement.

type Checker

type Checker interface {
	// Validate validates the check configuration.
	Validate(Check) error

	// Provision is run to set the checker fields after the check
	// configuration is validated.
	Provision(Check) error

	// Execute executes the check and returns the result.
	Execute(context.Context) (*Result, error)
}

Checker is something that probes the provided target and marks it's run as successful or not. This depends on the fact that whether the output received matches the desired output provided by the user or not.

type Component

type Component interface {
	GetType() string  // Returns the type.
	GetValue() string // Returns the value.
}

Component is the Type Value component for check components like Input, Output, Target etc.

type Metric

type Metric interface {
	GetCheckID() string
	GetCheckName() string

	IsSuccessful() bool
	IsTimeout() bool

	GetStartTime() time.Time
	GetDuration() time.Duration
}

Metric is anything that tells if the check is successful or not. It also tells if the check timed out, the start time and duration of check.

type Result

type Result struct {
	Successful bool
	Timeout    bool
	StartTime  time.Time
	Duration   time.Duration
}

Result is the checker result returned after a check exec has been completed.

Result also implements the metrics.Metric interface so it can be exported.

Directories

Path Synopsis
Package dns implements the DNS checker and prober.
Package dns implements the DNS checker and prober.
Package http implements the HTTP checker and prober.
Package http implements the HTTP checker and prober.
Package icmp implements the ICMP checker and prober.
Package icmp implements the ICMP checker and prober.
Package tcp implements the TCP checker and prober.
Package tcp implements the TCP checker and prober.
Package udp implements the UDP checker and prober.
Package udp implements the UDP checker and prober.
Package ws implements the WS checker and prober.
Package ws implements the WS checker and prober.

Jump to

Keyboard shortcuts

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