config

package
v4.0.0-...-5981c31 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: BSD-2-Clause, BSD-2-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package config provides a common base for Gravwell ingester config files. The ingester will typically need to extend the config struct to allow configuration of data sources. An ingester might implement something like the following:

type cfgType struct {
	Global       config.IngestConfig
	Listener     map[string]*lst
	Preprocessor processors.ProcessorConfig
}

func GetConfig(path string) (*cfgType, error) {
	var cr cfgType
	if err := config.LoadConfigFile(&cr, path); err != nil {
		return nil, err
	}
	if err := cr.Global.Verify(); err != nil {
		return nil, err
	}
	// Verify and set UUID
	if _, ok := cr.Global.IngesterUUID(); !ok {
		id := uuid.New()
		if err := cr.Global.SetIngesterUUID(id, path); err != nil {
			return nil, err
		}
		if id2, ok := cr.Global.IngesterUUID(); !ok || id != id2 {
			return nil, errors.New("Failed to set a new ingester UUID")
		}
	}
	return c, nil
}

Index

Constants

View Source
const (
	DefaultCleartextPort uint16 = 4023
	DefaultTLSPort       uint16 = 4024

	CACHE_MODE_DEFAULT  = "always"
	CACHE_DEPTH_DEFAULT = 128
	CACHE_SIZE_DEFAULT  = 1000
)

Variables

View Source
var (
	ErrNoConnections              = errors.New("No connections specified")
	ErrMissingIngestSecret        = errors.New("Ingest-Secret value missing")
	ErrInvalidLogLevel            = errors.New("Invalid Log Level")
	ErrInvalidConnectionTimeout   = errors.New("Invalid connection timeout")
	ErrGlobalSectionNotFound      = errors.New("Global config section not found")
	ErrInvalidLineLocation        = errors.New("Invalid line location")
	ErrInvalidUpdateLineParameter = errors.New("Update line location does not contain the specified paramter")
)
View Source
var (
	ErrInvalidArg   = errors.New("Invalid arguments")
	ErrEmptyEnvFile = errors.New("Environment secret file is empty")
	ErrBadValue     = errors.New("Environment value is invalid")
)
View Source
var (
	ErrConfigFileTooLarge     = errors.New("Config file is too large")
	ErrFailedFileRead         = errors.New("Failed to read entire config file")
	ErrConfigNotOpen          = errors.New("Configuration is not open")
	ErrInvalidImportInterface = errors.New("Invalid import interface argument")
	ErrInvalidImportParameter = errors.New("parameter is not a pointer")
	ErrInvalidArgument        = errors.New("Invalid argument")
	ErrInvalidMapKeyType      = errors.New("invalid map key type, must be string")
	ErrInvalidMapValueType    = errors.New("invalid map value type, must be pointer to struct")
	ErrBadMap                 = errors.New("VariableConfig has not be initialized")
	ErrNotFound               = errors.New("not found")
	ErrIsNotDirectory         = errors.New("path is not a directory")
)

Functions

func AppendDefaultPort

func AppendDefaultPort(bstr string, defPort uint16) string

AppendDefaultPort will append the network port in defPort to the address in bstr, provided the address does not already contain a port. Thus, AppendDefaultPort("10.0.0.1", 4023) will return "10.0.0.1:4023", but AppendDefaultPort("10.0.0.1:5555", 4023) will return "10.0.0.1:5555".

func LoadConfigBytes

func LoadConfigBytes(v interface{}, b []byte) error

LoadConfigBytes parses the contents of b into the given interface v.

func LoadConfigFile

func LoadConfigFile(v interface{}, p string) (err error)

LoadConfigFile will open a config file, check the file size and load the bytes using LoadConfigBytes

func LoadConfigOverlays

func LoadConfigOverlays(v interface{}, pth string) (err error)

LoadConfigOverlays scans the given directory path for files that end in .conf if they exist we load them up into the interface

func LoadEnvVar

func LoadEnvVar(cnd interface{}, envName string, defVal interface{}) error

Attempts to read a value from environment variable named envName If there's nothing there, it attempt to append _FILE to the variable name and see if it contains a filename; if so, it reads the contents of the file into cnd.

func ParseBool

func ParseBool(v string) (r bool, err error)

ParseBool attempts to parse the string v into a boolean. The following will return true:

  • "true"
  • "t"
  • "yes"
  • "y"
  • "1"

The following will return false:

  • "false"
  • "f"
  • "no"
  • "n"
  • "0"

All other values return an error.

func ParseInt64

func ParseInt64(v string) (i int64, err error)

ParseInt64 will attempt to turn the given string into a signed 64-bit integer.

func ParseRate

func ParseRate(s string) (bps int64, err error)

ParseRate parses a data rate, returning an integer bits per second. The rate string s should consist of numbers optionally followed by one of the following suffixes: k, kb, kbit, kbps, m, mb, mbit, mbps, g, gb, gbit, gbps. If no suffix is present, ParseRate assumes the string specifies bits per second.

func ParseSource

func ParseSource(v string) (b net.IP, err error)

ParseSource returns a net.IP byte buffer the returned buffer will always be a 32bit or 128bit buffer but we accept encodings as IPv4, IPv6, integer, hex encoded hash this function simply walks the available encodings until one works

func ParseUint64

func ParseUint64(v string) (i uint64, err error)

ParseUint64 will attempt to turn the given string into an unsigned 64-bit integer.

Types

type CustomTimeFormat

type CustomTimeFormat map[string]*TimeFormat

func (CustomTimeFormat) LoadFormats

