Skip to content

Commit

Permalink
log error message when invalid regex is used
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc authored and Eldad Zack committed Mar 27, 2017
1 parent 3a9b62a commit 09ef804
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ It is highly recommended that all users migrate to the new riemann output plugin

- [#2077](https://github.com/influxdata/telegraf/issues/2077): SQL Server Input - Arithmetic overflow error converting numeric to data type int.
- [#2262](https://github.com/influxdata/telegraf/issues/2262): Flush jitter can inhibit metric collection.
- [#2287](https://github.com/influxdata/telegraf/issues/2287): Kubernetes input: Handle null startTime for stopped pods
- [#1636](https://github.com/influxdata/telegraf/issues/1636): procstat - stop caching PIDs.
- [#2318](https://github.com/influxdata/telegraf/issues/2318): haproxy input - Add missing fields.
- [#2287](https://github.com/influxdata/telegraf/issues/2287): Kubernetes input: Handle null startTime for stopped pods.
- [#2356](https://github.com/influxdata/telegraf/issues/2356): cpu input panic when /proc/stat is empty.
- [#2341](https://github.com/influxdata/telegraf/issues/2341): telegraf swallowing panics in --test mode.
- [#2358](https://github.com/influxdata/telegraf/pull/2358): Create pidfile with 644 permissions & defer file deletion.
- [#2282](https://github.com/influxdata/telegraf/issues/2282): Reloading telegraf freezes prometheus output.
- [#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

0 comments on commit 09ef804

Please sign in to comment.