39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
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)
|
|
})
|
|
}
|