homelab/services/device-inventory/src/client/discovery.h
Dan V 69113c1ea7 feat: richer hardware discovery — CPU cache/voltage, memory type/bandwidth/part-no, GPU discovery
- CPU: max speed, bus MHz, L1/L2/L3 cache (from sysfs), voltage, socket type; /proc/cpuinfo fallback for non-root
- Memory sticks: DDR type, form factor, part number, rank, data width, theoretical bandwidth
- GPU: new part type discovered via lspci + /sys/class/drm + nvidia-smi; shows VRAM and display outputs
- discover-only tree updated to show all new fields

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-01 01:20:33 +02:00

42 lines
1.9 KiB
C++

#pragma once
#include <map>
#include <string>
#include <vector>
// ── DiscoveredPart ────────────────────────────────────────────────────────────
// One hardware component detected on the local machine, ready to send to the
// inventory server via CMD_UPSERT_PART.
struct DiscoveredPart {
std::string type_name; // PTYPE_* constant, e.g. "memory_stick"
std::map<std::string, std::string> kv; // field-key → value (list fields use LS)
};
// ── Discovery ─────────────────────────────────────────────────────────────────
// Queries OS tools (dmidecode, lsblk, ip, sysctl, …) to detect hardware.
// All methods are non-throwing: failures produce empty results + stderr warnings.
class Discovery {
public:
// Detect all supported part types.
std::vector<DiscoveredPart> discover_all();
// Detect parts of a single type (pass a PTYPE_* constant).
std::vector<DiscoveredPart> discover(const std::string& type_name);
private:
std::vector<DiscoveredPart> discover_memory_sticks();
std::vector<DiscoveredPart> discover_memory_slots();
std::vector<DiscoveredPart> discover_cpus();
std::vector<DiscoveredPart> discover_cpu_slots();
std::vector<DiscoveredPart> discover_disks();
std::vector<DiscoveredPart> discover_nics();
std::vector<DiscoveredPart> discover_gpus();
// Run a shell command, return trimmed stdout (≤64 KB). "" on failure.
static std::string run_cmd(const std::string& cmd);
// Parse dmidecode -t <type_num> output into a vector of field-map blocks.
static std::vector<std::map<std::string, std::string>>
parse_dmi(const std::string& type_num);
};