Change collect output to include EthernetInterfaces in Systems object

This commit is contained in:
David J. Allen 2023-10-12 14:03:04 -06:00
parent b76d5e61ff
commit 916050ad4d

View file

@ -185,24 +185,13 @@ func CollectInfo(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) er
data["Chassis"] = rm["Chassis"] data["Chassis"] = rm["Chassis"]
// ethernet interfaces // ethernet interfaces
interfaces, err := QueryEthernetInterfaces(client, q) // interfaces, err := QueryEthernetInterfaces(client, q)
if err != nil { // if err != nil {
l.Log.Errorf("could not query ethernet interfaces: %v", err) // l.Log.Errorf("could not query ethernet interfaces: %v", err)
continue // continue
} // }
json.Unmarshal(interfaces, &rm) // json.Unmarshal(interfaces, &rm)
data["Interfaces"] = rm["Interfaces"] // data["Interfaces"] = rm["Interfaces"]
// get MAC address of first interface (for now...)
if len(rm["Interfaces"]) > 0 {
var i map[string]interface{}
json.Unmarshal(rm["Interfaces"], &i)
data["MACAddr"] = i["MACAddress"]
data["IPAddress"] = i["IPAddress"]
if i["FQDN"] != "" {
data["FQDN"] = rm["FQDN"]
}
}
// storage // storage
// storage, err := QueryStorage(q) // storage, err := QueryStorage(q)
@ -214,16 +203,16 @@ func CollectInfo(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) er
// data["Storage"] = rm["Storage"] // data["Storage"] = rm["Storage"]
// get specific processor info // get specific processor info
procs, err := QueryProcessors(q) // procs, err := QueryProcessors(q)
if err != nil { // if err != nil {
l.Log.Errorf("could not query processors: %v", err) // l.Log.Errorf("could not query processors: %v", err)
} // }
var p map[string]interface{} // var p map[string]interface{}
json.Unmarshal(procs, &p) // json.Unmarshal(procs, &p)
data["Processors"] = rm["Processors"] // data["Processors"] = rm["Processors"]
// systems // systems
systems, err := QuerySystems(q) systems, err := QuerySystems(client, q)
if err != nil { if err != nil {
l.Log.Errorf("could not query systems: %v", err) l.Log.Errorf("could not query systems: %v", err)
} }
@ -453,7 +442,7 @@ func QueryBios(client *bmclib.Client, q *QueryParams) ([]byte, error) {
return b, err return b, err
} }
func QueryEthernetInterfaces(client *bmclib.Client, q *QueryParams) ([]byte, error) { func QueryEthernetInterfaces(client *bmclib.Client, q *QueryParams, systemID string) ([]byte, error) {
c, err := connectGofish(q) c, err := connectGofish(q)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not connect to bmc: %v", err) return nil, fmt.Errorf("could not connect to bmc: %v", err)
@ -477,15 +466,15 @@ func QueryEthernetInterfaces(client *bmclib.Client, q *QueryParams) ([]byte, err
return nil, fmt.Errorf("could not get ethernet interfaces: %v", err) return nil, fmt.Errorf("could not get ethernet interfaces: %v", err)
} }
data := map[string]any{"Interfaces": interfaces} data := map[string]any{"EthernetInterfaces": interfaces}
b, err := json.MarshalIndent(data, "", " ") b, err := json.MarshalIndent(data, "", " ")
if err != nil { if err != nil {
return nil, fmt.Errorf("could not marshal JSON: %v", err) return nil, fmt.Errorf("could not marshal JSON: %v", err)
} }
if q.Verbose { // if q.Verbose {
fmt.Printf("%v\n", string(b)) // fmt.Printf("%v\n", string(b))
} // }
return b, nil return b, nil
} }
@ -544,7 +533,7 @@ func QueryStorage(q *QueryParams) ([]byte, error) {
return b, nil return b, nil
} }
func QuerySystems(q *QueryParams) ([]byte, error) { func QuerySystems(client *bmclib.Client, q *QueryParams) ([]byte, error) {
c, err := connectGofish(q) c, err := connectGofish(q)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not connect to bmc (%v:%v): %v", q.Host, q.Port, err) return nil, fmt.Errorf("could not connect to bmc (%v:%v): %v", q.Host, q.Port, err)
@ -552,10 +541,25 @@ func QuerySystems(q *QueryParams) ([]byte, error) {
systems, err := c.Service.Systems() systems, err := c.Service.Systems()
if err != nil { if err != nil {
return nil, fmt.Errorf("could not query storage systems (%v:%v): %v", q.Host, q.Port, err) return nil, fmt.Errorf("could not query systems (%v:%v): %v", q.Host, q.Port, err)
} }
data := map[string]any{"Systems": systems } // query the system's ethernet interfaces
var temp []map[string]any
for _, system := range systems {
interfaces, err := QueryEthernetInterfaces(client, q, system.ID)
if err != nil {
continue
}
var i map[string]any
json.Unmarshal(interfaces, &i)
temp = append(temp, map[string]any{
"Data": system,
"EthernetInterfaces": i["EthernetInterfaces"],
})
}
data := map[string]any{"Systems": temp }
b, err := json.MarshalIndent(data, "", " ") b, err := json.MarshalIndent(data, "", " ")
if err != nil { if err != nil {
return nil, fmt.Errorf("could not marshal JSON: %v", err) return nil, fmt.Errorf("could not marshal JSON: %v", err)