-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read archived .evtx files with Winlogbeat (#11361)
This gives Winlogbeat the ability to read from archived .evtx files. The `name` parameter recognizes that the value is absolute path and then uses the appropriate APIs to open the file and ingest its contents. In order to support the use case of reading from a file and then exiting when there are no more events (`ERROR_NO_MORE_ITEMS`) I added a config option to change the behavior of the reader from waiting for more events to stopping. I also had to add `shutdown_timeout` option to make Winlogbeat wait for events to finish publishing before exiting. To keep it simple, globs are not supported. This would have required the introduction of a "prospector" to continuously monitor the glob for new / moved / deleted files. winlogbeat.event_logs: - name: ${EVTX_FILE} no_more_events: stop winlogbeat.shutdown_timeout: 30s winlogbeat.registry_file: evtx-registry.yml output.elasticsearch.hosts: ['http://localhost:9200'] Closes #4450
- Loading branch information
1 parent
17edc90
commit dfabb06
Showing
23 changed files
with
700 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package beater | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/elastic/beats/libbeat/common/atomic" | ||
"github.com/elastic/beats/winlogbeat/checkpoint" | ||
) | ||
|
||
type eventACKer struct { | ||
active *atomic.Int | ||
wg *sync.WaitGroup | ||
checkpoint *checkpoint.Checkpoint | ||
} | ||
|
||
func newEventACKer(checkpoint *checkpoint.Checkpoint) *eventACKer { | ||
return &eventACKer{ | ||
active: atomic.NewInt(0), | ||
wg: &sync.WaitGroup{}, | ||
checkpoint: checkpoint, | ||
} | ||
} | ||
|
||
// ACKEvents receives callbacks from the publisher for every event that is | ||
// published. It persists the record number of the last event in each | ||
func (a *eventACKer) ACKEvents(data []interface{}) { | ||
states := make(map[string]*checkpoint.EventLogState) | ||
|
||
for _, datum := range data { | ||
if st, ok := datum.(checkpoint.EventLogState); ok { | ||
states[st.Name] = &st | ||
} | ||
} | ||
|
||
for _, st := range states { | ||
a.checkpoint.PersistState(*st) | ||
} | ||
|
||
// Mark events as done (subtract). | ||
a.active.Add(-1 * len(data)) | ||
a.wg.Add(-1 * len(data)) | ||
} | ||
|
||
// Wait waits for all events to be ACKed or for the context to be done. | ||
func (a *eventACKer) Wait(ctx context.Context) { | ||
ctx, cancel := context.WithCancel(ctx) | ||
go func() { | ||
defer cancel() | ||
a.wg.Wait() | ||
}() | ||
<-ctx.Done() | ||
} | ||
|
||
// Add adds to the number of active events. | ||
func (a *eventACKer) Add(delta int) { | ||
a.active.Add(delta) | ||
a.wg.Add(delta) | ||
} | ||
|
||
// Active returns the number of active events (published but not yet ACKed). | ||
func (a *eventACKer) Active() int { | ||
return a.active.Load() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.