From 19c102cf4bc6296c4ae14611d46a78f1c9285869 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Mon, 2 Apr 2018 13:55:10 -0700 Subject: [PATCH] Fix parsing of dos line endings in smart input (#3960) --- plugins/inputs/smart/smart.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/smart/smart.go b/plugins/inputs/smart/smart.go index bc130363b..46912d487 100644 --- a/plugins/inputs/smart/smart.go +++ b/plugins/inputs/smart/smart.go @@ -1,6 +1,7 @@ package smart import ( + "bufio" "fmt" "os/exec" "path" @@ -202,7 +203,10 @@ func gatherDisk(acc telegraf.Accumulator, usesudo, attributes bool, smartctl, no device_fields := make(map[string]interface{}) device_fields["exit_status"] = exitStatus - for _, line := range strings.Split(outStr, "\n") { + scanner := bufio.NewScanner(strings.NewReader(outStr)) + + for scanner.Scan() { + line := scanner.Text() model := modelInInfo.FindStringSubmatch(line) if len(model) > 1 {