Added more output messages for handling errors

This commit is contained in:
David J. Allen 2024-05-10 17:00:21 -06:00
parent f4540ea4ce
commit 0f74e1e7f7
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC

View file

@ -100,7 +100,7 @@ func CollectAll(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) err
gofishClient, err := connectGofish(q) gofishClient, err := connectGofish(q)
if err != nil { if err != nil {
l.Log.Errorf("failed to connect to bmc (%v:%v): %v", q.Host, q.Port, err) l.Log.Errorf("failed to connect to BMC (%v:%v): %v", q.Host, q.Port, err)
} }
// data to be sent to smd // data to be sent to smd
@ -145,9 +145,15 @@ func CollectAll(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) err
// add other fields from systems // add other fields from systems
if len(rm["Systems"]) > 0 { if len(rm["Systems"]) > 0 {
var s map[string][]interface{} var s map[string][]interface{}
json.Unmarshal(rm["Systems"], &s) err = json.Unmarshal(rm["Systems"], &s)
if err != nil {
l.Log.Errorf("failed to unmarshal systems JSON: %v", err)
}
data["Name"] = s["Name"] data["Name"] = s["Name"]
} }
} else {
l.Log.Errorf("invalid client (client is nil)")
continue
} }
headers := make(map[string]string) headers := make(map[string]string)
@ -349,17 +355,29 @@ func CollectEthernetInterfaces(c *gofish.APIClient, q *QueryParams, systemID str
return nil, fmt.Errorf("failed to query storage systems (%v:%v): %v", q.Host, q.Port, err) return nil, fmt.Errorf("failed to query storage systems (%v:%v): %v", q.Host, q.Port, err)
} }
var interfaces []*redfish.EthernetInterface var (
interfaces []*redfish.EthernetInterface
errList []error
)
// get all of the ethernet interfaces in our systems
for _, system := range systems { for _, system := range systems {
i, err := redfish.ListReferencedEthernetInterfaces(c, "/redfish/v1/Systems/"+system.ID+"/EthernetInterfaces/") i, err := redfish.ListReferencedEthernetInterfaces(c, "/redfish/v1/Systems/"+system.ID+"/EthernetInterfaces/")
if err != nil { if err != nil {
errList = append(errList, err)
continue continue
} }
interfaces = append(interfaces, i...) interfaces = append(interfaces, i...)
} }
if len(interfaces) <= 0 { // format the error message for printing
return nil, fmt.Errorf("failed to get ethernet interfaces: %v", err) for i, e := range errList {
err = fmt.Errorf("\t[%d] %v\n", i, e)
}
// print any report errors
if len(errList) > 0 {
return nil, fmt.Errorf("failed to get ethernet interfaces with %d errors: \n%v", len(errList), err)
} }
data := map[string]any{"EthernetInterfaces": interfaces} data := map[string]any{"EthernetInterfaces": interfaces}
@ -425,7 +443,10 @@ func CollectSystems(c *gofish.APIClient, q *QueryParams) ([]byte, error) {
continue continue
} }
var i map[string]any var i map[string]any
json.Unmarshal(interfaces, &i) err = json.Unmarshal(interfaces, &i)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal interface: %v", err)
}
temp = append(temp, map[string]any{ temp = append(temp, map[string]any{
"Data": system, "Data": system,
"EthernetInterfaces": i["EthernetInterfaces"], "EthernetInterfaces": i["EthernetInterfaces"],