introduce basic fact collection

This commit is contained in:
2025-07-20 23:14:21 -04:00
parent 62336753c6
commit 3a47fa6706
58 changed files with 2801 additions and 107 deletions

38
client/facts/facts.go Normal file
View File

@@ -0,0 +1,38 @@
package facts
import (
"net/http"
"git.dubyatp.xyz/orphanage/client/httputil"
"github.com/zcalusic/sysinfo"
)
type FactsResponse struct {
APIVersion string `json:"apiVersion"`
CPUInfo sysinfo.CPU `json:"cpu"`
BoardInfo sysinfo.Board `json:"motherboard"`
DeviceInfo sysinfo.Product `json:"device"`
ChassisInfo sysinfo.Chassis `json:"chassis"`
MemoryInfo sysinfo.Memory `json:"memory"`
NetworkInfo []sysinfo.NetworkDevice `json:"network"`
StorageInfo []sysinfo.StorageDevice `json:"storage"`
}
func GetFacts(next http.Handler) http.Handler {
var si sysinfo.SysInfo
si.GetSysInfo()
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
resp := FactsResponse{
APIVersion: "v1",
CPUInfo: si.CPU,
BoardInfo: si.Board,
DeviceInfo: si.Product,
ChassisInfo: si.Chassis,
MemoryInfo: si.Memory,
NetworkInfo: si.Network,
StorageInfo: si.Storage,
}
httputil.WriteJSON(w, http.StatusOK, resp)
})
}