Skip to content

Commit

Permalink
updates fw scrape to support idrac9 fw 3.xx and 4.xx
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimkk-moideen committed Jul 8, 2024
1 parent 7e1dcf0 commit a408408
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
2 changes: 2 additions & 0 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func BuildRequest(uri, host string) *retryablehttp.Request {

req, _ := retryablehttp.NewRequest(http.MethodGet, uri, nil)
req.SetBasicAuth(user, password)
// this header is required by iDRAC9 with FW ver. 3.xx and 4.xx
req.Header.Add("Accept", "application/json")

return req
}
Expand Down
23 changes: 12 additions & 11 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,20 +364,20 @@ func NewExporter(ctx context.Context, target, uri, profile, model string, exclud
zap.Any("trace_id", ctx.Value("traceID")))

// Call /redfish/v1/Managers/XXXX/UpdateService/FirmwareInventory/ for firmware inventory
firmwareInventoryEndpoints, err := getMemberUrls(exp.url+uri+"/UpdateService/FirmwareInventory/", target, retryClient)
firmwareInventoryEndpoints, err := getFirmwareEndpoints(exp.url+uri+"/UpdateService/FirmwareInventory/", target, retryClient)
if err != nil {
// Try the iLo 4 firmware inventory endpoint
// Use the collected sysEndpoints.systems to build url(s)
if len(sysEndpoints.systems) > 0 {
// call /redfish/v1/Systems/XXXX/FirmwareInventory/
for _, system := range sysEndpoints.systems {
firmwareInventoryEndpoints = append(firmwareInventoryEndpoints, system+"FirmwareInventory/")
}
// Ensure we have at least one firmware inventory endpoint
if len(firmwareInventoryEndpoints) == 0 {
log.Error("error when getting FirmwareInventory url", zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
url := system + "FirmwareInventory/"
tasks = append(tasks,
pool.NewTask(common.Fetch(exp.url+url, target, profile, retryClient), exp.url+url, handle(&exp, FIRMWAREINVENTORY)))
}
} else {
log.Error("error when getting Firmware endpoints", zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
}
}

Expand Down Expand Up @@ -426,12 +426,13 @@ func NewExporter(ctx context.Context, target, uri, profile, model string, exclud
}

// Firmware Inventory
for _, url := range firmwareInventoryEndpoints {
// this list can potentially be large and cause scrapes to take a long time please
for _, fwEp := range firmwareInventoryEndpoints.Members {
// this list can potentially be large and cause scrapes to take a long time
// see the '--collector.firmware.modules-exclude' config in the README for more information
if reg, ok := excludes["firmware"]; ok {
if !reg.(*regexp.Regexp).MatchString(url) {
tasks = append(tasks, pool.NewTask(common.Fetch(exp.url+url, target, profile, retryClient), exp.url+url, handle(&exp, FIRMWAREINVENTORY)))
if !reg.(*regexp.Regexp).MatchString(fwEp.URL) {
tasks = append(tasks,
pool.NewTask(common.Fetch(exp.url+fwEp.URL, target, profile, retryClient), exp.url+fwEp.URL, handle(&exp, FIRMWAREINVENTORY)))
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions exporter/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,48 @@ func getAllDriveEndpoints(ctx context.Context, fqdn, initialUrl, host string, cl
return driveEndpoints, nil
}

func getFirmwareEndpoints(url, host string, client *retryablehttp.Client) (oem.Collection, error) {
var fwEpUrls oem.Collection
var resp *http.Response
var err error
retryCount := 0
req := common.BuildRequest(url, host)

resp, err = common.DoRequest(client, req)
if err != nil {
return fwEpUrls, err
}
defer resp.Body.Close()
if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
if resp.StatusCode == http.StatusNotFound {
for retryCount < 1 && resp.StatusCode == http.StatusNotFound {
time.Sleep(client.RetryWaitMin)
resp, err = common.DoRequest(client, req)
retryCount = retryCount + 1
}
if err != nil {
return fwEpUrls, err
} else if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
return fwEpUrls, fmt.Errorf("HTTP status %d", resp.StatusCode)
}
} else {
return fwEpUrls, fmt.Errorf("HTTP status %d", resp.StatusCode)
}
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return fwEpUrls, fmt.Errorf("Error reading Response Body - " + err.Error())
}

err = json.Unmarshal(body, &fwEpUrls)
if err != nil {
return fwEpUrls, fmt.Errorf("Error Unmarshalling Memory Collection struct - " + err.Error())
}

return fwEpUrls, nil
}

func getProcessorEndpoints(url, host string, client *retryablehttp.Client) (oem.Collection, error) {
var processors oem.Collection
var resp *http.Response
Expand Down

0 comments on commit a408408

Please sign in to comment.