Exemplo n.º 1
0
func (nxc *NxConfig) Add(class string, name string, value interface{}) {
	switch class {
	case "extension":
		addition := &nxextension{name: name, properties: value.(map[string]string)}
		nxc.Extensions = append(nxc.Extensions, *addition)
	case "input":
		addition := &nxinput{name: name, properties: value.(map[string]string)}
		nxc.Inputs = append(nxc.Inputs, *addition)
	case "output":
		addition := &nxoutput{name: name, properties: value.(map[string]string)}
		nxc.Outputs = append(nxc.Outputs, *addition)
	case "route":
		addition := &nxroute{name: name, properties: value.(map[string]string)}
		nxc.Routes = append(nxc.Routes, *addition)
	case "match":
		addition := &nxmatch{name: name, properties: value.(map[string]string)}
		nxc.Matches = append(nxc.Matches, *addition)
	case "processor":
		addition := &nxprocessor{name: name, properties: value.(map[string]string)}
		nxc.Processors = append(nxc.Processors, *addition)
	case "snippet":
		snippet := &nxsnippet{name: name, value: value.(string)}
		if !nxc.Exists("snippet", snippet) {
			nxc.Snippets = append(nxc.Snippets, *snippet)
		} else {
			msg := fmt.Sprintf("Skipping snippet %s till it already exist in configuration.", name)
			nxc.SetStatus(backends.StatusUnknown, msg)
			log.Warnf("[%s] %s", nxc.Name(), msg)
		}
	//pre-canned configuration types
	case "output-gelf-udp":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
	case "output-gelf-tcp":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
	case "output-gelf-tcp-tls":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
	case "input-file":
		input_properties := value.(map[string]interface{})
		addition := &nxcanned{name: name, kind: class, properties: input_properties}
		nxc.Canned = append(nxc.Canned, *addition)

		multiline := nxc.isEnabled(input_properties["multiline"])
		var multilineStart string
		var multilineStop string
		if input_properties["multiline_start"] != nil {
			multilineStart = common.EncloseWith(input_properties["multiline_start"].(string), "/")
		}
		if input_properties["multiline_stop"] != nil {
			multilineStop = common.EncloseWith(input_properties["multiline_stop"].(string), "/")
		}
		if multiline {
			extension := &nxextension{name: name + "-multiline", properties: map[string]string{"Module": "xm_multiline"}}
			if len(multilineStart) > 0 {
				extension.properties["HeaderLine"] = multilineStart
			}
			if len(multilineStop) > 0 {
				extension.properties["EndLine"] = multilineStop
			}
			nxc.Extensions = append(nxc.Extensions, *extension)
		}
	case "input-windows-event-log":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
	case "input-udp-syslog":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
		extension := &nxextension{name: "syslog", properties: map[string]string{"Module": "xm_syslog"}}
		if !nxc.Exists("extension", extension) {
			nxc.Extensions = append(nxc.Extensions, *extension)
		}
	case "input-tcp-syslog":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
		extension := &nxextension{name: "syslog", properties: map[string]string{"Module": "xm_syslog"}}
		if !nxc.Exists("extension", extension) {
			nxc.Extensions = append(nxc.Extensions, *extension)
		}
	}
}
Exemplo n.º 2
0
func (nxc *NxConfig) Add(class string, name string, value interface{}) {
	switch class {
	case "extension":
		addition := &nxextension{name: name, properties: value.(map[string]string)}
		nxc.Extensions = append(nxc.Extensions, *addition)
	case "input":
		addition := &nxinput{name: name, properties: value.(map[string]string)}
		nxc.Inputs = append(nxc.Inputs, *addition)
	case "output":
		addition := &nxoutput{name: name, properties: value.(map[string]string)}
		nxc.Outputs = append(nxc.Outputs, *addition)
	case "route":
		addition := &nxroute{name: name, properties: value.(map[string]string)}
		nxc.Routes = append(nxc.Routes, *addition)
	case "match":
		addition := &nxmatch{name: name, properties: value.(map[string]string)}
		nxc.Matches = append(nxc.Matches, *addition)
	case "snippet":
		addition := &nxsnippet{name: name, value: value.(string)}
		nxc.Snippets = append(nxc.Snippets, *addition)
	//pre-canned configuration types
	case "output-gelf-udp":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
	case "output-gelf-tcp":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
	case "output-gelf-tcp-tls":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
	case "input-file":
		input_properties := value.(map[string]interface{})
		addition := &nxcanned{name: name, kind: class, properties: input_properties}
		nxc.Canned = append(nxc.Canned, *addition)

		multiline := nxc.isEnabled(input_properties["multiline"])
		var multilineStart string
		var multilineStop string
		if input_properties["multiline_start"] != nil {
			multilineStart = common.EncloseWith(input_properties["multiline_start"].(string), "/")
		}
		if input_properties["multiline_stop"] != nil {
			multilineStop = common.EncloseWith(input_properties["multiline_stop"].(string), "/")
		}
		if multiline {
			extension := &nxextension{name: name + "-multiline", properties: map[string]string{"Module": "xm_multiline"}}
			if len(multilineStart) > 0 {
				extension.properties["HeaderLine"] = multilineStart
			}
			if len(multilineStop) > 0 {
				extension.properties["EndLine"] = multilineStop
			}
			nxc.Extensions = append(nxc.Extensions, *extension)
		}
	case "input-windows-event-log":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
	case "input-udp-syslog":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
		if !nxc.Exists("extension", "syslog") {
			extension := &nxextension{name: "syslog", properties: map[string]string{"Module": "xm_syslog"}}
			nxc.Extensions = append(nxc.Extensions, *extension)
		}
	case "input-tcp-syslog":
		addition := &nxcanned{name: name, kind: class, properties: value.(map[string]interface{})}
		nxc.Canned = append(nxc.Canned, *addition)
		if !nxc.Exists("extension", "syslog") {
			extension := &nxextension{name: "syslog", properties: map[string]string{"Module": "xm_syslog"}}
			nxc.Extensions = append(nxc.Extensions, *extension)
		}
	}
}