config

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPollFrequency = 30 * time.Second

Variables

View Source
var (
	DefaultConfig Config = Config{
		PollFrequency: model.Duration(DefaultPollFrequency),
	}

	DefaultHostConfig HostConfig = HostConfig{
		PollFrequency: DefaultConfig.PollFrequency,
	}

	DefaultBasicServiceConfig = BasicServiceConfig{
		Protocol: "tcp",
	}

	DefaultChallengeResponseServiceConfig = ChallengeResponseConfig{
		BasicServiceConfig: DefaultBasicServiceConfig,
	}

	DefaultHTTPServiceConfig = HTTPServiceConfig{
		ChallengeResponseConfig: DefaultChallengeResponseServiceConfig,
	}
)
View Source
var (
	ErrUnknownFields = errors.New("unknown fields in config map")
)

Functions

func Save

func Save(cfg *Config) ([]byte, error)

Types

type BasicServiceConfig

type BasicServiceConfig struct {
	Name     string         `yaml:"name"`              // Name of the service
	Protocol string         `yaml:"proto,omitempty"`   // TCP or UDP
	Port     uint64         `yaml:"port"`              // Port number of the service
	Timeout  model.Duration `yaml:"timeout,omitempty"` // Number of seconds to wait for response
	UseSSL   bool           `yaml:"ssl,omitempty"`     // The service uses SSL

}

A basic network service.

func (*BasicServiceConfig) UnmarshalYAML

func (bsc *BasicServiceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

type Bytes

type Bytes []byte

Bytes implements a custom []byte slice so we can unmarshal one from an escaped string.

func (*Bytes) MarshalYAML

func (b *Bytes) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*Bytes) UnmarshalYAML

func (b *Bytes) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type ChallengeResponseConfig

type ChallengeResponseConfig struct {
	BasicServiceConfig `yaml:",inline,omitempty"`
	ChallengeLiteral   *Bytes  `yaml:"challenge,omitempty"`
	ResponseRegex      *Regexp `yaml:"response_re,omitempty"` // Regex that must match
	ResponseLiteral    *Bytes  `yaml:"response,omitempty"`    // Literal string that must match
	MaxBytes           uint64  `yaml:"max_bytes,omitempty"`   // Maximum number of bytes to read while looking for the response regex. 0 means read until connection closes.
}

Similar to a banner check, but first sends the specified data befoe looking for a response.

func (*ChallengeResponseConfig) UnmarshalYAML