func (ctf CustomTimeFormat) LoadFormats(tg *timegrinder.TimeGrinder) (err error)

func (CustomTimeFormat) Validate

func (ctf CustomTimeFormat) Validate() (err error)

type IngestConfig

type IngestConfig struct {
	IngestStreamConfig
	Ingester_Name              string   `json:",omitempty"`
	Ingest_Secret              string   `json:"-"` // DO NOT send this when marshalling
	Ingest_Secret_File         string   `json:"-"` // DO NOT send this when marshalling
	Connection_Timeout         string   `json:",omitempty"`
	Verify_Remote_Certificates bool     `json:"-"` //legacy, will be removed
	Insecure_Skip_TLS_Verify   bool     `json:",omitempty"`
	Cleartext_Backend_Target   []string `json:",omitempty"`
	Encrypted_Backend_Target   []string `json:",omitempty"`
	Pipe_Backend_Target        []string `json:",omitempty"`
	Log_Level                  string   `json:",omitempty"`
	Log_File                   string   `json:",omitempty"`
	Disable_Self_Ingest        bool     //do not ship logs via the gravwell tag
	Source_Override            string   `json:",omitempty"` // override normal source if desired
	Rate_Limit                 string   `json:",omitempty"`
	Ingester_UUID              string   `json:",omitempty"`
	Cache_Depth                int      `json:",omitempty"`
	Cache_Mode                 string   `json:",omitempty"`
	Ingest_Cache_Path          string   `json:",omitempty"`
	Max_Ingest_Cache           int      `json:",omitempty"`
	Log_Source_Override        string   `json:",omitempty"` // override log messages only
	Label                      string   `json:",omitempty"` //arbitrary label that can be attached to an ingester
	Disable_Multithreading     bool     //basically set GOMAXPROCS(1)
	Stats_Sample_Interval      string   `json:",omitempty"` // if set to > 0 duration then we periodically throw stats
}

func (*IngestConfig) AddLocalLogging

func (ic *IngestConfig) AddLocalLogging(lg *log.Logger)

func (*IngestConfig) GetLogger

func (ic *IngestConfig) GetLogger() (l *log.Logger, err error)

func (*IngestConfig) IngesterUUID

func (ic *IngestConfig) IngesterUUID() (id uuid.UUID, ok bool)

IngesterUUID returns the UUID of this ingester, set with the `Ingester-UUID` parameter. If the UUID is not set, the UUID is invalid, or the UUID is all zeroes, the function will return ok = false. If the UUID is valid, it returns the UUID and ok = true.

func (*IngestConfig) InsecureSkipTLSVerification

func (ic *IngestConfig) InsecureSkipTLSVerification() bool

InsecureSkipTLSVerification returns true if the Insecure-Skip-TLS-Verify config parameter was set.

func (*IngestConfig) LogLevel

func (ic *IngestConfig) LogLevel() string

Return the specified log level

func (*IngestConfig) RateLimit

func (ic *IngestConfig) RateLimit() (bps int64, err error)

RateLimit returns the bandwidth limit, in bits per second, which should be applied to the indexer connection.

func (*IngestConfig) Secret

func (ic *IngestConfig) Secret() string

Secret returns the value of the Ingest-Secret parameter, used to authenticate to the indexer.

func (*IngestConfig) SelfIngest

func (ic *IngestConfig) SelfIngest() bool

func (*IngestConfig) SetIngesterUUID

func (ic *IngestConfig) SetIngesterUUID(id uuid.UUID, loc string) (err error)

SetIngesterUUID modifies the configuration file at loc, setting the Ingester-UUID parameter to the given UUID. This function allows ingesters to assign themselves a UUID if one is not given in the configuration file.

func (*IngestConfig) StatsSampleInterval

func (ic *IngestConfig) StatsSampleInterval() (dur time.Duration)

func (*IngestConfig) Targets

func (ic *IngestConfig) Targets() ([]string, error)

Targets returns a list of indexer targets, including TCP, TLS, and Unix pipes. Each target will be prepended with the connection type, e.g.:

tcp://10.0.0.1:4023

func (*IngestConfig) Timeout

func (ic *IngestConfig) Timeout() time.Duration

Timeout returns the timeout for an ingester connection to go live before giving up.

func (*IngestConfig) Verify

func (ic *IngestConfig) Verify() error

Verify checks the configuration parameters of the IngestConfig, verifying that there is at least one indexer target, creating directories as necessary, and generally making sure values are sensible.

type IngestStreamConfig

type IngestStreamConfig struct {
	Enable_Compression bool `json:",omitempty"`
}

type TimeFormat

type TimeFormat struct {
	Format           string
	Regex            string
	Extraction_Regex string
}

type VariableConfig

type VariableConfig struct {
	gcfg.Idxer
	Vals map[gcfg.Idx]*[]string
}

func (VariableConfig) GetBool

func (vc VariableConfig) GetBool(name string) (r bool, err error)

func (VariableConfig) GetFloat

func (vc VariableConfig) GetFloat(name string) (r float64, err error)

func (VariableConfig) GetInt

func (vc VariableConfig) GetInt(name string) (r int64, err error)

func (VariableConfig) GetString

func (vc VariableConfig) GetString(name string) (r string, err error)

func (VariableConfig) GetStringSlice

func (vc VariableConfig) GetStringSlice(name string) (r []string, err error)

func (VariableConfig) GetUint

func (vc VariableConfig) GetUint(name string) (r uint64, err error)

func (VariableConfig) MapTo

func (vc VariableConfig) MapTo(v interface{}) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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