diff --git a/pkg/receiver/activedirectoryinvreceiver/README.md b/pkg/receiver/activedirectoryinvreceiver/README.md index 363bf40917..fa9f856543 100644 --- a/pkg/receiver/activedirectoryinvreceiver/README.md +++ b/pkg/receiver/activedirectoryinvreceiver/README.md @@ -13,6 +13,7 @@ receivers: active_directory_inv: # Base DN # default = "" + # Base DN is a required field and cannot remain empty (default) base_dn: "CN=Users,DC=exampledomain,DC=com" # User attributes diff --git a/pkg/receiver/activedirectoryinvreceiver/adinvreceiver.go b/pkg/receiver/activedirectoryinvreceiver/adinvreceiver.go index 7de1b3f8b5..1f1ff88631 100644 --- a/pkg/receiver/activedirectoryinvreceiver/adinvreceiver.go +++ b/pkg/receiver/activedirectoryinvreceiver/adinvreceiver.go @@ -155,7 +155,7 @@ func (r *ADReceiver) poll(ctx context.Context) error { rl := logs.ResourceLogs().AppendEmpty() resourceLogs := &rl _ = resourceLogs.ScopeLogs().AppendEmpty() - root, err := r.client.Open(r.config.DN, resourceLogs) + root, err := r.client.Open(r.config.BaseDN, resourceLogs) if err != nil { return fmt.Errorf("Invalid Distinguished Name, please verify that the domain exists: %w", err) } diff --git a/pkg/receiver/activedirectoryinvreceiver/adinvreceiver_test.go b/pkg/receiver/activedirectoryinvreceiver/adinvreceiver_test.go index e717ab39dc..e12247a803 100644 --- a/pkg/receiver/activedirectoryinvreceiver/adinvreceiver_test.go +++ b/pkg/receiver/activedirectoryinvreceiver/adinvreceiver_test.go @@ -96,7 +96,7 @@ func (mo *MockObjectIter) Close() { func TestStart(t *testing.T) { cfg := CreateDefaultConfig().(*ADConfig) - cfg.DN = "CN=Guest,CN=Users,DC=exampledomain,DC=com" + cfg.BaseDN = "CN=Guest,CN=Users,DC=exampledomain,DC=com" sink := &consumertest.LogsSink{} mockClient := &MockClient{} diff --git a/pkg/receiver/activedirectoryinvreceiver/config.go b/pkg/receiver/activedirectoryinvreceiver/config.go index 775a0a4da5..caf65f4cf0 100644 --- a/pkg/receiver/activedirectoryinvreceiver/config.go +++ b/pkg/receiver/activedirectoryinvreceiver/config.go @@ -23,14 +23,14 @@ import ( // ADConfig defines configuration for Active Directory Inventory receiver. type ADConfig struct { - DN string `mapstructure:"base_dn"` // DN is the base distinguished name to search from + BaseDN string `mapstructure:"base_dn"` // DN is the base distinguished name to search from Attributes []string `mapstructure:"attributes"` PollInterval time.Duration `mapstructure:"poll_interval"` } var ( - errInvalidDN = errors.New("Base DN is incorrect, it must be a valid distinguished name (CN=Guest,OU=Users,DC=example,DC=com)") - errInvalidPollInterval = errors.New("poll interval is incorrect, invalid duration") + errInvalidDN = errors.New("base_dn is required, it must be a valid distinguished name (CN=Guest,OU=Users,DC=example,DC=com)") + errInvalidPollInterval = errors.New("poll_interval is incorrect, invalid duration") errSupportedOS = errors.New(typeStr + " is only supported on Windows.") ) @@ -53,7 +53,7 @@ func (c *ADConfig) Validate() error { regex := regexp.MustCompile(pattern) // Check if the Base DN is valid - if !regex.MatchString(c.DN) { + if !regex.MatchString(c.BaseDN) { return errInvalidDN } diff --git a/pkg/receiver/activedirectoryinvreceiver/config_test.go b/pkg/receiver/activedirectoryinvreceiver/config_test.go index a21582f910..bbf7f050eb 100644 --- a/pkg/receiver/activedirectoryinvreceiver/config_test.go +++ b/pkg/receiver/activedirectoryinvreceiver/config_test.go @@ -30,7 +30,7 @@ func TestValidate(t *testing.T) { { name: "Valid Config CN", config: ADConfig{ - DN: "CN=Guest,CN=Users,DC=exampledomain,DC=com", + BaseDN: "CN=Guest,CN=Users,DC=exampledomain,DC=com", Attributes: []string{"name"}, PollInterval: 60 * time.Second, }, @@ -38,7 +38,7 @@ func TestValidate(t *testing.T) { { name: "Valid Config DC", config: ADConfig{ - DN: "DC=exampledomain,DC=com", + BaseDN: "DC=exampledomain,DC=com", Attributes: []string{"name"}, PollInterval: 60 * time.Second, }, @@ -46,7 +46,7 @@ func TestValidate(t *testing.T) { { name: "Valid Config OU", config: ADConfig{ - DN: "CN=Guest,OU=Users,DC=exampledomain,DC=com", + BaseDN: "CN=Guest,OU=Users,DC=exampledomain,DC=com", Attributes: []string{"name"}, PollInterval: 24 * time.Hour, }, @@ -54,7 +54,7 @@ func TestValidate(t *testing.T) { { name: "Invalid DN", config: ADConfig{ - DN: "NA", + BaseDN: "NA", Attributes: []string{"name"}, PollInterval: 24 * time.Hour, }, @@ -63,7 +63,7 @@ func TestValidate(t *testing.T) { { name: "Invalid Empty DN", config: ADConfig{ - DN: "", + BaseDN: "", Attributes: []string{"name"}, PollInterval: 24 * time.Hour, }, @@ -72,7 +72,7 @@ func TestValidate(t *testing.T) { { name: "Invalid Poll Interval", config: ADConfig{ - DN: "CN=Users,DC=exampledomain,DC=com", + BaseDN: "CN=Users,DC=exampledomain,DC=com", Attributes: []string{"name"}, PollInterval: 0, }, diff --git a/pkg/receiver/activedirectoryinvreceiver/factory.go b/pkg/receiver/activedirectoryinvreceiver/factory.go index 0744be3524..82e65ca47b 100644 --- a/pkg/receiver/activedirectoryinvreceiver/factory.go +++ b/pkg/receiver/activedirectoryinvreceiver/factory.go @@ -40,7 +40,7 @@ func NewFactory() receiver.Factory { // CreateDefaultConfig creates the default configuration for the receiver func CreateDefaultConfig() component.Config { return &ADConfig{ - DN: "", + BaseDN: "", Attributes: []string{"name", "mail", "department", "manager", "memberOf"}, PollInterval: 24 * time.Hour, }