diff --git a/receivers/redfishReceiver.go b/receivers/redfishReceiver.go index 71fb93d..dc4bcea 100644 --- a/receivers/redfishReceiver.go +++ b/receivers/redfishReceiver.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "sync" "time" @@ -615,6 +616,11 @@ func NewRedfishReceiver(name string, config json.RawMessage) (Receiver, error) { // Time limit for requests made by this HTTP client (default: 10 s) HttpTimeoutString string `json:"http_timeout,omitempty"` + // Default client username, password and endpoint + Username *string `json:"username"` // User name to authenticate with + Password *string `json:"password"` // Password to use for authentication + Endpoint *string `json:"endpoint"` // URL of the redfish service + // Globally disable collection of power, processor or thermal metrics DisablePowerMetrics bool `json:"disable_power_metrics"` DisableProcessorMetrics bool `json:"disable_processor_metrics"` @@ -719,26 +725,37 @@ func NewRedfishReceiver(name string, config json.RawMessage) (Receiver, error) { } clientConfig.Hostname = *clientConfigJSON.Hostname - if clientConfigJSON.Endpoint == nil { + var endpoint string + if clientConfigJSON.Endpoint != nil { + endpoint = *clientConfigJSON.Endpoint + } else if configJSON.Endpoint != nil { + endpoint = *configJSON.Endpoint + } else { err := fmt.Errorf("client config number %v requires endpoint", i) cclog.ComponentError(r.name, err) return nil, err } - gofishConfig.Endpoint = *clientConfigJSON.Endpoint + gofishConfig.Endpoint = strings.Replace(endpoint, "%h", clientConfig.Hostname, -1) - if clientConfigJSON.Username == nil { + if clientConfigJSON.Username != nil { + gofishConfig.Username = *clientConfigJSON.Username + } else if configJSON.Username != nil { + gofishConfig.Username = *configJSON.Username + } else { err := fmt.Errorf("client config number %v requires username", i) cclog.ComponentError(r.name, err) return nil, err } - gofishConfig.Username = *clientConfigJSON.Username - if clientConfigJSON.Password == nil { + if clientConfigJSON.Password != nil { + gofishConfig.Password = *clientConfigJSON.Password + } else if configJSON.Password != nil { + gofishConfig.Password = *configJSON.Password + } else { err := fmt.Errorf("client config number %v requires password", i) cclog.ComponentError(r.name, err) return nil, err } - gofishConfig.Password = *clientConfigJSON.Password // Reuse existing http client gofishConfig.HTTPClient = httpClient diff --git a/receivers/redfishReceiver.md b/receivers/redfishReceiver.md index 524c330..3ccb015 100644 --- a/receivers/redfishReceiver.md +++ b/receivers/redfishReceiver.md @@ -8,26 +8,23 @@ The Redfish receiver uses the [Redfish (specification)](https://www.dmtf.org/sta { "": { "type": "redfish", + "username": "", + "password": "", + "endpoint": "https://%h-bmc", "exclude_metrics": [ "min_consumed_watts" ], "client_config": [ { - "hostname": "", - "username": "", - "password": "", - "endpoint": "https://" + "hostname": "" }, { "hostname": "", - "username": "", - "password": "", - "endpoint": "https://", "disable_power_metrics": true }, { "hostname": "", - "username": "", - "password": "", - "endpoint": "https://", + "username": "", + "password": "", + "endpoint": "https://%h-BMC", "disable_thermal_metrics": true } ] @@ -42,15 +39,15 @@ Global settings: - `http_insecure`: Control whether a client verifies the server's certificate (default: true == do not verify server's certificate) - `http_timeout`: Time limit for requests made by this HTTP client (default: 10 s) -Global and per redfish device settings: +Global and per redfish device settings (per redfish device settings overwrite the global settings): - `disable_power_metrics`: disable collection of power metrics - `disable_thermal_metrics`: disable collection of thermal metrics - `exclude_metrics`: list of excluded metrics +- `username`: User name to authenticate with +- `password`: Password to use for authentication +- `endpoint`: URL of the redfish service (placeholder `%h` gets replaced by the hostname) Per redfish device settings: - `hostname`: hostname the redfish service belongs to -- `username`: User name to authenticate with -- `password`: Password to use for authentication -- `endpoint`: URL of the redfish service