func (chrc *ChallengeResponseConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

type ChallengeResponseConfigValidationError

type ChallengeResponseConfigValidationError struct {
	ServiceDescription string
}

func (ChallengeResponseConfigValidationError) Error

type Config

type Config struct {
	BasicAuthUsername string `yaml:"username,omitempty"` // If set, enables basic auth
	BasicAuthPassword string `yaml:"password,omitempty"` // If set, enables basic auth (must have a username)

	TLSCertificatePath string `yaml:"tls_cert,omitempty"` // Path to TLS certificate. Enables TLS if specified.
	TLSKeyPath         string `yaml:"tls_key,omitempty"`  // Path to TLS key file. Enables TLS if specified.

	PollFrequency model.Duration `yaml:"poll_frequency,omitempty"` // Default polling frequency for hosts
	PingTimeout   model.Duration `yaml:"ping_timeout,omitempty"`   // Default ping time out for hosts
	Timeout       model.Duration `yaml:"timeout,omitempty"`        // Default service IO timeout
	MaxBytes      uint64         `yaml:"max_bytes,omitempty"`      // Default maximum bytes to read from services
	PingDisable   bool           `yaml:"disable_ping,omitempty"`   // Disable ping checks by default
	PingCount     uint64         `yaml:"ping_count,omitempty"`     // Number of pings to send

	Hosts []HostConfig `yaml:"hosts"` // List of hosts which are to be polled

	XXX map[string]interface{} `yaml:",omitempty"` // Catch any unknown flags.

	OriginalConfig string // Original config file contents
}

func Load

func Load(s string) (*Config, error)

func LoadFromFile

func LoadFromFile(filename string) (*Config, error)

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

type HTTPServiceConfig

type HTTPServiceConfig struct {
	ChallengeResponseConfig `yaml:",inline,omitempty"`
	Verb                    string          `yaml:"verb,omitempty"`           // HTTP verb to use
	URL                     URL             `yaml:"url,omitempty"`            // HTTP request URL to send
	SuccessStatuses         HTTPStatusRange `yaml:"success_status,omitempty"` // List of status codes indicating success
	BasicAuth               bool            `yaml:"auth,omitempty"`           // Use HTTP basic auth
	Username                string          `yaml:"username,omitempty"`       // Username for HTTP basic auth
	Password                string          `yaml:"password,omitempty"`       // Password for HTTP basic auth
}

An HTTP speaking service. Does not yet support being a proxy. If UseSSL is not set but you request HTTPS, it'll fail.

func (*HTTPServiceConfig) UnmarshalYAML

func (hsc *HTTPServiceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

type HTTPStatusRange

type HTTPStatusRange map[int]bool

HTTPStatusRange is a range of HTTP status codes which can be specifid in YAML using human-friendly ranging notation.

func (HTTPStatusRange) MarshalYAML

func (hsr HTTPStatusRange) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*HTTPStatusRange) UnmarshalYAML

func (hsr *HTTPStatusRange) UnmarshalYAML(unmarshal func(interface{}) error) error

type HostConfig

type HostConfig struct {
	Hostname      string         `yaml:"hostname"`                 // Host or IP to contact
	PollFrequency model.Duration `yaml:"poll_frequency,omitempty"` // Frequency to poll this specific host
	PingDisable   bool           `yaml:"disable_ping,omitempty"`   // Disable ping checks for this host
	PingTimeout   model.Duration `yaml:"ping_timeout,omitempty"`   // Maximum ping timeout
	PingCount     uint64         `yaml:"ping_count,omitempty"`     // Number of pings to send each poll

	BasicChecks             []*BasicServiceConfig      `yaml:"basic_checks,omitempty"`
	ChallengeResponseChecks []*ChallengeResponseConfig `yaml:"challenge_response_checks,omitempty"`
	HTTPChecks              []*HTTPServiceConfig       `yaml:"http_checks,omitempty"`

	XXX map[string]interface{} `yaml:",omitempty"` // Catch any unknown flags.
}

Defines a host which we want to find service information about. Hosts export DNS checks.

func (*HostConfig) UnmarshalYAML

func (c *HostConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

type IPNetwork

type IPNetwork struct {
	net.IPNet
}

IPNetwork is the config wrapper type for an IP Network.

func (IPNetwork) MarshalYAML

func (ipn IPNetwork) MarshalYAML() (interface{}, error)

func (*IPNetwork) UnmarshalYAML

func (ipn *IPNetwork) UnmarshalYAML(unmarshal func(interface{}) error) error

type Regexp

type Regexp struct {
	regexp.Regexp
	// contains filtered or unexported fields
}

Regexp encapsulates a regexp.Regexp and makes it YAML marshallable.

func MustNewRegexp

func MustNewRegexp(s string) *Regexp

MustNewRegexp works like NewRegexp, but panics if the regular expression does not compile.

func NewRegexp

func NewRegexp(s string) (*Regexp, error)

NewRegexp creates a new anchored Regexp and returns an error if the passed-in regular expression does not compile.

func (*Regexp) MarshalYAML

func (re *Regexp) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*Regexp) UnmarshalYAML

func (re *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type URL

type URL struct {
	*url.URL
}

URL is a custom URL type that allows validation at configuration load time.

func (URL) MarshalYAML

func (u URL) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for URLs.

func (*URL) UnmarshalYAML

func (u *URL) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for URLs.

Jump to

Keyboard shortcuts

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