Add test case for smart serial number
This commit is contained in:
parent
fc1b1e8d20
commit
9867fe3279
|
@ -119,7 +119,6 @@ type Smart struct {
|
||||||
Devices []string
|
Devices []string
|
||||||
UseSudo bool
|
UseSudo bool
|
||||||
Timeout internal.Duration
|
Timeout internal.Duration
|
||||||
Log telegraf.Logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
|
@ -209,10 +208,7 @@ func (m *Smart) scan() ([]string, error) {
|
||||||
for _, line := range strings.Split(string(out), "\n") {
|
for _, line := range strings.Split(string(out), "\n") {
|
||||||
dev := strings.Split(line, " ")
|
dev := strings.Split(line, " ")
|
||||||
if len(dev) > 1 && !excludedDev(m.Excludes, strings.TrimSpace(dev[0])) {
|
if len(dev) > 1 && !excludedDev(m.Excludes, strings.TrimSpace(dev[0])) {
|
||||||
m.Log.Debugf("Adding device: %+#v", dev)
|
|
||||||
devices = append(devices, strings.TrimSpace(dev[0]))
|
devices = append(devices, strings.TrimSpace(dev[0]))
|
||||||
} else {
|
|
||||||
m.Log.Debugf("Skipping device: %+#v", dev)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return devices, nil
|
return devices, nil
|
||||||
|
|
|
@ -15,7 +15,6 @@ import (
|
||||||
|
|
||||||
func TestGatherAttributes(t *testing.T) {
|
func TestGatherAttributes(t *testing.T) {
|
||||||
s := NewSmart()
|
s := NewSmart()
|
||||||
s.Log = testutil.Logger{}
|
|
||||||
s.Path = "smartctl"
|
s.Path = "smartctl"
|
||||||
s.Attributes = true
|
s.Attributes = true
|
||||||
|
|
||||||
|
@ -331,7 +330,6 @@ func TestGatherAttributes(t *testing.T) {
|
||||||
|
|
||||||
func TestGatherNoAttributes(t *testing.T) {
|
func TestGatherNoAttributes(t *testing.T) {
|
||||||
s := NewSmart()
|
s := NewSmart()
|
||||||
s.Log = testutil.Logger{}
|
|
||||||
s.Path = "smartctl"
|
s.Path = "smartctl"
|
||||||
s.Attributes = false
|
s.Attributes = false
|
||||||
|
|
||||||
|
@ -440,8 +438,56 @@ func TestGatherHtSAS(t *testing.T) {
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
gatherDisk(acc, internal.Duration{Duration: time.Second * 30}, true, true, "", "", "", wg)
|
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) {
|
func TestGatherSSD(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue