Skip to content

Commit

Permalink
README changes for the windows AD inventory receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
rnishtala-sumo committed Nov 3, 2023
1 parent 93dd18f commit d240ffb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions pkg/receiver/activedirectoryinvreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/receiver/activedirectoryinvreceiver/adinvreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
8 changes: 4 additions & 4 deletions pkg/receiver/activedirectoryinvreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
)

Expand All @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/receiver/activedirectoryinvreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ 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,
},
},
{
name: "Valid Config DC",
config: ADConfig{
DN: "DC=exampledomain,DC=com",
BaseDN: "DC=exampledomain,DC=com",
Attributes: []string{"name"},
PollInterval: 60 * time.Second,
},
},
{
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,
},
},
{
name: "Invalid DN",
config: ADConfig{
DN: "NA",
BaseDN: "NA",
Attributes: []string{"name"},
PollInterval: 24 * time.Hour,
},
Expand All @@ -63,7 +63,7 @@ func TestValidate(t *testing.T) {
{
name: "Invalid Empty DN",
config: ADConfig{
DN: "",
BaseDN: "",
Attributes: []string{"name"},
PollInterval: 24 * time.Hour,
},
Expand All @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/receiver/activedirectoryinvreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit d240ffb

Please sign in to comment.