diff --git a/backends/nxlog/configuration.go b/backends/nxlog/configuration.go index 1912d22..2d6da62 100644 --- a/backends/nxlog/configuration.go +++ b/backends/nxlog/configuration.go @@ -151,7 +151,64 @@ func (nxc *NxConfig) Add(class string, name string, value interface{}) { 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) + } + } +} + +func (nxc *NxConfig) Exists(class string, name string) bool { + result := false + switch class { + case "extension": + for _, entity := range nxc.Extensions { + if entity.name == name { + result = true + } + } + case "input": + for _, entity := range nxc.Inputs { + if entity.name == name { + result = true + } + } + case "output": + for _, entity := range nxc.Outputs { + if entity.name == name { + result = true + } + } + case "route": + for _, entity := range nxc.Routes { + if entity.name == name { + result = true + } + } + case "match": + for _, entity := range nxc.Matches { + if entity.name == name { + result = true + } + } + case "snippet": + for _, entity := range nxc.Snippets { + if entity.name == name { + result = true + } + } } + return result } func (nxc *NxConfig) Update(a *NxConfig) { diff --git a/backends/nxlog/render.go b/backends/nxlog/render.go index d654060..2e116f3 100644 --- a/backends/nxlog/render.go +++ b/backends/nxlog/render.go @@ -169,6 +169,38 @@ func (nxc *NxConfig) windowsEventLogInputsToString() string { return result.String() } +func (nxc *NxConfig) udpSyslogInputsToString() string { + var result bytes.Buffer + for _, can := range nxc.Canned { + if can.kind == "input-udp-syslog" { + result.WriteString("\n") + result.WriteString(" Module im_udp\n") + result.WriteString(" Host " + nxc.propertyString(can.properties["host"], 0) + "\n") + result.WriteString(" Port " + nxc.propertyString(can.properties["port"], 0) + "\n") + result.WriteString(" Exec parse_syslog_bsd();\n") + result.WriteString("\n") + } + } + result.WriteString("\n") + return result.String() +} + +func (nxc *NxConfig) tcpSyslogInputsToString() string { + var result bytes.Buffer + for _, can := range nxc.Canned { + if can.kind == "input-tcp-syslog" { + result.WriteString("\n") + result.WriteString(" Module im_tcp\n") + result.WriteString(" Host " + nxc.propertyString(can.properties["host"], 0) + "\n") + result.WriteString(" Port " + nxc.propertyString(can.properties["port"], 0) + "\n") + result.WriteString(" Exec parse_syslog_bsd();\n") + result.WriteString("\n") + } + } + result.WriteString("\n") + return result.String() +} + func (nxc *NxConfig) gelfUdpOutputsToString() string { var result bytes.Buffer for _, can := range nxc.Canned { @@ -198,6 +230,8 @@ func (nxc *NxConfig) Render() bytes.Buffer { // pre-canned types result.WriteString(nxc.fileInputsToString()) result.WriteString(nxc.windowsEventLogInputsToString()) + result.WriteString(nxc.udpSyslogInputsToString()) + result.WriteString(nxc.tcpSyslogInputsToString()) result.WriteString(nxc.gelfUdpOutputsToString()) // result.WriteString(nxc.routesToString())