diff --git a/plugins/inputs/logparser/grok/grok.go b/plugins/inputs/logparser/grok/grok.go index 66715ef37..47d4ecdf5 100644 --- a/plugins/inputs/logparser/grok/grok.go +++ b/plugins/inputs/logparser/grok/grok.go @@ -132,6 +132,7 @@ func (p *Parser) Compile() error { // "custom patterns" p.namedPatterns = make([]string, 0, len(p.Patterns)) for i, pattern := range p.Patterns { + pattern = strings.TrimSpace(pattern) if pattern == "" { continue } diff --git a/plugins/inputs/logparser/grok/grok_test.go b/plugins/inputs/logparser/grok/grok_test.go index e5e124b9c..a585140f6 100644 --- a/plugins/inputs/logparser/grok/grok_test.go +++ b/plugins/inputs/logparser/grok/grok_test.go @@ -958,3 +958,15 @@ func TestTimezoneLocalCompileFileAndParse(t *testing.T) { assert.Equal(t, map[string]string{}, metricB.Tags()) assert.Equal(t, time.Date(2016, time.June, 4, 12, 41, 45, 0, time.Local).UnixNano(), metricB.Time().UnixNano()) } + +func TestNewlineInPatterns(t *testing.T) { + p := &Parser{ + Patterns: []string{` + %{SYSLOGTIMESTAMP:timestamp} + `}, + } + require.NoError(t, p.Compile()) + m, err := p.ParseLine("Apr 10 05:11:57") + require.NoError(t, err) + require.NotNil(t, m) +}