config

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: GPL-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package config defines the exporter configuration objects

Index

Constants

View Source
const (
	TLSCACertsSystem string = "system"
	ProxyEnvironment string = "environment"
	ProxyDirect      string = "direct"
)
View Source
const (
	TLSCertificatePoolMaxNonFileEntryReturn int = 50
)

Variables

View Source
var (
	ErrMapStructureDecode = errors.New("MapStructureDecode function failed")
	ErrInconsistentLabels = errors.New("Extra Prometheus labels found without defaults set")
)
View Source
var (
	ErrInvalidInputType = errors.New("invalid input type for decoder")
)
View Source
var (
	ErrInvalidPEMFile = errors.New("PEM file could not be added to certificate pool")
)

Functions

func Decoder added in v0.9.1

func Decoder(target interface{}, allowUnused bool) (*mapstructure.Decoder, error)

Decoder returns the decoder for config maps.

func DefaultConfigFile added in v0.9.1

func DefaultConfigFile() []byte

DefaultConfigFile returns the default embedded YAML config which sets the poller_defaults.

func LoadAndSanitizeConfig added in v0.9.1

func LoadAndSanitizeConfig(configData []byte) (string, error)

LoadAndSanitizeConfig is used purely for displaying the config to users. It removes sensitive keys from the config and provides a reserialized YAML view of it.

func MapStructureDecodeHookFunc added in v0.9.1

func MapStructureDecodeHookFunc() mapstructure.DecodeHookFuncType

MapStructureDecodeHookFunc returns a DecodeHookFunc that applies output to the UnmarshalYAML function, when the target type implements the yaml.Unmarshaller interface.

Types

type AuthConfig added in v0.9.1

type AuthConfig struct {
	BasicAuthCredentials []BasicAuthConfig `mapstructure:"basic_auth,omitempty"`
}

AuthConfig holds the configuration of any authentication put on the exporter interface.

type BasicAuthConfig added in v0.9.1

type BasicAuthConfig struct {
	Username string `mapstructure:"username,omitempty"` // Username to accept
	Password string `mapstructure:"password,omitempty"` // Plain text password to accept
}

BasicAuthConfig defines basic authentication credentials to accept on the web interface. If Password is not set, then the credential set is ignored. The password is plaintext.

type BasicServiceConfig

type BasicServiceConfig struct {
	BasicServiceSettings `mapstructure:",squash"`
	Name                 string `mapstructure:"name"`            // Name of the service
	Protocol             string `mapstructure:"proto,omitempty"` // TCP or UDP
	Port                 uint64 `mapstructure:"port"`            // Port number of the service
}

A basic network service.

type BasicServiceSettings added in v0.9.1

type BasicServiceSettings struct {
	Timeout                 model.Duration     `mapstructure:"timeout,omitempty"`             // Number of seconds to wait for response
	TLSEnable               bool               `mapstructure:"tls_enable,omitempty"`          // The service uses TLS
	TLSVerifyFailOk         bool               `mapstructure:"tls_verify_fail_ok,omitempty"`  // The service uses TLS
	TLSServerNameIndication *string            `mapstructure:"tls_sni_name,omitempty"`        // The TLS SNI name to send.
	TLSCertificatePin       *TLSCertificateMap `mapstructure:"tls_certificate_pin,omitempty"` // Map of certificates which *must* be returned by the service. If null, ignored.
	TLSCACerts              TLSCertificatePool `mapstructure:"tls_cacerts,omitempty"`         // Path to CAfile to verify the service TLS with
	Proxy                   string             `mapstructure:"proxy,omitempty"`               // Proxy configuration for the service
	ProxyAuth               *BasicAuthConfig   `mapstructure:"proxy_auth,omitempty"`          // Authentication for the proxy service
	ExtraLabels             map[string]string  `mapstructure:"extra_labels,omitempty"`        // Extra Prometheus Metrics to add to collected metrics
}

BasicServiceSettings are the common settings all services share.

type Bytes

type Bytes []byte

Bytes implements a custom []byte slice implemented TextMarshaller so base64 binary content can be passed n.

func (*Bytes) MarshalText added in v0.9.1

func (d *Bytes) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Bytes) UnmarshalText added in v0.9.1

func (d *Bytes) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type ChallengeResponseConfig

