Skip to content

Commit

Permalink
Merge branch 'main' into add-vault-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
derrick-dacosta authored Mar 18, 2024
2 parents bda1c9e + 4c6e3cd commit 5100166
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 6 deletions.
57 changes: 54 additions & 3 deletions cisco/s3260m4/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,20 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
)
}

rcontrollers, err := getRaidEndpoint(fqdn.String()+uri+"/Systems/"+serial+"/Storage", target, retryClient)
if err != nil {
log.Error("error when getting storage controller endpoints from "+S3260M4, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
}

for _, rcontroller := range rcontrollers.Members {
tasks = append(tasks,
pool.NewTask(common.Fetch(fqdn.String()+rcontroller.URL, DRIVE, target, profile, retryClient)))
}

tasks = append(tasks,
pool.NewTask(common.Fetch(fqdn.String()+mgr+"/Processors/CPU1", PROCESSOR, target, profile, retryClient)),
pool.NewTask(common.Fetch(fqdn.String()+mgr+"/Processors/CPU2", PROCESSOR, target, profile, retryClient)),
pool.NewTask(common.Fetch(fqdn.String()+uri+"/Systems/"+serial+"/Storage/SBMezz1", DRIVE, target, profile, retryClient)),
pool.NewTask(common.Fetch(fqdn.String()+uri+"/Systems/"+serial+"/Storage/IOEMezz1", DRIVE, target, profile, retryClient)))
pool.NewTask(common.Fetch(fqdn.String()+mgr+"/Processors/CPU2", PROCESSOR, target, profile, retryClient)))

for _, dimm := range dimms.Members {
tasks = append(tasks,
Expand Down Expand Up @@ -743,3 +752,45 @@ func getDIMMEndpoints(url, host string, client *retryablehttp.Client) (Collectio

return dimms, nil
}

func getRaidEndpoint(url, host string, client *retryablehttp.Client) (Collection, error) {
var rcontrollers 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 rcontrollers, err
}
defer resp.Body.Close()
if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
if resp.StatusCode == http.StatusNotFound {
for retryCount < 3 && resp.StatusCode == http.StatusNotFound {
time.Sleep(client.RetryWaitMin)
resp, err = common.DoRequest(client, req)
retryCount = retryCount + 1
}
if err != nil {
return rcontrollers, err
} else if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
return rcontrollers, fmt.Errorf("HTTP status %d", resp.StatusCode)
}
} else {
return rcontrollers, fmt.Errorf("HTTP status %d", resp.StatusCode)
}
}

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

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

return rcontrollers, nil
}
58 changes: 55 additions & 3 deletions cisco/s3260m5/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,21 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
}
}

// Storage controller endpoints array
rcontrollers, err := getRaidEndpoint(fqdn.String()+uri+"/Systems/"+serial+"/Storage", target, retryClient)
if err != nil {
log.Error("error when getting storage controller endpoints from "+S3260M5, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
}

for _, rcontroller := range rcontrollers.Members {
tasks = append(tasks,
pool.NewTask(common.Fetch(fqdn.String()+rcontroller.URL, DRIVE, target, profile, retryClient)))
}

tasks = append(tasks,
pool.NewTask(common.Fetch(fqdn.String()+mgr+"/Processors/CPU1", PROCESSOR, target, profile, retryClient)),
pool.NewTask(common.Fetch(fqdn.String()+mgr+"/Processors/CPU2", PROCESSOR, target, profile, retryClient)),
pool.NewTask(common.Fetch(fqdn.String()+uri+"/Systems/"+serial+"/Storage/SBMezz1", DRIVE, target, profile, retryClient)),
pool.NewTask(common.Fetch(fqdn.String()+uri+"/Systems/"+serial+"/Storage/SBMezz2", DRIVE, target, profile, retryClient)))
pool.NewTask(common.Fetch(fqdn.String()+mgr+"/Processors/CPU2", PROCESSOR, target, profile, retryClient)))

for _, dimm := range dimms.Members {
tasks = append(tasks,
Expand Down Expand Up @@ -740,3 +750,45 @@ func getDIMMEndpoints(url, host string, client *retryablehttp.Client) (Collectio

return dimms, nil
}

func getRaidEndpoint(url, host string, client *retryablehttp.Client) (Collection, error) {
var rcontrollers 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 rcontrollers, err
}
defer resp.Body.Close()
if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
if resp.StatusCode == http.StatusNotFound {
for retryCount < 3 && resp.StatusCode == http.StatusNotFound {
time.Sleep(client.RetryWaitMin)
resp, err = common.DoRequest(client, req)
retryCount = retryCount + 1
}
if err != nil {
return rcontrollers, err
} else if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
return rcontrollers, fmt.Errorf("HTTP status %d", resp.StatusCode)
}
} else {
return rcontrollers, fmt.Errorf("HTTP status %d", resp.StatusCode)
}
}

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

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

return rcontrollers, nil
}
4 changes: 4 additions & 0 deletions hpe/dl360/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ func (e *Exporter) exportPowerMetrics(body []byte) error {
if ps.Status.State == "Enabled" {
if ps.MemberID != "" {
(*dlPower)["supplyOutput"].WithLabelValues(ps.MemberID, ps.SparePartNumber).Set(float64(ps.LastPowerOutputWatts))
} else if string(ps.Oem.Hp.BayNumber) == "null" {

Check failure on line 487 in hpe/dl360/exporter.go

View workflow job for this annotation

GitHub Actions / test

conversion from int to string yields a string of one rune, not a string of digits (did you mean fmt.Sprint(x)?)
(*dlPower)["supplyOutput"].WithLabelValues(strconv.Itoa(ps.Oem.Hpe.BayNumber), ps.SparePartNumber).Set(float64(ps.LastPowerOutputWatts))
} else {
(*dlPower)["supplyOutput"].WithLabelValues(strconv.Itoa(ps.Oem.Hp.BayNumber), ps.SparePartNumber).Set(float64(ps.LastPowerOutputWatts))
}
Expand All @@ -494,6 +496,8 @@ func (e *Exporter) exportPowerMetrics(body []byte) error {
}
if ps.MemberID != "" {
(*dlPower)["supplyStatus"].WithLabelValues(ps.MemberID, ps.SparePartNumber).Set(state)
} else if string(ps.Oem.Hp.BayNumber) == "null" {

Check failure on line 499 in hpe/dl360/exporter.go

View workflow job for this annotation

GitHub Actions / test

conversion from int to string yields a string of one rune, not a string of digits (did you mean fmt.Sprint(x)?)
(*dlPower)["supplyStatus"].WithLabelValues(strconv.Itoa(ps.Oem.Hpe.BayNumber), ps.SparePartNumber).Set(state)
} else {
(*dlPower)["supplyStatus"].WithLabelValues(strconv.Itoa(ps.Oem.Hp.BayNumber), ps.SparePartNumber).Set(state)
}
Expand Down

0 comments on commit 5100166

Please sign in to comment.