Field bundles from ad-hoc service scripts (first sample: Giga G894-SD3 .rar with dmidecode/lscpu/lspci/nvme/lsblk output, no fixed layout). ADL-078: - linux-generic: recognizes utility output by content, merges records by stable key, low detect confidence (20-30) below all vendor parsers - pciids.LookupByDescription: resolve a textual lspci description back to vendor/device IDs and manufacturer/model - archive: accept .rar via the in-repo internal/rar5 reader (RAR 5 / RAR 7, single volume, solid; encrypted, multi-volume, SFX and RAR 4.x rejected), same per-file and total limits as tar/zip - UI: .rar in the upload accept list Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package linux_generic
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"git.mchus.pro/mchus/logpile/internal/models"
|
|
)
|
|
|
|
// lscpuInfo is the system-wide CPU summary printed by `lscpu`.
|
|
type lscpuInfo struct {
|
|
model string
|
|
sockets int
|
|
coresPerSocket int
|
|
threadsPerCore int
|
|
mhz int
|
|
maxMHz int
|
|
}
|
|
|
|
func parseLscpu(file sourceFile, inv *inventory) {
|
|
info := &inv.lscpu
|
|
for _, line := range strings.Split(file.content, "\n") {
|
|
key, value, ok := splitKeyValue(line)
|
|
if !ok || value == "" {
|
|
continue
|
|
}
|
|
switch key {
|
|
case "Model name":
|
|
setIfEmpty(&info.model, value)
|
|
case "Socket(s)":
|
|
setIntIfZero(&info.sockets, atoi(value))
|
|
case "Core(s) per socket":
|
|
setIntIfZero(&info.coresPerSocket, atoi(value))
|
|
case "Thread(s) per core":
|
|
setIntIfZero(&info.threadsPerCore, atoi(value))
|
|
case "CPU MHz":
|
|
setIntIfZero(&info.mhz, int(leadingNumber(value)))
|
|
case "CPU max MHz":
|
|
setIntIfZero(&info.maxMHz, int(leadingNumber(value)))
|
|
}
|
|
}
|
|
}
|
|
|
|
func setIntIfZero(dst *int, value int) {
|
|
if *dst == 0 {
|
|
*dst = value
|
|
}
|
|
}
|
|
|
|
// buildCPUs prefers per-socket dmidecode records and fills their gaps from
|
|
// lscpu; with lscpu alone it emits one record per reported socket.
|
|
func (inv *inventory) buildCPUs() []models.CPU {
|
|
info := inv.lscpu
|
|
threads := info.coresPerSocket * info.threadsPerCore
|
|
|
|
if len(inv.cpus) > 0 {
|
|
cpus := make([]models.CPU, len(inv.cpus))
|
|
copy(cpus, inv.cpus)
|
|
for i := range cpus {
|
|
setIfEmpty(&cpus[i].Model, info.model)
|
|
setIntIfZero(&cpus[i].Cores, info.coresPerSocket)
|
|
setIntIfZero(&cpus[i].Threads, threads)
|
|
setIntIfZero(&cpus[i].MaxFreqMHz, info.maxMHz)
|
|
}
|
|
return cpus
|
|
}
|
|
|
|
if info.model == "" {
|
|
return nil
|
|
}
|
|
sockets := info.sockets
|
|
if sockets <= 0 {
|
|
sockets = 1
|
|
}
|
|
cpus := make([]models.CPU, 0, sockets)
|
|
for socket := 0; socket < sockets; socket++ {
|
|
cpus = append(cpus, models.CPU{
|
|
Socket: socket,
|
|
Model: info.model,
|
|
Cores: info.coresPerSocket,
|
|
Threads: threads,
|
|
FrequencyMHz: info.mhz,
|
|
MaxFreqMHz: info.maxMHz,
|
|
})
|
|
}
|
|
return cpus
|
|
}
|