Skip lines that do not match in grok parser

This commit is contained in:
Daniel Nelson 2018-08-10 18:11:32 -07:00
parent 22b3bc4f8e
commit 035e6a6f78
No known key found for this signature in database
GPG Key ID: CAAD59C9444F6155
1 changed files with 10 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package grok
import (
"bufio"
"bytes"
"fmt"
"log"
"os"
@ -356,18 +357,20 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) {
}
func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
scanner := bufio.NewScanner(strings.NewReader(string(buf)))
var lines []string
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
var metrics []telegraf.Metric
for _, line := range lines {
metrics := make([]telegraf.Metric, 0)
scanner := bufio.NewScanner(bytes.NewReader(buf))
for scanner.Scan() {
line := scanner.Text()
m, err := p.ParseLine(line)
if err != nil {
return nil, err
}
if m == nil {
continue
}
metrics = append(metrics, m)
}