Skip to content

Commit

Permalink
Fix Winlogbeat registry file
Browse files Browse the repository at this point in the history
The registry file did not contain the event log name, and therefore resumption after restart did not work
at all and Winlogbeat would start from the beginning. This fixes that issue.

Fixes elastic#5813
  • Loading branch information
andrewkroh committed Dec 5, 2017
1 parent 3d9c606 commit 1706008
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di

*Winlogbeat*

- Fix the registry file. It was not correctly storing event log names, and
upon restart it would begin reading at the start of each event log. {issue}5813[5813]

==== Added

*Affecting all Beats*
Expand Down
2 changes: 1 addition & 1 deletion winlogbeat/eventlog/eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (e Record) ToEvent() beat.Event {
Timestamp: e.TimeCreated.SystemTime,
Fields: m,
Private: checkpoint.EventLogState{
Name: e.API,
Name: e.Channel,
RecordNumber: e.RecordID,
Timestamp: e.TimeCreated.SystemTime,
},
Expand Down
14 changes: 14 additions & 0 deletions winlogbeat/tests/system/test_eventlogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,17 @@ def test_utf16_characters(self):
})
self.assertTrue(len(evts), 1)
self.assertEqual(evts[0]["message"], msg)

def test_registry_data(self):
"""
eventlogging - Registry is updated
"""
self.write_event_log("Hello world!")
evts = self.read_events()
self.assertTrue(len(evts), 1)

event_logs = self.read_registry()
self.assertTrue(len(event_logs.keys()), 1)
self.assertIn(self.providerName, event_logs)
record_number = event_logs[self.providerName]["record_number"]
self.assertGreater(record_number, 0)
14 changes: 14 additions & 0 deletions winlogbeat/tests/system/test_wineventlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,17 @@ def test_utf16_characters(self):
})
self.assertTrue(len(evts), 1)
self.assertEqual(evts[0]["message"], msg)

def test_registry_data(self):
"""
wineventlog - Registry is updated
"""
self.write_event_log("Hello world!")
evts = self.read_events()
self.assertTrue(len(evts), 1)

event_logs = self.read_registry()
self.assertTrue(len(event_logs.keys()), 1)
self.assertIn(self.providerName, event_logs)
record_number = event_logs[self.providerName]["record_number"]
self.assertGreater(record_number, 0)
17 changes: 17 additions & 0 deletions winlogbeat/tests/system/winlogbeat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import platform
import sys
import yaml

if sys.platform.startswith("win"):
import win32api
Expand Down Expand Up @@ -95,6 +96,22 @@ def read_events(self, config=None, expected_events=1):

return self.read_output()

def read_registry(self):
f = open(os.path.join(self.working_dir, "data", ".winlogbeat.yml"), "r")
data = yaml.load(f)
self.assertIn("update_time", data)
self.assertIn("event_logs", data)

event_logs = {}
for event_log in data["event_logs"]:
self.assertIn("name", event_log)
self.assertIn("record_number", event_log)
self.assertIn("timestamp", event_log)
name = event_log["name"]
event_logs[name] = event_log

return event_logs

def assert_common_fields(self, evt, msg=None, eventID=10, sid=None,
level="Information", extra=None):
assert evt["computer_name"].lower() == platform.node().lower()
Expand Down

0 comments on commit 1706008

Please sign in to comment.