Class: Fluent::Plugin::GrokParser
- Inherits:
-
Parser
- Object
- Parser
- Fluent::Plugin::GrokParser
- Defined in:
- lib/fluent/plugin/parser_grok.rb
Direct Known Subclasses
Instance Method Summary collapse
- #configure(conf = {}) ⇒ Object
-
#initialize ⇒ GrokParser
constructor
A new instance of GrokParser.
- #parse(text) ⇒ Object
Constructor Details
#initialize ⇒ GrokParser
Returns a new instance of GrokParser.
18 19 20 21 |
# File 'lib/fluent/plugin/parser_grok.rb', line 18 def initialize super @default_parser = Fluent::Plugin::NoneParser.new end |
Instance Method Details
#configure(conf = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fluent/plugin/parser_grok.rb', line 23 def configure(conf={}) super @grok = Grok.new(self, conf) default_pattern_dir = File.("../../../../patterns/*", __FILE__) Dir.glob(default_pattern_dir) do |pattern_file_path| @grok.add_patterns_from_file(pattern_file_path) end if @custom_pattern_path if Dir.exist? @custom_pattern_path Dir.glob(@custom_pattern_path + "/*") do |pattern_file_path| @grok.add_patterns_from_file(pattern_file_path) end elsif File.exist? @custom_pattern_path @grok.add_patterns_from_file(@custom_pattern_path) end end @grok.setup end |
#parse(text) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fluent/plugin/parser_grok.rb', line 46 def parse(text) @grok.parsers.each do |parser| parser.parse(text) do |time, record| if time and record yield time, record return end end end @default_parser.parse(text) do |time, record| record[@grok_failure_key] = "No grok pattern matched" if @grok_failure_key yield time, record end end |