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

Method parseConfiguredDevices

agent/smart.go:228–264  ·  view source on GitHub ↗
(config string)

Source from the content-addressed store, hash-verified

226}
227
228func (sm *SmartManager) parseConfiguredDevices(config string) ([]*DeviceInfo, error) {
229 splitChar, _ := utils.GetEnv("SMART_DEVICES_SEPARATOR")
230 if splitChar == "" {
231 splitChar = ","
232 }
233 entries := strings.Split(config, splitChar)
234 devices := make([]*DeviceInfo, 0, len(entries))
235 for _, entry := range entries {
236 entry = strings.TrimSpace(entry)
237 if entry == "" {
238 continue
239 }
240
241 parts := strings.SplitN(entry, ":", 2)
242
243 name := strings.TrimSpace(parts[0])
244 if name == "" {
245 return nil, fmt.Errorf("invalid SMART_DEVICES entry %q", entry)
246 }
247
248 devType := ""
249 if len(parts) == 2 {
250 devType = strings.ToLower(strings.TrimSpace(parts[1]))
251 }
252
253 devices = append(devices, &DeviceInfo{
254 Name: name,
255 Type: devType,
256 })
257 }
258
259 if len(devices) == 0 {
260 return nil, errNoValidSmartData
261 }
262
263 return devices, nil
264}
265
266func (sm *SmartManager) refreshExcludedDevices() {
267 rawValue, _ := utils.GetEnv("EXCLUDE_SMART")

Callers 1

ScanDevicesMethod · 0.95

Calls 1

GetEnvFunction · 0.92

Tested by

no test coverage detected