From 31a8e63d728d7d5cb773c677dab6de9785cd86f5 Mon Sep 17 00:00:00 2001 From: Holger Obermaier <40787752+ho-ob@users.noreply.github.com> Date: Thu, 1 Dec 2022 09:48:34 +0100 Subject: [PATCH] Use package hostlist to expand a host list --- receivers.json | 16 +++++++--------- receivers/ipmiReceiver.md | 2 +- receivers/redfishReceiver.go | 18 +++++++++++++----- receivers/redfishReceiver.md | 14 +++++++------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/receivers.json b/receivers.json index ae07225..dac979e 100644 --- a/receivers.json +++ b/receivers.json @@ -7,23 +7,23 @@ }, "redfish_recv": { "type": "redfish", + "endpoint": "https://%h-bmc", "client_config": [ { - "hostname": "my-host-1", + "host_list": "my-host-1-[1-2]", "username": "username-1", - "password": "password-1", - "endpoint": "https://my-endpoint-1" + "password": "password-1" }, { - "hostname": "my-host-2", + "host_list": "my-host-2-[1,2]", "username": "username-2", - "password": "password-2", - "endpoint": "https://my-endpoint-2" + "password": "password-2" } ] }, "ipmi_recv": { "type": "ipmi", + "endpoint": "ipmi-sensors://%h-ipmi", "exclude_metrics": [ "fan_speed", "voltage" @@ -32,15 +32,13 @@ { "username": "username-1", "password": "password-1", - "endpoint": "ipmi-sensors://%h-ipmi", "host_list": "my-host-1-[1-2]" }, { "username": "username-2", "password": "password-2", - "endpoint": "ipmi-sensors://%h-ipmi", "host_list": "my-host-2-[1,2]" } ] } -} +} \ No newline at end of file diff --git a/receivers/ipmiReceiver.md b/receivers/ipmiReceiver.md index cdf8e72..7d7369f 100644 --- a/receivers/ipmiReceiver.md +++ b/receivers/ipmiReceiver.md @@ -12,7 +12,7 @@ The IPMI Receiver uses `ipmi-sensors` from the [FreeIPMI](https://www.gnu.org/so "fanout": 256, "username": "", "password": "", - "endpoint": "ipmi-sensors://%h-p", + "endpoint": "ipmi-sensors://%h-bmc", "exclude_metrics": [ "fan_speed", "voltage" ], "client_config": [ { diff --git a/receivers/redfishReceiver.go b/receivers/redfishReceiver.go index de9744d..a37a296 100644 --- a/receivers/redfishReceiver.go +++ b/receivers/redfishReceiver.go @@ -12,6 +12,7 @@ import ( cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger" lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric" + "github.com/ClusterCockpit/cc-metric-collector/pkg/hostlist" // See: https://pkg.go.dev/github.com/stmcginnis/gofish "github.com/stmcginnis/gofish" @@ -630,10 +631,10 @@ func NewRedfishReceiver(name string, config json.RawMessage) (Receiver, error) { ExcludeMetrics []string `json:"exclude_metrics,omitempty"` ClientConfigs []struct { - HostList []string `json:"host_list"` // List of hosts with the same client configuration - 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 + HostList string `json:"host_list"` // List of hosts with the same client configuration + 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 // Per client disable collection of power,processor or thermal metrics DisablePowerMetrics bool `json:"disable_power_metrics"` @@ -763,7 +764,14 @@ func NewRedfishReceiver(name string, config json.RawMessage) (Receiver, error) { isExcluded[key] = true } - for _, host := range clientConfigJSON.HostList { + hostList, err := hostlist.Expand(clientConfigJSON.HostList) + if err != nil { + err := fmt.Errorf("client config number %d failed to parse host list %s: %v", + i, clientConfigJSON.HostList, err) + cclog.ComponentError(r.name, err) + return nil, err + } + for _, host := range hostList { // Endpoint of the redfish service endpoint := strings.Replace(endpoint_pattern, "%h", host, -1) diff --git a/receivers/redfishReceiver.md b/receivers/redfishReceiver.md index 1bc3ed8..7eb6f34 100644 --- a/receivers/redfishReceiver.md +++ b/receivers/redfishReceiver.md @@ -8,22 +8,22 @@ The Redfish receiver uses the [Redfish (specification)](https://www.dmtf.org/sta { "": { "type": "redfish", - "username": "", - "password": "", + "username": "", + "password": "", "endpoint": "https://%h-bmc", "exclude_metrics": [ "min_consumed_watts" ], "client_config": [ { - "host_list": [ "", "" ] + "host_list": "n[1,2-4]" }, { - "host_list": [ "", "" ] + "host_list": "n5" "disable_power_metrics": true }, { - "host_list": [ "" ], - "username": "", - "password": "", + "host_list": "n6" ], + "username": "", + "password": "", "endpoint": "https://%h-BMC", "disable_thermal_metrics": true }