Skip to content

Commit

Permalink
Keep leading whitespace for messages in syslog input (influxdata#4498)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and otherpirate committed Mar 15, 2019
1 parent 3c7cf07 commit 2bf190e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions plugins/inputs/syslog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Syslog messages should be formatted according to
## Only applies to stream sockets (e.g. TCP).
# max_connections = 1024

## Read timeout (default = 500ms).
## Read timeout is the maximum time allowed for reading a single message (default = 5s).
## 0 means unlimited.
# read_timeout = 500ms
# read_timeout = "5s"

## Whether to parse in best effort mode or not (default = false).
## By default best effort parsing is off.
Expand Down
32 changes: 32 additions & 0 deletions plugins/inputs/syslog/rfc5426_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,38 @@ func getTestCasesForRFC5426() []testCase5426 {
},
werr: true,
},
{
name: "trim message",
data: []byte("<1>1 - - - - - - \tA\n"),
wantBestEffort: &testutil.Metric{
Measurement: "syslog",
Fields: map[string]interface{}{
"version": uint16(1),
"message": "\tA",
"facility_code": 0,
"severity_code": 1,
},
Tags: map[string]string{
"severity": "alert",
"facility": "kern",
},
Time: defaultTime,
},
wantStrict: &testutil.Metric{
Measurement: "syslog",
Fields: map[string]interface{}{
"version": uint16(1),
"message": "\tA",
"facility_code": 0,
"severity_code": 1,
},
Tags: map[string]string{
"severity": "alert",
"facility": "kern",
},
Time: defaultTime,
},
},
}

return testCases
Expand Down
9 changes: 6 additions & 3 deletions plugins/inputs/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"sync"
"time"
"unicode"

"github.com/influxdata/go-syslog/rfc5424"
"github.com/influxdata/go-syslog/rfc5425"
Expand Down Expand Up @@ -71,9 +72,9 @@ var sampleConfig = `
## Only applies to stream sockets (e.g. TCP).
# max_connections = 1024
## Read timeout (default = 500ms).
## Read timeout is the maximum time allowed for reading a single message (default = 5s).
## 0 means unlimited.
# read_timeout = 500ms
# read_timeout = "5s"
## Whether to parse in best effort mode or not (default = false).
## By default best effort parsing is off.
Expand Down Expand Up @@ -365,7 +366,9 @@ func fields(msg rfc5424.SyslogMessage, s *Syslog) map[string]interface{} {
}

if msg.Message() != nil {
flds["message"] = strings.TrimSpace(*msg.Message())
flds["message"] = strings.TrimRightFunc(*msg.Message(), func(r rune) bool {
return unicode.IsSpace(r)
})
}

if msg.StructuredData() != nil {
Expand Down

0 comments on commit 2bf190e

Please sign in to comment.