Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update fetching response on power and raid metrics #40

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" {
(*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" {
(*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
6 changes: 5 additions & 1 deletion vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ func (v *Vault) GetKVSecret(ctx context.Context, props *SecretProperties, secret
kvSecret, err = v.client.KVv1(props.MountPath).Get(ctx, fmt.Sprintf("%s/%s", props.Path, secret))
}
} else {
kvSecret, err = v.client.KVv2(props.MountPath).Get(ctx, fmt.Sprintf("%s/%s", props.Path, secret))
if props.SecretName != "" {
kvSecret, err = v.client.KVv2(props.MountPath).Get(ctx, fmt.Sprintf("%s/%s", props.Path, props.SecretName))
} else {
kvSecret, err = v.client.KVv2(props.MountPath).Get(ctx, fmt.Sprintf("%s/%s", props.Path, secret))
}
}

if err != nil {
Expand Down
Loading