type ChallengeResponseConfig struct {
	BasicServiceConfig `mapstructure:",squash"`
	ChallengeString    *string `mapstructure:"challenge,omitempty"`
	ChallengeBinary    Bytes   `mapstructure:"challenge_b64,omitempty"` // Supercedes the string
	ResponseRegex      *Regexp `mapstructure:"response_re,omitempty"`   // Regex that must match. It is applied to the binary output.
	ResponseLiteral    *string `mapstructure:"response,omitempty"`      // Literal string that must match
	ResponseBinary     Bytes   `mapstructure:"response_b64,omitempty"`  // Literal bytes which must match - supercedes the string
	MaxBytes           uint64  `mapstructure:"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.

type ChallengeResponseConfigValidationError

type ChallengeResponseConfigValidationError struct {
	ServiceDescription string
}

func (ChallengeResponseConfigValidationError) Error

type ChallengeResponseServiceSettings added in v0.9.1

type ChallengeResponseServiceSettings struct {
	MaxBytes uint64 `mapstructure:"max_bytes,omitempty"` // Maximum number of bytes to read from connection for response searching
}

type CollectorConfig added in v0.9.1

type CollectorConfig struct {
	MaxConnections int `mapstructure:"max_connections,omitempty"`
}

CollectorConfig configures globals limits on the Prometheus metric collectors.

type Config

type Config struct {
	Web         *WebConfig       `mapstructure:"web,omitempty"`
	Collector   *CollectorConfig `mapstructure:"collector,omitempty"`
	HostDefault *HostSettings    `mapstructure:"host_defaults,omitempty"`
	Hosts       []*HostConfig    `mapstructure:"hosts,omitempty"`
}

Config is the top-level config item the.

func Load

func Load(configData []byte) (*Config, error)

Load loads a configuration file from the supplied bytes.

func LoadFromFile

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

type HTTPRequestAuth added in v0.9.1

type HTTPRequestAuth struct {
	BasicAuth *BasicAuthConfig `mapstructure:"basic_auth,omitempty"`
}

HTTPRequestAuth represents configuration for sending HTTP requests.

type HTTPServiceConfig

type HTTPServiceConfig struct {
	ChallengeResponseConfig `mapstructure:",squash"`
	HTTPSettings            `mapstructure:",squash"`
	Verb                    HTTPVerb        `mapstructure:"verb,omitempty"` // HTTP verb to use
	URL                     URL             `mapstructure:"url,omitempty"`  // HTTP request URL to send
	RequestAuth             HTTPRequestAuth `mapstructure:"auth,omitempty"` // Authentication configuration
}

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

type HTTPSettings added in v0.9.1

type HTTPSettings struct {
	HTTPMaxRedirects int64               `mapstructure:"http_max_redirects,omitempty"`
	EnableRedirects  bool                `mapstructure:"http_enable_redirects,omitempty"` // If set to true, does not follow redirects
	Headers          []map[string]string `mapstructure:"http_headers,omitempty"`          // HTTP request headers to set
	SuccessStatuses  HTTPStatusRange     `mapstructure:"http_success_status,omitempty"`   // List of status codes indicating success
}

HTTPSettings are inheritable HTTP settings.

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) FromString added in v0.9.1

func (hsr *HTTPStatusRange) FromString(ranges string) error

FromString initializes a new HTTPStatusRange from the given string specifier

func (HTTPStatusRange) MarshalText added in v0.9.1

func (hsr HTTPStatusRange) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler.

func (*HTTPStatusRange) UnmarshalText added in v0.9.1

func (hsr *HTTPStatusRange) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler.

type HTTPVerb added in v0.9.1

type HTTPVerb string

HTTPVerb wraps string to ensure that verbs are uppercase. It doesn't check if they're valid to allow people to do stupid things with them if they want.

func (*HTTPVerb) MarshalText added in v0.9.1

func (d *HTTPVerb) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (HTTPVerb) String added in v0.9.1

func (d HTTPVerb) String() string

func (*HTTPVerb) UnmarshalText added in v0.9.1

func (d *HTTPVerb) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type HostConfig

type HostConfig struct {
	Hostname     string `mapstructure:"hostname"` // Host or IP to contact
	HostSettings `mapstructure:",squash"`

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

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

type HostSettings added in v0.9.1

type HostSettings struct {
	PollFrequency model.Duration `mapstructure:"poll_frequency,omitempty"` // Frequency to poll this specific host
	PingDisable   bool           `mapstructure:"disable_ping,omitempty"`   // Disable ping checks for this host
	PingTimeout   model.Duration `mapstructure:"ping_timeout,omitempty"`   // Maximum ping timeout
	PingCount     uint64         `mapstructure:"ping_count,omitempty"`     // Number of pings to send each poll

	ExtraLabels map[string]string `mapstructure:"extra_labels,omitempty"` // Extra Prometheus Metrics to add to collected metrics

	ServiceDefaults ServiceSettings `mapstructure:"service_defaults,omitempty"`
}

HostSettings contains the poller configuration which is applied per hostname (as opposed to per service).

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 MapStructureDecoder added in v0.9.1

type MapStructureDecoder interface {
	MapStructureDecode(interface{}) error
}

MapStructureDecoder is detected by MapStructureDecodeHookFunc to allow a type to decode itself.

type ProxyURL added in v0.9.1

type ProxyURL string

ProxyURL is a custom type to validate roxy specifications.

func (*ProxyURL) MarshalText added in v0.9.1

func (p *ProxyURL) MarshalText() ([]byte, error)

UnmarshalText MarshalText encoding.UnmarshalText.

func (*ProxyURL) UnmarshalText added in v0.9.1

func (p *ProxyURL) UnmarshalText(text []byte) error

UnmarshalText implements encoding.UnmarshalText.

type Regexp

type Regexp struct {
	*regexp.Regexp
}

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

func (*Regexp) MarshalText added in v0.9.1

func (r *Regexp) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Regexp) UnmarshalText added in v0.9.1

func (r *Regexp) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type ServiceSettings added in v0.9.1

type ServiceSettings struct {
	BasicServiceSettings             `mapstructure:",squash"`
	ChallengeResponseServiceSettings `mapstructure:",squash"`
	HTTPSettings                     `mapstructure:",squash"`
}

ServiceSettings is used for declaring service defaults.

type Sum224 added in v0.12.0

type Sum224 [sha256.Size224]byte

TLSCertificateMap encodes a list of certificates and stores them in a hashmap for easy lookups. It is similar to the standard library CertPool.

type TLSCertificateMap added in v0.12.0

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

func (*TLSCertificateMap) AddCert added in v0.12.0

func (t *TLSCertificateMap) AddCert(cert *x509.Certificate) error

AddCert adds a certificate to a pool.

func (*TLSCertificateMap) GetCerts added in v0.12.0

func (t *TLSCertificateMap) GetCerts() []*x509.Certificate

func (*TLSCertificateMap) HasCert added in v0.12.0

func (t *TLSCertificateMap) HasCert(cert *x509.Certificate) bool

func (*TLSCertificateMap) HashCert added in v0.12.0

func (t *TLSCertificateMap) HashCert(cert *x509.Certificate) Sum224

func (*TLSCertificateMap) MapStructureDecode added in v0.12.0

func (t *TLSCertificateMap) MapStructureDecode(input interface{}) error

MapStructureDecode implements unmarshalling for TLSCertificateMap nolint: funlen,cyclop

type TLSCertificatePool added in v0.9.1

type TLSCertificatePool struct {
	*x509.CertPool
	// contains filtered or unexported fields
}

TLSCertificatePool is our custom type for decoding a certificate pool out of YAML.

func (*TLSCertificatePool) MapStructureDecode added in v0.9.1

func (t *TLSCertificatePool) MapStructureDecode(input interface{}) error

MapStructureDecode implements the yaml.Unmarshaler interface for tls_cacerts.

type URL

type URL struct {
	*url.URL
}

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

func NewURL added in v0.9.1

func NewURL(url string) (URL, error)

func (*URL) MarshalText added in v0.9.1

func (u *URL) MarshalText() ([]byte, error)

MarshalYAML implements the yaml.Marshaler interface for URLs.

func (*URL) UnmarshalText added in v0.9.1

func (u *URL) UnmarshalText(text []byte) error

UnmarshalYAML implements the yaml.Unmarshaler interface for URLs.

type WebConfig added in v0.9.1

type WebConfig struct {
	TelemetryPath     string         `mapstructure:"telemetry_path,omitempty"`
	ReadHeaderTimeout model.Duration `mapstructure:"read_header_timeout,omitempty"`
	Listen            []URL          `mapstructure:"listen,omitempty"`
	Auth              *AuthConfig    `mapstructure:"auth,omitempty"`
}

WebConfig holds global configuration for the exporters webserver.

Jump to

Keyboard shortcuts

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