Skip to content

Commit

Permalink
Set document ID from audit record ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansr committed Feb 14, 2020
1 parent 31df65b commit c3d6aae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions x-pack/filebeat/input/o365audit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ type APIConfig struct {
// MaxRequestsPerMinute sets the limit on the number of API requests that
// can be sent, per tenant.
MaxRequestsPerMinute int `config:"max_requests_per_minute" validate:"positive"`

// SetIDFromAuditRecord controls whether the unique "Id" field in audit
// record is used as the document id for ingestion. This helps avoiding
// duplicates.
SetIDFromAuditRecord bool `config:"set_id_from_audit_record"`
}

func defaultConfig() Config {
Expand Down Expand Up @@ -122,6 +127,8 @@ func defaultConfig() Config {
// According to the docs this is the max requests that are allowed
// per tenant per minute.
MaxRequestsPerMinute: 2000,

SetIDFromAuditRecord: true,
},
}
}
Expand Down
9 changes: 7 additions & 2 deletions x-pack/filebeat/input/o365audit/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ var errTerminated = errors.New("terminated due to output closed")
// Report returns an action that produces a beat.Event from the given object.
func (env apiEnvironment) Report(doc common.MapStr, private interface{}) poll.Action {
return func(poll.Enqueuer) error {
if !env.Callback(toBeatEvent(doc, private)) {
if !env.Callback(env.toBeatEvent(doc, private)) {
return errTerminated
}
return nil
Expand All @@ -272,7 +272,7 @@ func (env apiEnvironment) ReportAPIError(err apiError) poll.Action {
}
}

func toBeatEvent(doc common.MapStr, private interface{}) beat.Event {
func (env apiEnvironment) toBeatEvent(doc common.MapStr, private interface{}) beat.Event {
var errs multierror.Errors
ts, err := getDateKey(doc, "CreationTime", apiDateFormats)
if err != nil {
Expand All @@ -286,6 +286,11 @@ func toBeatEvent(doc common.MapStr, private interface{}) beat.Event {
},
Private: private,
}
if env.Config.SetIDFromAuditRecord {
if id, err := getString(doc, "Id"); err == nil && len(id) > 0 {
b.SetID(id)
}
}
if len(errs) > 0 {
msgs := make([]string, len(errs))
for idx, e := range errs {
Expand Down

0 comments on commit c3d6aae

Please sign in to comment.