Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion winlogbeat/eventlog/wineventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ func (l *winEventLog) Open(state checkpoint.EventLogState) error {
var err error
// we need to defer metrics initialization since when the event log
// is used from winlog input it would register it twice due to CheckConfig calls
l.metrics = newInputMetrics(l.channelName, l.id)
if l.metrics == nil {
l.metrics = newInputMetrics(l.channelName, l.id)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it mean that l.Open is called twice without l.Close? If so, there seems to be more issues

https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtsubscribe#return-value

so perhaps

-return l.openChannel(bookmark)
+ if l.subscription {
+    win.Close(l.subscription)
+}
+return l.openChannel(bookmark)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only gets called more than once in case it fails to open, so no need to call close in that case.

if len(state.Bookmark) > 0 {
bookmark, err = win.CreateBookmarkFromXML(state.Bookmark)
} else if state.RecordNumber > 0 && l.channelName != "" {
Expand Down
4 changes: 3 additions & 1 deletion winlogbeat/eventlog/wineventlog_experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ func (l *winEventLogExp) Open(state checkpoint.EventLogState) error {
l.lastRead = state
// we need to defer metrics initialization since when the event log
// is used from winlog input it would register it twice due to CheckConfig calls
l.metrics = newInputMetrics(l.channelName, l.id)
if l.metrics == nil {
l.metrics = newInputMetrics(l.channelName, l.id)
}

var err error
l.iterator, err = win.NewEventIterator(
Expand Down