parent
fb463bcc17
commit
049daf7892
|
|
@ -32,6 +32,8 @@ type Config struct {
|
|||
Timezone string `toml:"csv_timezone"`
|
||||
TrimSpace bool `toml:"csv_trim_space"`
|
||||
|
||||
gotColumnNames bool
|
||||
|
||||
TimeFunc func() time.Time
|
||||
DefaultTags map[string]string
|
||||
}
|
||||
|
|
@ -64,6 +66,8 @@ func NewParser(c *Config) (*Parser, error) {
|
|||
return nil, fmt.Errorf("csv_column_names field count doesn't match with csv_column_types")
|
||||
}
|
||||
|
||||
c.gotColumnNames = len(c.ColumnNames) > 0
|
||||
|
||||
if c.TimeFunc == nil {
|
||||
c.TimeFunc = time.Now
|
||||
}
|
||||
|
|
@ -102,10 +106,13 @@ func (p *Parser) Parse(buf []byte) ([]telegraf.Metric, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
// if there is a header and nothing in DataColumns
|
||||
// if there is a header and we did not get DataColumns
|
||||
// set DataColumns to names extracted from the header
|
||||
headerNames := make([]string, 0)
|
||||
if len(p.ColumnNames) == 0 {
|
||||
// we always reread the header to avoid side effects
|
||||
// in cases where multiple files with different
|
||||
// headers are read
|
||||
if !p.gotColumnNames {
|
||||
headerNames := make([]string, 0)
|
||||
for i := 0; i < p.HeaderRowCount; i++ {
|
||||
header, err := csvReader.Read()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue