dns

package
v0.5.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const CheckName = "dns"

Variables

This section is empty.

Functions

func NewCheck

func NewCheck() checks.Check

NewCheck creates a new instance of the dns check

Types

type Config

type Config struct {
	Targets  []string           `json:"targets" yaml:"targets"`
	Interval time.Duration      `json:"interval" yaml:"interval"`
	Timeout  time.Duration      `json:"timeout" yaml:"timeout"`
	Retry    helper.RetryConfig `json:"retry" yaml:"retry"`
}

Config defines the configuration parameters for a DNS check

func (*Config) For

func (c *Config) For() string

For returns the name of the check

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid

type DNS

type DNS struct {
	checks.CheckBase
	// contains filtered or unexported fields
}

DNS is a check that resolves the names and addresses

func (*DNS) GetConfig

func (d *DNS) GetConfig() checks.Runtime

func (*DNS) GetMetricCollectors

func (d *DNS) GetMetricCollectors() []prometheus.Collector

GetMetricCollectors returns all metric collectors of check

func (*DNS) Name

func (d *DNS) Name() string

func (*DNS) RemoveLabelledMetrics

func (d *DNS) RemoveLabelledMetrics(target string) error

RemoveLabelledMetrics removes the metrics which have the passed target as a label

func (*DNS) Run

func (d *DNS) Run(ctx context.Context, cResult chan checks.ResultDTO) error

Run starts the dns check

func (*DNS) Schema

func (d *DNS) Schema() (*openapi3.SchemaRef, error)

Schema provides the schema of the data that will be provided by the dns check

func (*DNS) Shutdown

func (d *DNS) Shutdown()

func (*DNS) UpdateConfig

func (d *DNS) UpdateConfig(cfg checks.Runtime) error

type Resolver

type Resolver interface {
	LookupAddr(ctx context.Context, addr string) ([]string, error)
	LookupHost(ctx context.Context, addr string) ([]string, error)
	SetDialer(d *net.Dialer)
}

func NewResolver

func NewResolver() Resolver

type ResolverMock

type ResolverMock struct {
	// LookupAddrFunc mocks the LookupAddr method.
	LookupAddrFunc func(ctx context.Context, addr string) ([]string, error)

	// LookupHostFunc mocks the LookupHost method.
	LookupHostFunc func(ctx context.Context, addr string) ([]string, error)

	// SetDialerFunc mocks the SetDialer method.
	SetDialerFunc func(d *net.Dialer)
	// contains filtered or unexported fields
}

ResolverMock is a mock implementation of Resolver.

func TestSomethingThatUsesResolver(t *testing.T) {

	// make and configure a mocked Resolver
	mockedResolver := &ResolverMock{
		LookupAddrFunc: func(ctx context.Context, addr string) ([]string, error) {
			panic("mock out the LookupAddr method")
		},
		LookupHostFunc: func(ctx context.Context, addr string) ([]string, error) {
			panic("mock out the LookupHost method")
		},
		SetDialerFunc: func(d *net.Dialer)  {
			panic("mock out the SetDialer method")
		},
	}

	// use mockedResolver in code that requires Resolver
	// and then make assertions.

}

func (*ResolverMock) LookupAddr

func (mock *ResolverMock) LookupAddr(ctx context.Context, addr string) ([]string, error)

LookupAddr calls LookupAddrFunc.

func (*ResolverMock) LookupAddrCalls

func (mock *ResolverMock) LookupAddrCalls() []struct {
	Ctx  context.Context
	Addr string
}

LookupAddrCalls gets all the calls that were made to LookupAddr. Check the length with:

len(mockedResolver.LookupAddrCalls())

func (*ResolverMock) LookupHost

func (mock *ResolverMock) LookupHost(ctx context.Context, addr string) ([]string, error)

LookupHost calls LookupHostFunc.

func (*ResolverMock) LookupHostCalls

func (mock *ResolverMock) LookupHostCalls() []struct {
	Ctx  context.Context
	Addr string
}

LookupHostCalls gets all the calls that were made to LookupHost. Check the length with:

len(mockedResolver.LookupHostCalls())

func (*ResolverMock) SetDialer

func (mock *ResolverMock) SetDialer(d *net.Dialer)

SetDialer calls SetDialerFunc.

func (*ResolverMock) SetDialerCalls

func (mock *ResolverMock) SetDialerCalls() []struct {
	D *net.Dialer
}

SetDialerCalls gets all the calls that were made to SetDialer. Check the length with:

len(mockedResolver.SetDialerCalls())

Jump to

Keyboard shortcuts

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