// 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 }) }
// 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 }