Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal support for Beats > 7.0 #7879

Merged
merged 1 commit into from
Apr 16, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ private Message parseEvent(JsonNode event) {
final String timestampField = event.path("@timestamp").asText();
final DateTime timestamp = Tools.dateTimeFromString(timestampField);

final JsonNode beat = event.path("beat");
final String hostname = beat.path("hostname").asText(BEATS_UNKNOWN);
JsonNode agentOrBeat = event.path("agent");
// backwards compatibility for beats < 7.0
if (agentOrBeat.isMissingNode()) {
agentOrBeat = event.path("beat");
}
final String hostname = agentOrBeat.path("hostname").asText(BEATS_UNKNOWN);

final Message gelfMessage = new Message(message, hostname, timestamp);
gelfMessage.addField("beats_type", beatsType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ public void decodeMessagesHandlesWinlogbeatMessages() throws Exception {
assertThat(message.getField("winlogbeat_log_name")).isEqualTo("Security");
}

@Test
public void decodeMessagesHandlesWinlogbeatv7Messages() throws Exception {
final Message message = codec.decode(messageFromJson("winlogbeat-v7.json"));
assertThat(message).isNotNull();
assertThat(message.getSource()).isEqualTo("example.local");
assertThat(message.getTimestamp()).isEqualTo(new DateTime(2016, 11, 24, 12, 13, DateTimeZone.UTC));
assertThat(message.getField("beats_type")).isEqualTo("winlogbeat");
assertThat(message.getField("winlogbeat_winlog_level")).isEqualTo("Information");
assertThat(message.getField("winlogbeat_winlog_event_id")).isEqualTo(5024);
assertThat(message.getField("winlogbeat_winlog_process_id")).isEqualTo(500);
assertThat(message.getField("winlogbeat_winlog_log_name")).isEqualTo("Security");
}

@Test
public void decodeMessagesHandleGenericBeatMessages() throws Exception {
final Message message = codec.decode(messageFromJson("generic.json"));
Expand Down Expand Up @@ -293,4 +306,4 @@ private RawMessage messageFromJson(String resourceName) throws IOException {
final byte[] json = Resources.toByteArray(resource);
return new RawMessage(json);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"@metadata": {
"beat": "winlogbeat"
},
"@timestamp": "2016-11-24T12:13:00.000Z",
"agent": {
"hostname": "example.local",
"version": "7.6.2"
},
"gl2_source_collector": "5a4b9161-2f6a-48f6-b121-109dc85c8481",
"winlog": {
"computer_name": "windows",
"event_id": 5024,
"keywords": [
"Audit Success"
],
"level": "Information",
"log_name": "Security",
"message": "The Windows Firewall service started successfully.",
"opcode": "Info",
"process_id": 500,
"provider_guid": "{54849625-5478-4994-A5BA-3E3B0328C30D}",
"record_number": "2126",
"source_name": "Microsoft-Windows-Security-Auditing",
"tags": [
"windows",
"iis"
],
"task": "Other System Events"
}
}