MCPcopy
hub / github.com/henrygd/beszel / parseScan

Method parseScan

agent/smart.go:601–625  ·  view source on GitHub ↗

parseScan parses the output of smartctl --scan -j and returns the discovered devices.

(output []byte)

Source from the content-addressed store, hash-verified

599
600// parseScan parses the output of smartctl --scan -j and returns the discovered devices.
601func (sm *SmartManager) parseScan(output []byte) ([]*DeviceInfo, bool) {
602 scan := &scanOutput{}
603
604 if err := json.Unmarshal(output, scan); err != nil {
605 return nil, false
606 }
607
608 if len(scan.Devices) == 0 {
609 slog.Debug("no devices found in smartctl scan")
610 return nil, false
611 }
612
613 devices := make([]*DeviceInfo, 0, len(scan.Devices))
614 for _, device := range scan.Devices {
615 slog.Debug("smartctl scan", "name", device.Name, "type", device.Type, "protocol", device.Protocol)
616 devices = append(devices, &DeviceInfo{
617 Name: device.Name,
618 Type: device.Type,
619 InfoName: device.InfoName,
620 Protocol: device.Protocol,
621 })
622 }
623
624 return devices, true
625}
626
627// mergeDeviceLists combines scanned and configured SMART devices, preferring
628// configured SMART_DEVICES when both sources reference the same device.

Callers 2

TestParseScanFunction · 0.95
ScanDevicesMethod · 0.95

Calls

no outgoing calls

Tested by 1

TestParseScanFunction · 0.76