Beispiel #1
0
func NewMultilineCodecFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.CodecFactory, error) {
	var err error

	result := &CodecMultilineFactory{}
	if err = config.PopulateConfig(result, config_path, unused); err != nil {
		return nil, err
	}

	if result.Pattern == "" {
		return nil, errors.New("Multiline codec pattern must be specified.")
	}

	result.matcher, err = regexp.Compile(result.Pattern)
	if err != nil {
		return nil, fmt.Errorf("Failed to compile multiline codec pattern, '%s'.", err)
	}

	if result.What == "" || result.What == "previous" {
		result.what = codecMultiline_What_Previous
	} else if result.What == "next" {
		result.what = codecMultiline_What_Next
	}

	if result.MaxMultilineBytes == 0 {
		result.MaxMultilineBytes = config.General.SpoolMaxBytes
	}

	// We conciously allow a line 4 bytes longer what we would normally have as the limit
	// This 4 bytes is the event header size. It's not worth considering though
	if result.MaxMultilineBytes > config.General.SpoolMaxBytes {
		return nil, fmt.Errorf("max multiline bytes cannot be greater than /general/spool max bytes")
	}

	return result, nil
}
Beispiel #2
0
func NewTcpTransportFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.TransportFactory, error) {
	var err error

	ret := &TransportTcpFactory{
		transport:   name,
		hostport_re: regexp.MustCompile(`^\[?([^]]+)\]?:([0-9]+)$`),
	}

	// Only allow SSL configurations if this is "tls"
	if name == "tls" {
		if err = config.PopulateConfig(ret, config_path, unused); err != nil {
			return nil, err
		}

		if len(ret.SSLCertificate) > 0 && len(ret.SSLKey) > 0 {
			cert, err := tls.LoadX509KeyPair(ret.SSLCertificate, ret.SSLKey)
			if err != nil {
				return nil, fmt.Errorf("Failed loading client ssl certificate: %s", err)
			}

			ret.tls_config.Certificates = []tls.Certificate{cert}
		}

		if len(ret.SSLCA) > 0 {
			ret.tls_config.RootCAs = x509.NewCertPool()
			pemdata, err := ioutil.ReadFile(ret.SSLCA)
			if err != nil {
				return nil, fmt.Errorf("Failure reading CA certificate: %s\n", err)
			}
			rest := pemdata
			var block *pem.Block
			var pemBlockNum = 1
			for {
				block, rest = pem.Decode(rest)
				if block != nil {
					if block.Type != "CERTIFICATE" {
						return nil, fmt.Errorf("Block %d does not contain a certificate: %s\n", pemBlockNum, ret.SSLCA)
					}
					cert, err := x509.ParseCertificate(block.Bytes)
					if err != nil {
						return nil, fmt.Errorf("Failed to parse CA certificate in block %d: %s\n", pemBlockNum, ret.SSLCA)
					}
					ret.tls_config.RootCAs.AddCert(cert)
					pemBlockNum += 1
				} else {
					break
				}
			}
		}
	} else {
		if err := config.ReportUnusedConfig(config_path, unused); err != nil {
			return nil, err
		}
	}

	return ret, nil
}
Beispiel #3
0
func NewZmqTransportFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.TransportFactory, error) {
	var err error

	ret := &TransportZmqFactory{
		transport:   name,
		hostport_re: regexp.MustCompile(`^\[?([^]]+)\]?:([0-9]+)$`),
	}

	if name == "zmq" {
		if err = config.PopulateConfig(ret, config_path, unused); err != nil {
			return nil, err
		}

		if err := ret.processConfig(config_path); err != nil {
			return nil, err
		}

		return ret, nil
	}

	// Don't allow curve settings
	if _, ok := unused["CurveServerkey"]; ok {
		goto CheckUnused
	}
	if _, ok := unused["CurvePublickey"]; ok {
		goto CheckUnused
	}
	if _, ok := unused["CurveSecretkey"]; ok {
		goto CheckUnused
	}

	if err = config.PopulateConfig(ret, config_path, unused); err != nil {
		return nil, err
	}

	if ret.PeerSendQueue == 0 {
		ret.PeerSendQueue = default_NetworkConfig_PeerSendQueue
	}

CheckUnused:
	if err := config.ReportUnusedConfig(config_path, unused); err != nil {
		return nil, err
	}

	return ret, nil
}
Beispiel #4
0
func NewFilterCodecFactory(config *core.Config, config_path string, unused map[string]interface{}, name string) (core.CodecFactory, error) {
	var err error

	result := &CodecFilterFactory{}
	if err = config.PopulateConfig(result, config_path, unused); err != nil {
		return nil, err
	}

	if len(result.Patterns) == 0 {
		return nil, errors.New("Filter codec pattern must be specified.")
	}

	result.matchers = make([]*regexp.Regexp, len(result.Patterns))
	for k, pattern := range result.Patterns {
		result.matchers[k], err = regexp.Compile(pattern)
		if err != nil {
			return nil, fmt.Errorf("Failed to compile filter codec pattern, '%s'.", err)
		}
	}

	return result, nil
}