Use package hostlist to expand a host list

This commit is contained in:
Holger Obermaier 2022-12-01 09:25:40 +01:00
parent a29f0c7e3b
commit 6f1f33f3a5
3 changed files with 24 additions and 20 deletions

View File

@ -32,18 +32,14 @@
{ {
"username": "username-1", "username": "username-1",
"password": "password-1", "password": "password-1",
"endpoint": "ipmi-sensors://my-endpoint-1", "endpoint": "ipmi-sensors://%h-ipmi",
"host_list": [ "host_list": "my-host-1-[1-2]"
"my-host-1"
]
}, },
{ {
"username": "username-2", "username": "username-2",
"password": "password-2", "password": "password-2",
"endpoint": "ipmi-sensors://my-endpoint-2", "endpoint": "ipmi-sensors://%h-ipmi",
"host_list": [ "host_list": "my-host-2-[1,2]"
"my-host-2"
]
} }
] ]
} }

View File

@ -15,6 +15,7 @@ import (
cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger" cclog "github.com/ClusterCockpit/cc-metric-collector/pkg/ccLogger"
lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric" lp "github.com/ClusterCockpit/cc-metric-collector/pkg/ccMetric"
"github.com/ClusterCockpit/cc-metric-collector/pkg/hostlist"
) )
type IPMIReceiverClientConfig struct { type IPMIReceiverClientConfig struct {
@ -319,12 +320,12 @@ func NewIPMIReceiver(name string, config json.RawMessage) (Receiver, error) {
ExcludeMetrics []string `json:"exclude_metrics,omitempty"` ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
ClientConfigs []struct { ClientConfigs []struct {
Fanout int `json:"fanout,omitempty"` // Maximum number of simultaneous IPMI connections (default: 64) Fanout int `json:"fanout,omitempty"` // Maximum number of simultaneous IPMI connections (default: 64)
DriverType string `json:"driver_type,omitempty"` // Out of band IPMI driver (default: LAN_2_0) DriverType string `json:"driver_type,omitempty"` // Out of band IPMI driver (default: LAN_2_0)
HostList []string `json:"host_list"` // List of hosts with the same client configuration HostList string `json:"host_list"` // List of hosts with the same client configuration
Username *string `json:"username"` // User name to authenticate with Username *string `json:"username"` // User name to authenticate with
Password *string `json:"password"` // Password to use for authentication Password *string `json:"password"` // Password to use for authentication
Endpoint *string `json:"endpoint"` // URL of the IPMI service Endpoint *string `json:"endpoint"` // URL of the IPMI service
// Per client excluded metrics // Per client excluded metrics
ExcludeMetrics []string `json:"exclude_metrics,omitempty"` ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
@ -435,10 +436,17 @@ func NewIPMIReceiver(name string, config json.RawMessage) (Receiver, error) {
return nil, err return nil, err
} }
// Create mapping between ipmi hostname and node hostname // Create mapping between IPMI host name and node host name
// This also guaranties that all ipmi hostnames are uniqu // This also guaranties that all IPMI host names are unique
ipmi2HostMapping := make(map[string]string) ipmi2HostMapping := make(map[string]string)
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 {
ipmiHost := strings.Replace(host_pattern, "%h", host, -1) ipmiHost := strings.Replace(host_pattern, "%h", host, -1)
ipmi2HostMapping[ipmiHost] = host ipmi2HostMapping[ipmiHost] = host
} }

View File

@ -16,10 +16,10 @@ The IPMI Receiver uses `ipmi-sensors` from the [FreeIPMI](https://www.gnu.org/so
"exclude_metrics": [ "fan_speed", "voltage" ], "exclude_metrics": [ "fan_speed", "voltage" ],
"client_config": [ "client_config": [
{ {
"host_list": ["n1", "n2", "n3", "n4" ] "host_list": "n[1,2-4]"
}, },
{ {
"host_list": [ "n5", "n6" ], "host_list": "n[5-6]",
"driver_type": "LAN", "driver_type": "LAN",
"cli_options": [ "--workaround-flags=..." ], "cli_options": [ "--workaround-flags=..." ],
"password": "<Password 2>" "password": "<Password 2>"