Skip to content

Commit

Permalink
Add test case for smart serial number
Browse files Browse the repository at this point in the history
(cherry picked from commit 9867fe3)
  • Loading branch information
danielnelson committed Sep 30, 2019
1 parent 3605d87 commit 43357d3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
4 changes: 0 additions & 4 deletions plugins/inputs/smart/smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package smart
import (
"bufio"
"fmt"
"log"
"os/exec"
"path"
"regexp"
Expand Down Expand Up @@ -209,10 +208,7 @@ func (m *Smart) scan() ([]string, error) {
for _, line := range strings.Split(string(out), "\n") {
dev := strings.Split(line, " ")
if len(dev) > 1 && !excludedDev(m.Excludes, strings.TrimSpace(dev[0])) {
log.Printf("D! [inputs.smart] adding device: %+#v", dev)
devices = append(devices, strings.TrimSpace(dev[0]))
} else {
log.Printf("D! [inputs.smart] skipping device: %+#v", dev)
}
}
return devices, nil
Expand Down
52 changes: 50 additions & 2 deletions plugins/inputs/smart/smart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,56 @@ func TestGatherHtSAS(t *testing.T) {

wg.Add(1)
gatherDisk(acc, internal.Duration{Duration: time.Second * 30}, true, true, "", "", "", wg)
assert.Equal(t, 5, acc.NFields(), "Wrong number of fields gathered")
assert.Equal(t, uint64(3), acc.NMetrics(), "Wrong number of metrics gathered")

expected := []telegraf.Metric{
testutil.MustMetric(
"smart_attribute",
map[string]string{
"device": ".",
"serial_no": "PDWAR9GE",
"enabled": "Enabled",
"id": "194",
"model": "HUC103030CSS600",
"name": "Temperature_Celsius",
},
map[string]interface{}{
"raw_value": 36,
},
time.Unix(0, 0),
),
testutil.MustMetric(
"smart_attribute",
map[string]string{
"device": ".",
"serial_no": "PDWAR9GE",
"enabled": "Enabled",
"id": "4",
"model": "HUC103030CSS600",
"name": "Start_Stop_Count",
},
map[string]interface{}{
"raw_value": 47,
},
time.Unix(0, 0),
),
testutil.MustMetric(
"smart_device",
map[string]string{
"device": ".",
"serial_no": "PDWAR9GE",
"enabled": "Enabled",
"model": "HUC103030CSS600",
},
map[string]interface{}{
"exit_status": 0,
"health_ok": true,
"temp_c": 36,
},
time.Unix(0, 0),
),
}

testutil.RequireMetricsEqual(t, expected, acc.GetTelegrafMetrics(), testutil.SortMetrics(), testutil.IgnoreTime())
}

func TestGatherSSD(t *testing.T) {
Expand Down

0 comments on commit 43357d3

Please sign in to comment.