Skip to content

Commit

Permalink
Revert "[filebeat][winlog] implement status reporter for winlog input (
Browse files Browse the repository at this point in the history
…elastic#40163)"

This reverts commit 5e4e7e5.
  • Loading branch information
cmacknz committed Oct 28, 2024
1 parent 7aae4c8 commit 1636258
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions filebeat/input/winlog/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
input "github.com/elastic/beats/v7/filebeat/input/v2"
cursor "github.com/elastic/beats/v7/filebeat/input/v2/input-cursor"
"github.com/elastic/beats/v7/libbeat/feature"
"github.com/elastic/beats/v7/libbeat/management/status"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/go-concert/ctxtool"
"github.com/elastic/go-concert/timed"
Expand All @@ -40,10 +39,6 @@ type eventlogRunner struct{}

const pluginName = "winlog"

const channelNotFoundError = "Encountered channel not found error when opening Windows Event Log"
const eventLogReadingError = "Error occurred while reading from Windows Event Log"
const resetError = "Error resetting Windows Event Log handle"

// Plugin create a stateful input Plugin collecting logs from Windows Event Logs.
func Plugin(log *logp.Logger, store cursor.StateStore) input.Plugin {
return input.Plugin{
Expand Down Expand Up @@ -104,7 +99,6 @@ func (eventlogRunner) Run(

// Flag used to detect repeat "channel not found" errors, eliminating log spam.
channelNotFoundErrDetected := false
ctx.UpdateStatus(status.Running, "")

runLoop:
for {
Expand All @@ -115,9 +109,6 @@ runLoop:

evtCheckpoint := initCheckpoint(log, cursor)
openErr := api.Open(evtCheckpoint)
// Mark the input running.
// Status will be changed to "Degraded" if any error are encountered during opening/reading
ctx.UpdateStatus(status.Running, "")

switch {
case eventlog.IsRecoverable(openErr):
Expand All @@ -126,16 +117,14 @@ runLoop:
continue
case !api.IsFile() && eventlog.IsChannelNotFound(openErr):
if !channelNotFoundErrDetected {
log.Errorw(channelNotFoundError, "error", openErr)
log.Errorw("Encountered channel not found error when opening Windows Event Log", "error", openErr)
} else {
log.Debugw(channelNotFoundError, "error", openErr)
log.Debugw("Encountered channel not found error when opening Windows Event Log", "error", openErr)
}
ctx.UpdateStatus(status.Degraded, fmt.Sprintf("%s: %v", channelNotFoundError, openErr))
channelNotFoundErrDetected = true
_ = timed.Wait(cancelCtx, 5*time.Second)
continue
case openErr != nil:
ctx.UpdateStatus(status.Degraded, fmt.Sprintf("failed to open Windows Event Log channel %q: %v", api.Channel(), openErr))
return fmt.Errorf("failed to open Windows Event Log channel %q: %w", api.Channel(), openErr)
}
channelNotFoundErrDetected = false
Expand All @@ -148,16 +137,14 @@ runLoop:
if eventlog.IsRecoverable(err) {
log.Errorw("Encountered recoverable error when reading from Windows Event Log", "error", err)
if resetErr := api.Reset(); resetErr != nil {
log.Errorw(resetError, "error", resetErr)
ctx.UpdateStatus(status.Degraded, fmt.Sprintf("%s: %v", resetError, resetErr))
log.Errorw("Error resetting Windows Event Log handle", "error", resetErr)
}
continue runLoop
}
if !api.IsFile() && eventlog.IsChannelNotFound(err) {
log.Errorw("Encountered channel not found error when reading from Windows Event Log", "error", err)
if resetErr := api.Reset(); resetErr != nil {
log.Errorw(resetError, "error", resetErr)
ctx.UpdateStatus(status.Degraded, fmt.Sprintf("%s: %v", resetError, resetErr))
log.Errorw("Error resetting Windows Event Log handle", "error", resetErr)
}
continue runLoop
}
Expand All @@ -173,8 +160,7 @@ runLoop:
return nil
}

log.Errorw(eventLogReadingError, "error", err)
ctx.UpdateStatus(status.Degraded, fmt.Sprintf("%s: %v", eventLogReadingError, err))
log.Errorw("Error occurred while reading from Windows Event Log", "error", err)
return err
}
if len(records) == 0 {
Expand All @@ -187,7 +173,6 @@ runLoop:
if err := publisher.Publish(event, record.Offset); err != nil {
// Publisher indicates disconnect when returning an error.
// stop trying to publish records and quit
ctx.UpdateStatus(status.Degraded, fmt.Sprintf("Error occurred while publishing from winlog: %v", err))
return err
}
}
Expand Down

0 comments on commit 1636258

Please sign in to comment.