Exemple #1
0
// Update decodes the collect-statse(8) parts of the config.
func Update(config_ *config.Config) error {
	return config_.UpdateHost(func(hostID string, elem *config.Element) error {
		hc := new(HostConfig)
		if err := xml.Unmarshal(elem.Raw, hc); err != nil {
			return nil
		}
		if err := hc.validate(); err != nil {
			return fmt.Errorf("host %s: statse: %v", hostID, err)
		}
		elem.Value = hc
		return nil
	})
}
Exemple #2
0
// aggregator returns the host responsible for aggregation of flows
// for the given forwarder host.
func aggregator(forwarder *config.Host, config *config.Config) (*config.Host, bool) {
	for _, host := range config.Cluster(forwarder.ClusterID) {
		hc, ok := hostConfig(host)
		if !ok {
			continue
		}
		if hc.Aggregator {
			return host, true
		}
	}
	return nil, false
}
Exemple #3
0
// updateHost extends the provided common config with host-level Process elements.
func updateHost(config_ *config.Config) error {
	global := make(config.Namespace)
	before := make(config.Namespace)
	for id := range config_.Hosts.NS {
		before[id] = true
	}
	// Decode <process> elements.
	err := config_.UpdateHost(func(hostID string, elem *config.Element) error {
		p := new(Process)
		if err := xml.Unmarshal(elem.Raw, p); err != nil {
			return nil
		}
		if err := p.validate(); err != nil {
			return fmt.Errorf("host %s: %v", hostID, err)
		}
		config_.Hosts.NS[p.ID] = true
		global[p.ID] = true
		elem.Value = p
		return nil
	})
	if err != nil {
		return err
	}
	// Ensure no naming ambiguity exists.
	count := make(map[string]int)
	for id := range global {
		count[id]++
	}
	for id := range before {
		count[id]++
	}
	for id := range count {
		if count[id] > 1 {
			return fmt.Errorf("identifier redeclared: %v", id)
		}
	}
	return nil
}
Exemple #4
0
// newView returns an initial view containing common settings.
func newView(key *Key, config *config.Config) (*View, error) {
	host, err := config.Host(key.Host)
	if err != nil {
		return nil, err
	}
	view := &View{
		Relay: make(map[string]*Relay),
	}
	// Load custom filter rules.
	err = config.Filter.Run(&view.Filter, key.Program, host.ID, host.ClusterID)
	if err != nil {
		return nil, &internalError{err}
	}
	// Add host tag if missing.
	view.Filter = append(view.Filter, &Rule{
		Match: []string{"", "host", "^$"},
		Set:   []string{"", "host", host.ID},
	})
	return view, nil
}