cfgfile

package
v6.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDynamicConfig = DynamicConfig{
		Reload: Reload{
			Period:  10 * time.Second,
			Enabled: false,
		},
	}
)

Functions

func ChangeDefaultCfgfileFlag

func ChangeDefaultCfgfileFlag(beatName string) error

ChangeDefaultCfgfileFlag replaces the value and default value for the `-c` flag so that it reflects the beat name.

func GetPathConfig

func GetPathConfig() string

GetPathConfig returns ${path.config}. If ${path.config} is not set, ${path.home} is returned.

func HandleFlags

func HandleFlags() error

HandleFlags adapts default config settings based on command line flags.

func IsTestConfig

func IsTestConfig() bool

IsTestConfig returns whether or not this is configuration used for testing

func Load

func Load(path string) (*common.Config, error)

Load reads the configuration from a YAML file structure. If path is empty this method reads from the configuration file specified by the '-c' command line flag.

func LoadList

func LoadList(file string) ([]*common.Config, error)

LoadList loads a list of configs data from the given file.

func Read deprecated

func Read(out interface{}, path string) error

Deprecated: Please use Load().

Read reads the configuration from a YAML file into the given interface structure. If path is empty this method reads from the configuration file specified by the '-c' command line flag.

Types

type CfgFile

type CfgFile struct {
	Name    string
	Path    string
	Enabled bool
}

type DynamicConfig

type DynamicConfig struct {
	// If path is a relative path, it is relative to the ${path.config}
	Path   string `config:"path"`
	Reload Reload `config:"reload"`
}

DynamicConfig loads config files from a given path, allowing to reload new changes while running the beat

type GlobManager

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

GlobManager allows to manage a directory of conf files. Using a glob pattern to match them, this object will allow to switch their state between enabled and disabled

func NewGlobManager

func NewGlobManager(glob, enabledExtension, disabledExtension string) (*GlobManager, error)

NewGlobManager takes a glob and enabled/disabled extensions and returns a GlobManager object. Parameters:

  • glob - matching conf files (ie: modules.d/*.yml)
  • enabledExtension - extension for enabled confs, must match the glob (ie: .yml)
  • disabledExtension - extension to append for disabled confs (ie: .disabled)

func (*GlobManager) Disable

func (g *GlobManager) Disable(name string) error

Disable given conf file, does nothing if it's disabled already

func (*GlobManager) Enable

func (g *GlobManager) Enable(name string) error

Enable given conf file, does nothing if it's enabled already

func (*GlobManager) Enabled

func (g *GlobManager) Enabled(name string) bool

Enabled returns true if given conf file is enabled

func (*GlobManager) Exists

func (g *GlobManager) Exists(name string) bool

Exists return true if the given conf exists (enabled or disabled)

func (*GlobManager) ListDisabled

func (g *GlobManager) ListDisabled() []*CfgFile

ListDisabled conf files

func (*GlobManager) ListEnabled

func (g *GlobManager) ListEnabled() []*CfgFile

ListEnabled conf files

type GlobWatcher

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

func NewGlobWatcher

func NewGlobWatcher(glob string) *GlobWatcher

func (*GlobWatcher) Scan

func (gw *GlobWatcher) Scan() ([]string, bool, error)

Scan scans all files matched by the glob and checks if the number of files or the modtime of the files changed It returns the list of files, a boolean if anything in the glob changed and potential errors. To detect changes not only mod time is compared but also the hash of the files list. This is required to also detect files which were removed. The modtime is compared based on second as normally mod-time is in seconds. If it is unclear if something changed the method will return true for the changes. It is strongly recommend to call scan not more frequent then 1s.

type Registry

type Registry struct {
	sync.RWMutex
	List map[uint64]Runner
}

Registry holds a list of Runners mapped by their unique hashes

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns a new empty Registry

func (*Registry) Add

func (r *Registry) Add(hash uint64, m Runner)

Add the given Runner to the list, indexed by a hash

func (*Registry) CopyList

func (r *Registry) CopyList() map[uint64]Runner

CopyList returns a static copy of the Runners map

func (*Registry) Get

func (r *Registry) Get(hash uint64) Runner

Get returns the Runner with the given hash, or nil if it doesn't exist

func (*Registry) Has

func (r *Registry) Has(hash uint64) bool

Has returns true if there is a Runner with the given hash

func (*Registry) Remove

func (r *Registry) Remove(hash uint64)

Remove the Runner with the given hash from the list

type Reload

type Reload struct {
	Period  time.Duration `config:"period"`
	Enabled bool          `config:"enabled"`
}

type Reloader

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

Reloader is used to register and reload modules

func NewReloader

func NewReloader(cfg *common.Config) *Reloader

NewReloader creates new Reloader instance for the given config

func (*Reloader) Check

func (rl *Reloader) Check(runnerFactory RunnerFactory) error

Check configs are valid (only if reload is disabled)

func (*Reloader) Run

func (rl *Reloader) Run(runnerFactory RunnerFactory)

Run runs the reloader

func (*Reloader) Stop

func (rl *Reloader) Stop()

Stop stops the reloader and waits for all modules to properly stop

type Runner

type Runner interface {
	Start()
	Stop()
}

type RunnerFactory

type RunnerFactory interface {
	Create(config *common.Config, meta *common.MapStrPointer) (Runner, error)
}

Jump to

Keyboard shortcuts

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