Use device name instead of abs path for devices tag in smart input (#3550)

This commit is contained in:
Daniel Nelson 2017-12-08 13:22:41 -08:00 committed by GitHub
parent 899ad26373
commit 4452b0a03f
3 changed files with 24 additions and 21 deletions

View File

@ -129,7 +129,7 @@ the configuration to execute that.
Example output from an _Apple SSD_:
```
> smart_attribute,serial_no=S1K5NYCD964433,wwn=5002538655584d30,id=199,name=UDMA_CRC_Error_Count,flags=-O-RC-,fail=-,host=mbpro.local,device=/dev/rdisk0 threshold=0i,raw_value=0i,exit_status=0i,value=200i,worst=200i 1502536854000000000
> smart_attribute,device=/dev/rdisk0,serial_no=S1K5NYCD964433,wwn=5002538655584d30,id=240,name=Unknown_SSD_Attribute,flags=-O---K,fail=-,host=mbpro.local exit_status=0i,value=100i,worst=100i,threshold=0i,raw_value=0i 1502536854000000000
> smart_device,enabled=Enabled,host=mbpro.local,device=/dev/rdisk0,model=APPLE\ SSD\ SM0512F,serial_no=S1K5NYCD964433,wwn=5002538655584d30,capacity=500277790720 udma_crc_errors=0i,exit_status=0i,health_ok=true,read_error_rate=0i,temp_c=40i 1502536854000000000
> smart_attribute,serial_no=S1K5NYCD964433,wwn=5002538655584d30,id=199,name=UDMA_CRC_Error_Count,flags=-O-RC-,fail=-,host=mbpro.local,device=rdisk0 threshold=0i,raw_value=0i,exit_status=0i,value=200i,worst=200i 1502536854000000000
> smart_attribute,device=rdisk0,serial_no=S1K5NYCD964433,wwn=5002538655584d30,id=240,name=Unknown_SSD_Attribute,flags=-O---K,fail=-,host=mbpro.local exit_status=0i,value=100i,worst=100i,threshold=0i,raw_value=0i 1502536854000000000
> smart_device,enabled=Enabled,host=mbpro.local,device=rdisk0,model=APPLE\ SSD\ SM0512F,serial_no=S1K5NYCD964433,wwn=5002538655584d30,capacity=500277790720 udma_crc_errors=0i,exit_status=0i,health_ok=true,read_error_rate=0i,temp_c=40i 1502536854000000000
```

View File

@ -3,6 +3,7 @@ package smart
import (
"fmt"
"os/exec"
"path"
"regexp"
"strconv"
"strings"
@ -178,13 +179,13 @@ func exitStatus(err error) (int, error) {
return 0, err
}
func gatherDisk(acc telegraf.Accumulator, usesudo, attributes bool, path, nockeck, device string, wg *sync.WaitGroup) {
func gatherDisk(acc telegraf.Accumulator, usesudo, attributes bool, smartctl, nockeck, device string, wg *sync.WaitGroup) {
defer wg.Done()
// smartctl 5.41 & 5.42 have are broken regarding handling of --nocheck/-n
args := []string{"--info", "--health", "--attributes", "--tolerance=verypermissive", "-n", nockeck, "--format=brief"}
args = append(args, strings.Split(device, " ")...)
cmd := sudo(usesudo, path, args...)
cmd := sudo(usesudo, smartctl, args...)
out, e := internal.CombinedOutputTimeout(cmd, time.Second*5)
outStr := string(out)
@ -196,7 +197,8 @@ func gatherDisk(acc telegraf.Accumulator, usesudo, attributes bool, path, nockec
}
device_tags := map[string]string{}
device_tags["device"] = strings.Split(device, " ")[0]
device_node := strings.Split(device, " ")[0]
device_tags["device"] = path.Base(device_node)
device_fields := make(map[string]interface{})
device_fields["exit_status"] = exitStatus
@ -240,7 +242,8 @@ func gatherDisk(acc telegraf.Accumulator, usesudo, attributes bool, path, nockec
tags := map[string]string{}
fields := make(map[string]interface{})
tags["device"] = strings.Split(device, " ")[0]
device_node := strings.Split(device, " ")[0]
tags["device"] = path.Base(device_node)
if serial, ok := device_tags["serial_no"]; ok {
tags["serial_no"] = serial

View File

@ -89,7 +89,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "1",
@ -107,7 +107,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "5",
@ -125,7 +125,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "9",
@ -143,7 +143,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "12",
@ -161,7 +161,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "169",
@ -179,7 +179,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "173",
@ -197,7 +197,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "190",
@ -215,7 +215,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "192",
@ -233,7 +233,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "194",
@ -251,7 +251,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "197",
@ -269,7 +269,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "199",
@ -287,7 +287,7 @@ func TestGatherAttributes(t *testing.T) {
"exit_status": int(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
"id": "240",
@ -317,7 +317,7 @@ func TestGatherAttributes(t *testing.T) {
"udma_crc_errors": int64(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",
@ -363,7 +363,7 @@ func TestGatherNoAttributes(t *testing.T) {
"udma_crc_errors": int64(0),
},
map[string]string{
"device": "/dev/ada0",
"device": "ada0",
"model": "APPLE SSD SM256E",
"serial_no": "S0X5NZBC422720",
"wwn": "5002538043584d30",