Allow global configuration for redfish devices username, password and endpoint.

This commit is contained in:
Holger Obermaier 2022-08-25 16:47:44 +02:00
parent 60ef0ed116
commit 7ccbf1ebe2
2 changed files with 34 additions and 20 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "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) // Time limit for requests made by this HTTP client (default: 10 s)
HttpTimeoutString string `json:"http_timeout,omitempty"` 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 // Globally disable collection of power, processor or thermal metrics
DisablePowerMetrics bool `json:"disable_power_metrics"` DisablePowerMetrics bool `json:"disable_power_metrics"`
DisableProcessorMetrics bool `json:"disable_processor_metrics"` DisableProcessorMetrics bool `json:"disable_processor_metrics"`
@ -719,26 +725,37 @@ func NewRedfishReceiver(name string, config json.RawMessage) (Receiver, error) {
} }
clientConfig.Hostname = *clientConfigJSON.Hostname 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) err := fmt.Errorf("client config number %v requires endpoint", i)
cclog.ComponentError(r.name, err) cclog.ComponentError(r.name, err)
return nil, 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) err := fmt.Errorf("client config number %v requires username", i)
cclog.ComponentError(r.name, err) cclog.ComponentError(r.name, err)
return nil, 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) err := fmt.Errorf("client config number %v requires password", i)
cclog.ComponentError(r.name, err) cclog.ComponentError(r.name, err)
return nil, err return nil, err
} }
gofishConfig.Password = *clientConfigJSON.Password
// Reuse existing http client // Reuse existing http client
gofishConfig.HTTPClient = httpClient gofishConfig.HTTPClient = httpClient

View File

@ -8,26 +8,23 @@ The Redfish receiver uses the [Redfish (specification)](https://www.dmtf.org/sta
{ {
"<redfish receiver name>": { "<redfish receiver name>": {
"type": "redfish", "type": "redfish",
"username": "<user A>",
"password": "<password A>",
"endpoint": "https://%h-bmc",
"exclude_metrics": [ "min_consumed_watts" ], "exclude_metrics": [ "min_consumed_watts" ],
"client_config": [ "client_config": [
{ {
"hostname": "<host 1>", "hostname": "<host 1>"
"username": "<user 1>",
"password": "<password 1>",
"endpoint": "https://<endpoint 1>"
}, },
{ {
"hostname": "<host 2>", "hostname": "<host 2>",
"username": "<user 2>",
"password": "<password 2>",
"endpoint": "https://<endpoint 2>",
"disable_power_metrics": true "disable_power_metrics": true
}, },
{ {
"hostname": "<host 3>", "hostname": "<host 3>",
"username": "<user 3>", "username": "<user B>",
"password": "<password 3>", "password": "<password B>",
"endpoint": "https://<endpoint 3>", "endpoint": "https://%h-BMC",
"disable_thermal_metrics": true "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_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) - `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_power_metrics`: disable collection of power metrics
- `disable_thermal_metrics`: disable collection of thermal metrics - `disable_thermal_metrics`: disable collection of thermal metrics
- `exclude_metrics`: list of excluded 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: Per redfish device settings:
- `hostname`: hostname the redfish service belongs to - `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