introduce basic fact collection
This commit is contained in:
38
client/facts/facts.go
Normal file
38
client/facts/facts.go
Normal 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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user