Trim null characters in Value data format (#2049)
* Trim null characters in Value data format Some producers (such as the paho embedded c mqtt client) add a null character "\x00" to the end of a message. The Value parser would fail on any message from such a producer. * Trim whitespace and null in all Value data formats * No unnecessary reassignments in Value data format parser * Update change log for Value data format fix
This commit is contained in:
committed by
Cameron Sparr
parent
94ce67cc67
commit
196509cc53
@@ -17,13 +17,12 @@ type ValueParser struct {
|
||||
}
|
||||
|
||||
func (v *ValueParser) Parse(buf []byte) ([]telegraf.Metric, error) {
|
||||
vStr := string(bytes.TrimSpace(bytes.Trim(buf, "\x00")))
|
||||
|
||||
// unless it's a string, separate out any fields in the buffer,
|
||||
// ignore anything but the last.
|
||||
var vStr string
|
||||
if v.DataType == "string" {
|
||||
vStr = strings.TrimSpace(string(buf))
|
||||
} else {
|
||||
values := bytes.Fields(buf)
|
||||
if v.DataType != "string" {
|
||||
values := strings.Fields(vStr)
|
||||
if len(values) < 1 {
|
||||
return []telegraf.Metric{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user