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

Not to load WinevtXMLparser by default #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions lib/fluent/plugin/in_windows_eventlog2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ReconnectError < Fluent::UnrecoverableError; end
end

config_section :parse do
config_set_default :@type, 'winevt_xml'
config_set_default :@type, 'windows_eventlog2_dummy'
config_set_default :estimate_current_event, false
end

Expand Down Expand Up @@ -122,7 +122,12 @@ def configure(conf)
@winevt_xml = false
@parser = nil
if @render_as_xml
@parser = parser_create
parser_config = @parser_configs.first
if parser_config["@type"] == "windows_eventlog2_dummy"
@parser = parser_create(usage: "parse_xml", type: "winevt_xml", conf: conf.elements("parse").first)
else
@parser = parser_create
end
@winevt_xml = @parser.respond_to?(:winevt_xml?) && @parser.winevt_xml?
class << self
alias_method :on_notify, :on_notify_xml
Expand Down Expand Up @@ -407,4 +412,16 @@ def to_key(key)
end
####
end

class WindowsEventLog2DummyParser < Parser
Fluent::Plugin.register_parser('windows_eventlog2_dummy', self)

def configure(conf)
super
end

def parse(text)
raise NotImplementedError, "This is a dummy parser for the default setting and can not be used actually."
end
end
end
12 changes: 12 additions & 0 deletions test/plugin/test_in_windows_eventlog2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ def test_configure
])
end
end

test "default parser should not be WinevtXMLparser" do
# Because it is not a mandatory dependency.
d = create_driver CONFIG
assert_equal 1, d.instance._parsers.size
assert_not_equal "Fluent::Plugin::WinevtXMLparser", d.instance._parsers.values.first.class.name
end

test "parser should be WinevtXMLparser if render_as_xml is enabled" do
d = create_driver XML_RENDERING_CONFIG
assert_equal Fluent::Plugin::WinevtXMLparser, d.instance.instance_variable_get(:@parser).class
end
end

data("Japanese" => ["ja_JP", false],
Expand Down