Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log error message when invalid regex pattern is used #2454

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ be deprecated eventually.
- [#2390](https://github.com/influxdata/telegraf/issues/2390): Empty tag value causes error on InfluxDB output.
- [#2380](https://github.com/influxdata/telegraf/issues/2380): buffer_size field value is negative number from "internal" plugin.
- [#2414](https://github.com/influxdata/telegraf/issues/2414): Missing error handling in the MySQL plugin leads to segmentation violation.
- [#2178](https://github.com/influxdata/telegraf/issues/2178): logparser: regexp with lookahead.

## v1.2.1 [2017-02-01]

Expand Down
37 changes: 37 additions & 0 deletions plugins/inputs/logparser/grok/grok_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,43 @@ func Benchmark_ParseLine_CustomPattern(b *testing.B) {
benchM = m
}

// Test a very simple parse pattern.
func TestSimpleParse(t *testing.T) {
p := &Parser{
Patterns: []string{"%{TESTLOG}"},
CustomPatterns: `
TESTLOG %{NUMBER:num:int} %{WORD:client}
`,
}
assert.NoError(t, p.Compile())

m, err := p.ParseLine(`142 bot`)
assert.NoError(t, err)
require.NotNil(t, m)

assert.Equal(t,
map[string]interface{}{
"num": int64(142),
"client": "bot",
},
m.Fields())
}

// Verify that patterns with a regex lookahead fail at compile time.
func TestParsePatternsWithLookahead(t *testing.T) {
p := &Parser{
Patterns: []string{"%{MYLOG}"},
CustomPatterns: `
NOBOT ((?!bot|crawl).)*
MYLOG %{NUMBER:num:int} %{NOBOT:client}
`,
}
assert.NoError(t, p.Compile())

_, err := p.ParseLine(`1466004605359052000 bot`)
assert.Error(t, err)
}

func TestMeasurementName(t *testing.T) {
p := &Parser{
Measurement: "my_web_log",
Expand Down
2 changes: 2 additions & 0 deletions plugins/inputs/logparser/logparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ func (l *LogParserPlugin) parser() {
if m != nil {
l.acc.AddFields(m.Name(), m.Fields(), m.Tags(), m.Time())
}
} else {
log.Println("E! Error parsing log line: " + err.Error())
}
}
}
Expand Down