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

Fix chassis serialnumber #51

Merged
merged 2 commits into from
Apr 2, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ log is based on the [Keep a CHANGELOG](http://keepachangelog.com/) project.

- Cisco UCS C220 - add additional edge cases when collecting memory metrics [#2](https://github.com/Comcast/fishymetrics/issues/2)
- null pointer derefence errors when using incorrect credentials [#36](https://github.com/Comcast/fishymetrics/issues/36)
- incorrect /Memory path for HPE hosts [#49](https://github.com/Comcast/fishymetrics/issues/49)

## Updated

Expand All @@ -28,6 +29,7 @@ log is based on the [Keep a CHANGELOG](http://keepachangelog.com/) project.
- HP DL360 module to support responses from iLO4 [#34](https://github.com/Comcast/fishymetrics/issues/34)
- HP DL360 & XL420 to include processor, iloselftest and smart storage battery metrics [#43](https://github.com/Comcast/fishymetrics/issues/43)
- consolidate hardware component structs to a single package [#45](https://github.com/Comcast/fishymetrics/issues/45)
- get chassis serial number from JSON response instead of url path [#50](https://github.com/Comcast/fishymetrics/issues/50)

## [0.7.1]

Expand Down
27 changes: 12 additions & 15 deletions hpe/dl20/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"net"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -165,15 +164,13 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
return nil, err
}

exp.chassisSerialNumber = path.Base(sysEndpoint)

// chassis BIOS version
biosVer, err := getBIOSVersion(fqdn.String()+sysEndpoint, target, retryClient)
resp, err := getSystemsMetadata(fqdn.String()+sysEndpoint, target, retryClient)
if err != nil {
log.Error("error when getting BIOS version from "+DL20, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
}
exp.biosVersion = biosVer
exp.biosVersion = resp.BiosVersion
exp.chassisSerialNumber = resp.SerialNumber

// vars for drive parsing
var (
Expand Down Expand Up @@ -300,7 +297,7 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
}

// DIMM endpoints array
dimms, err := getDIMMEndpoints(fqdn.String()+sysEndpoint+"/Memory", target, retryClient)
dimms, err := getDIMMEndpoints(fqdn.String()+sysEndpoint+"Memory/", target, retryClient)
if err != nil {
log.Error("error when getting DIMM endpoints from "+DL20, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
Expand Down Expand Up @@ -801,30 +798,30 @@ func getChassisEndpoint(url, host string, client *retryablehttp.Client) (string,
return urlFinal, nil
}

func getBIOSVersion(url, host string, client *retryablehttp.Client) (string, error) {
var biosVer oem.ServerManager
func getSystemsMetadata(url, host string, client *retryablehttp.Client) (oem.ServerManager, error) {
var sm oem.ServerManager
req := common.BuildRequest(url, host)

resp, err := client.Do(req)
if err != nil {
return "", err
return sm, err
}
defer resp.Body.Close()
if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
return "", fmt.Errorf("HTTP status %d", resp.StatusCode)
return sm, fmt.Errorf("HTTP status %d", resp.StatusCode)
}

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

err = json.Unmarshal(body, &biosVer)
err = json.Unmarshal(body, &sm)
if err != nil {
return "", fmt.Errorf("Error Unmarshalling DL20 ServerManager struct - " + err.Error())
return sm, fmt.Errorf("Error Unmarshalling DL20 ServerManager struct - " + err.Error())
}

return biosVer.BiosVersion, nil
return sm, nil
}

func getDIMMEndpoints(url, host string, client *retryablehttp.Client) (oem.Collection, error) {
Expand Down
27 changes: 12 additions & 15 deletions hpe/dl360/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"net"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -171,15 +170,13 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
return nil, err
}

exp.chassisSerialNumber = path.Base(sysEndpoint)

// chassis BIOS version
biosVer, err := getBIOSVersion(fqdn.String()+sysEndpoint, target, retryClient)
resp, err := getSystemsMetadata(fqdn.String()+sysEndpoint, target, retryClient)
if err != nil {
log.Error("error when getting BIOS version from "+DL360, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
}
exp.biosVersion = biosVer
exp.biosVersion = resp.BiosVersion
exp.chassisSerialNumber = resp.SerialNumber

// vars for drive parsing
var (
Expand Down Expand Up @@ -306,7 +303,7 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
}

// DIMM endpoints array
dimms, err := getDIMMEndpoints(fqdn.String()+sysEndpoint+"/Memory", target, retryClient)
dimms, err := getDIMMEndpoints(fqdn.String()+sysEndpoint+"Memory/", target, retryClient)
if err != nil {
log.Error("error when getting DIMM endpoints from "+DL360, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
Expand Down Expand Up @@ -934,30 +931,30 @@ func getChassisEndpoint(url, host string, client *retryablehttp.Client) (string,
return urlFinal, nil
}

func getBIOSVersion(url, host string, client *retryablehttp.Client) (string, error) {
var biosVer oem.ServerManager
func getSystemsMetadata(url, host string, client *retryablehttp.Client) (oem.ServerManager, error) {
var sm oem.ServerManager
req := common.BuildRequest(url, host)

resp, err := client.Do(req)
if err != nil {
return "", err
return sm, err
}
defer resp.Body.Close()
if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
return "", fmt.Errorf("HTTP status %d", resp.StatusCode)
return sm, fmt.Errorf("HTTP status %d", resp.StatusCode)
}

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

err = json.Unmarshal(body, &biosVer)
err = json.Unmarshal(body, &sm)
if err != nil {
return "", fmt.Errorf("Error Unmarshalling DL360 ServerManager struct - " + err.Error())
return sm, fmt.Errorf("Error Unmarshalling DL360 ServerManager struct - " + err.Error())
}

return biosVer.BiosVersion, nil
return sm, nil
}

func getDIMMEndpoints(url, host string, client *retryablehttp.Client) (oem.Collection, error) {
Expand Down
27 changes: 12 additions & 15 deletions hpe/dl380/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"net"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -165,15 +164,13 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
return nil, err
}

exp.chassisSerialNumber = path.Base(sysEndpoint)

// chassis BIOS version
biosVer, err := getBIOSVersion(fqdn.String()+sysEndpoint, target, retryClient)
resp, err := getSystemsMetadata(fqdn.String()+sysEndpoint, target, retryClient)
if err != nil {
log.Error("error when getting BIOS version from "+DL380, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
}
exp.biosVersion = biosVer
exp.biosVersion = resp.BiosVersion
exp.chassisSerialNumber = resp.SerialNumber

// vars for drive parsing
var (
Expand Down Expand Up @@ -298,7 +295,7 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
}

// DIMM endpoints array
dimms, err := getDIMMEndpoints(fqdn.String()+sysEndpoint+"/Memory", target, retryClient)
dimms, err := getDIMMEndpoints(fqdn.String()+sysEndpoint+"Memory/", target, retryClient)
if err != nil {
log.Error("error when getting DIMM endpoints from "+DL380, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
Expand Down Expand Up @@ -796,30 +793,30 @@ func getChassisEndpoint(url, host string, client *retryablehttp.Client) (string,
return urlFinal, nil
}

func getBIOSVersion(url, host string, client *retryablehttp.Client) (string, error) {
var biosVer oem.ServerManager
func getSystemsMetadata(url, host string, client *retryablehttp.Client) (oem.ServerManager, error) {
var sm oem.ServerManager
req := common.BuildRequest(url, host)

resp, err := client.Do(req)
if err != nil {
return "", err
return sm, err
}
defer resp.Body.Close()
if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
return "", fmt.Errorf("HTTP status %d", resp.StatusCode)
return sm, fmt.Errorf("HTTP status %d", resp.StatusCode)
}

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

err = json.Unmarshal(body, &biosVer)
err = json.Unmarshal(body, &sm)
if err != nil {
return "", fmt.Errorf("Error Unmarshalling DL380 ServerManager struct - " + err.Error())
return sm, fmt.Errorf("Error Unmarshalling DL380 ServerManager struct - " + err.Error())
}

return biosVer.BiosVersion, nil
return sm, nil
}

func getDIMMEndpoints(url, host string, client *retryablehttp.Client) (oem.Collection, error) {
Expand Down
27 changes: 12 additions & 15 deletions hpe/dl560/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"net"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -165,15 +164,13 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
return nil, err
}

exp.chassisSerialNumber = path.Base(sysEndpoint)

// chassis BIOS version
biosVer, err := getBIOSVersion(fqdn.String()+sysEndpoint, target, retryClient)
resp, err := getSystemsMetadata(fqdn.String()+sysEndpoint, target, retryClient)
if err != nil {
log.Error("error when getting BIOS version from "+DL560, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
}
exp.biosVersion = biosVer
exp.biosVersion = resp.BiosVersion
exp.chassisSerialNumber = resp.SerialNumber

// vars for drive parsing
var (
Expand Down Expand Up @@ -291,7 +288,7 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
}

// DIMM endpoints array
dimms, err := getDIMMEndpoints(fqdn.String()+sysEndpoint+"/Memory", target, retryClient)
dimms, err := getDIMMEndpoints(fqdn.String()+sysEndpoint+"Memory/", target, retryClient)
if err != nil {
log.Error("error when getting DIMM endpoints from "+DL560, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
Expand Down Expand Up @@ -789,30 +786,30 @@ func getChassisEndpoint(url, host string, client *retryablehttp.Client) (string,
return urlFinal, nil
}

func getBIOSVersion(url, host string, client *retryablehttp.Client) (string, error) {
var biosVer oem.ServerManager
func getSystemsMetadata(url, host string, client *retryablehttp.Client) (oem.ServerManager, error) {
var sm oem.ServerManager
req := common.BuildRequest(url, host)

resp, err := client.Do(req)
if err != nil {
return "", err
return sm, err
}
defer resp.Body.Close()
if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
return "", fmt.Errorf("HTTP status %d", resp.StatusCode)
return sm, fmt.Errorf("HTTP status %d", resp.StatusCode)
}

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

err = json.Unmarshal(body, &biosVer)
err = json.Unmarshal(body, &sm)
if err != nil {
return "", fmt.Errorf("Error Unmarshalling DL560 ServerManager struct - " + err.Error())
return sm, fmt.Errorf("Error Unmarshalling DL560 ServerManager struct - " + err.Error())
}

return biosVer.BiosVersion, nil
return sm, nil
}

func getDIMMEndpoints(url, host string, client *retryablehttp.Client) (oem.Collection, error) {
Expand Down
27 changes: 12 additions & 15 deletions hpe/xl420/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"net"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -171,15 +170,13 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
return nil, err
}

exp.chassisSerialNumber = path.Base(sysEndpoint)

// chassis BIOS version
biosVer, err := getBIOSVersion(fqdn.String()+sysEndpoint, target, retryClient)
resp, err := getSystemsMetadata(fqdn.String()+sysEndpoint, target, retryClient)
if err != nil {
log.Error("error when getting BIOS version from "+XL420, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
}
exp.biosVersion = biosVer
exp.biosVersion = resp.BiosVersion
exp.chassisSerialNumber = resp.SerialNumber

// vars for drive parsing
var (
Expand Down Expand Up @@ -306,7 +303,7 @@ func NewExporter(ctx context.Context, target, uri, profile string) (*Exporter, e
}

// DIMM endpoints array
dimms, err := getDIMMEndpoints(fqdn.String()+sysEndpoint+"/Memory", target, retryClient)
dimms, err := getDIMMEndpoints(fqdn.String()+sysEndpoint+"Memory/", target, retryClient)
if err != nil {
log.Error("error when getting DIMM endpoints from "+XL420, zap.Error(err), zap.Any("trace_id", ctx.Value("traceID")))
return nil, err
Expand Down Expand Up @@ -930,30 +927,30 @@ func getChassisEndpoint(url, host string, client *retryablehttp.Client) (string,
return urlFinal, nil
}

func getBIOSVersion(url, host string, client *retryablehttp.Client) (string, error) {
var biosVer oem.ServerManager
func getSystemsMetadata(url, host string, client *retryablehttp.Client) (oem.ServerManager, error) {
var sm oem.ServerManager
req := common.BuildRequest(url, host)

resp, err := client.Do(req)
if err != nil {
return "", err
return sm, err
}
defer resp.Body.Close()
if !(resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices) {
return "", fmt.Errorf("HTTP status %d", resp.StatusCode)
return sm, fmt.Errorf("HTTP status %d", resp.StatusCode)
}

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

err = json.Unmarshal(body, &biosVer)
err = json.Unmarshal(body, &sm)
if err != nil {
return "", fmt.Errorf("Error Unmarshalling XL420 ServerManager struct - " + err.Error())
return sm, fmt.Errorf("Error Unmarshalling XL420 ServerManager struct - " + err.Error())
}

return biosVer.BiosVersion, nil
return sm, nil
}

func getDIMMEndpoints(url, host string, client *retryablehttp.Client) (oem.Collection, error) {
Expand Down
Loading
Loading