예제 #1
0
func (c *Config) validateFilter() error {
	if c.Filter == nil {
		c.Filter = []filter.Rule{{Block: true}}
	}
	_, err := filter.New(c.Filter...)
	if err != nil {
		return fmt.Errorf("forwarder: %v", err)
	}
	return nil
}
예제 #2
0
func Filter(rules []filter.Rule) ([]filter.Rule, error) {
	if rules == nil {
		rules = []filter.Rule{{Block: true}}
		return rules, nil
	}
	if n := len(rules); n > maxRules {
		err := fmt.Errorf("too many filter rules defined (%d>%d)", n, maxRules)
		return nil, err
	}
	_, err := filter.New(rules...)
	if err != nil {
		err := fmt.Errorf("error creating filter: %v", err)
		return nil, err
	}
	return rules, nil
}
예제 #3
0
// ListenAndServe starts Statse listener that forwards incoming Statse messages
// to the aggregator.
func ListenAndServe(config *Config) error {
	if err := config.Validate(); err != nil {
		return err
	}
	filter, err := filter.New(config.Filter...)
	if err != nil {
		return err
	}
	l, err := statse.Listen(statse.ListenAddr)
	if err != nil {
		return err
	}
	defaultServer = &server{
		dec:        statse.NewDecoder(l),
		filter:     filter,
		aggregator: aggregator.NewClient(config.AggregatorHost),
	}
	return defaultServer.loop()
}