Skip to content

Commit

Permalink
add TCP/UDP syslog listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Sturm committed Apr 19, 2016
1 parent 269993f commit b950b95
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
57 changes: 57 additions & 0 deletions backends/nxlog/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
34 changes: 34 additions & 0 deletions backends/nxlog/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("<Input " + can.name + ">\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("</Input>\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("<Input " + can.name + ">\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("</Input>\n")
}
}
result.WriteString("\n")
return result.String()
}

func (nxc *NxConfig) gelfUdpOutputsToString() string {
var result bytes.Buffer
for _, can := range nxc.Canned {
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit b950b95

Please sign in to comment.