diff --git a/.chloggen/sshcheckreceiver-fix-key_file-config-27035.yaml b/.chloggen/sshcheckreceiver-fix-key_file-config-27035.yaml new file mode 100755 index 000000000000..f44c92e35333 --- /dev/null +++ b/.chloggen/sshcheckreceiver-fix-key_file-config-27035.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'bug_fix' + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: sshcheckreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Use key_file instead of keyfile for the key in config. Aligns project practice, code, and docs. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [27035] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/receiver/sshcheckreceiver/README.md b/receiver/sshcheckreceiver/README.md index 7e3ad74b3b6b..211d6551afaa 100644 --- a/receiver/sshcheckreceiver/README.md +++ b/receiver/sshcheckreceiver/README.md @@ -24,9 +24,9 @@ If `ignore_host_key` is not set then host key validation requires the agent eith The following settings are required: - `endpoint` - `username` -- `password` or `keyfile` +- `password` or `key_file` -Either `password` or `keyfile` must be set. But if both are set then password is treated as the `passphrase` and the key is assumed to be encrypted. +Either `password` or `key_file` must be set. But if both are set then password is treated as the `passphrase` and the key is assumed to be encrypted. The following settings are optional: diff --git a/receiver/sshcheckreceiver/config.go b/receiver/sshcheckreceiver/config.go index 2650f26e5ea3..fed1ba9e9a10 100644 --- a/receiver/sshcheckreceiver/config.go +++ b/receiver/sshcheckreceiver/config.go @@ -20,7 +20,7 @@ var ( errMissingEndpoint = errors.New(`"endpoint" not specified in config`) errInvalidEndpoint = errors.New(`"endpoint" is invalid`) errMissingUsername = errors.New(`"username" not specified in config`) - errMissingPasswordAndKeyFile = errors.New(`either "password" or "keyfile" is required`) + errMissingPasswordAndKeyFile = errors.New(`either "password" or "key_file" is required`) errConfigNotSSHCheck = errors.New("config was not a SSH check receiver config") errWindowsUnsupported = errors.New(metadata.Type + " is unsupported on Windows.") diff --git a/receiver/sshcheckreceiver/config_test.go b/receiver/sshcheckreceiver/config_test.go index a512b6ad6ce0..94bc2a1ec411 100644 --- a/receiver/sshcheckreceiver/config_test.go +++ b/receiver/sshcheckreceiver/config_test.go @@ -4,10 +4,13 @@ package sshcheckreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sshcheckreceiver" import ( + "path/filepath" "testing" + "time" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/receiver/scraperhelper" "go.uber.org/multierr" @@ -32,7 +35,7 @@ func TestValidate(t *testing.T) { expectedErr error }{ { - desc: "missing password and keyfile", + desc: "missing password and key_file", cfg: &Config{ SSHClientSettings: configssh.SSHClientSettings{ Username: "otelu", @@ -82,7 +85,7 @@ func TestValidate(t *testing.T) { expectedErr: error(nil), }, { - desc: "no error with keyfile", + desc: "no error with key_file", cfg: &Config{ SSHClientSettings: configssh.SSHClientSettings{ Endpoint: "localhost:2222", @@ -105,3 +108,36 @@ func TestValidate(t *testing.T) { }) } } + +func TestLoadConfig(t *testing.T) { + // load test config + cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) + require.NoError(t, err) + rcvrs, err := cm.Sub("receivers") + require.NoError(t, err) + sshconf, err := rcvrs.Sub("sshcheck") + require.NoError(t, err) + // unmarshal to receiver config + actualConfig, ok := NewFactory().CreateDefaultConfig().(*Config) + require.True(t, ok) + require.NoError(t, sshconf.Unmarshal(actualConfig)) + + // set expected config + expectedConfig, ok := NewFactory().CreateDefaultConfig().(*Config) + require.True(t, ok) + + expectedConfig.ScraperControllerSettings = scraperhelper.ScraperControllerSettings{ + InitialDelay: time.Second, + CollectionInterval: 10 * time.Second, + } + expectedConfig.SSHClientSettings = configssh.SSHClientSettings{ + Endpoint: "notdefault:1313", + Username: "notdefault_username", + Password: "notdefault_password", + KeyFile: "notdefault/path/keyfile", + KnownHosts: "path/to/collector_known_hosts", + IgnoreHostKey: false, + Timeout: 10 * time.Second, + } + require.Equal(t, expectedConfig, actualConfig) +} diff --git a/receiver/sshcheckreceiver/testdata/config.yaml b/receiver/sshcheckreceiver/testdata/config.yaml index 3100b4563618..61b906205951 100644 --- a/receiver/sshcheckreceiver/testdata/config.yaml +++ b/receiver/sshcheckreceiver/testdata/config.yaml @@ -1,10 +1,10 @@ receivers: sshcheck: endpoint: notdefault:1313 - username: notdefault_password + username: notdefault_username password: notdefault_password - keyfile: notdefault/path/keyfile - collection_interval: 13m + key_file: notdefault/path/keyfile + collection_interval: 10s known_hosts: path/to/collector_known_hosts ignore_host_key: false