Skip to content

Commit f093143

Browse files
authored
Merge pull request #113 from BlakeHensleyy/delimiter-options-for-parsing-fixed
Add Delimiter and Casing options for parsing
2 parents a198f14 + 76a6e4b commit f093143

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ Fluentd Input plugin for the Windows Event Log using newer Windows Event Logging
8282
|`<storage>` | Setting for `storage` plugin for recording read position like `in_tail`'s `pos_file`.|
8383
|`<parse>` | Setting for `parser` plugin for parsing raw XML EventLog records. |
8484
|`parse_description`| (option) parse `description` field and set parsed result into the record. `Description` and `EventData` fields are removed|
85+
|`description_key_delimiter`| (option) (Only applicable if parse_description is true) Change the character placed between the parent_key and key. Set the value to "" for no delimiter. Defaults to `.` .|
86+
|`description_word_delimiter`| (option) (Only applicable if parse_description is true) Change the character placed between each word of the key. Set the value to "" for no delimiter. Defaults to `_` .|
87+
|`downcase_description_keys`| (option) (Only applicable if parse_description is true) Specify whether to downcase the keys that are parsed from the Description. Defaults to `true`.|
8588
|`read_from_head` | **Deprecated** (option) Start to read the entries from the oldest, not from when fluentd is started. Defaults to `false`.|
8689
|`read_existing_events` | (option) Read the entries which already exist before fluentd is started. Defaults to `false`.|
8790
|`render_as_xml` | (option) Render Windows EventLog as XML or Ruby Hash object directly. Defaults to `false`.|

lib/fluent/plugin/in_windows_eventlog2.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class ReconnectError < Fluent::UnrecoverableError; end
4141
config_param :read_from_head, :bool, default: false, deprecated: "Use `read_existing_events' instead."
4242
config_param :read_existing_events, :bool, default: false
4343
config_param :parse_description, :bool, default: false
44+
config_param :description_key_delimiter, :string, default: "."
45+
config_param :description_word_delimiter, :string, default: "_"
46+
config_param :downcase_description_keys, :bool, default: true
4447
config_param :render_as_xml, :bool, default: false
4548
config_param :rate_limit, :integer, default: Winevt::EventLog::Subscribe::RATE_INFINITE
4649
config_param :preserve_qualifiers_on_hash, :bool, default: false
@@ -408,7 +411,7 @@ def parse_desc(record)
408411
elsif parent_key.nil?
409412
record[to_key(key)] = value
410413
else
411-
k = "#{parent_key}.#{to_key(key)}"
414+
k = "#{parent_key}#{@description_key_delimiter}#{to_key(key)}"
412415
record[k] = value
413416
end
414417
end
@@ -420,8 +423,8 @@ def parse_desc(record)
420423
end
421424

422425
def to_key(key)
423-
key.downcase!
424-
key.gsub!(' '.freeze, '_'.freeze)
426+
key.downcase! if @downcase_description_keys
427+
key.gsub!(' '.freeze, @description_word_delimiter)
425428
key
426429
end
427430
####

test/plugin/test_in_windows_eventlog2.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,36 @@ def test_parse_desc
238238
assert_equal(expected, h)
239239
end
240240

241+
def test_parse_desc_camelcase
242+
d = create_driver(config_element("ROOT", "", {"tag" => "fluent.eventlog",
243+
"parse_description" => true,
244+
"description_key_delimiter" => "",
245+
"description_word_delimiter" => "",
246+
"downcase_description_keys" => false
247+
}, [
248+
config_element("storage", "", {
249+
'@type' => 'local',
250+
'persistent' => false
251+
}),
252+
]))
253+
desc =<<-DESC
254+
A user's local group membership was enumerated.\r\n\r\nSubject:\r\n\tSecurity ID:\t\tS-X-Y-XX-WWWWWW-VVVV\r\n\tAccount Name:\t\tAdministrator\r\n\tAccount Domain:\t\tDESKTOP-FLUENTTEST\r\n\tLogon ID:\t\t0x3185B1\r\n\r\nUser:\r\n\tSecurity ID:\t\tS-X-Y-XX-WWWWWW-VVVV\r\n\tAccount Name:\t\tAdministrator\r\n\tAccount Domain:\t\tDESKTOP-FLUENTTEST\r\n\r\nProcess Information:\r\n\tProcess ID:\t\t0x50b8\r\n\tProcess Name:\t\tC:\\msys64\\usr\\bin\\make.exe
255+
DESC
256+
h = {"Description" => desc}
257+
expected = {"DescriptionTitle" => "A user's local group membership was enumerated.",
258+
"SubjectSecurityID" => "S-X-Y-XX-WWWWWW-VVVV",
259+
"SubjectAccountName" => "Administrator",
260+
"SubjectAccountDomain" => "DESKTOP-FLUENTTEST",
261+
"SubjectLogonID" => "0x3185B1",
262+
"UserSecurityID" => "S-X-Y-XX-WWWWWW-VVVV",
263+
"UserAccountName" => "Administrator",
264+
"UserAccountDomain" => "DESKTOP-FLUENTTEST",
265+
"ProcessInformationProcessID" => "0x50b8",
266+
"ProcessInformationProcessName" => "C:\\msys64\\usr\\bin\\make.exe"}
267+
d.instance.parse_desc(h)
268+
assert_equal(expected, h)
269+
end
270+
241271
def test_parse_privileges_description
242272
d = create_driver
243273
desc = ["Special privileges assigned to new logon.\r\n\r\nSubject:\r\n\tSecurity ID:\t\tS-X-Y-ZZ\r\n\t",

0 commit comments

Comments
 (0)