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.
35 36 37 38 |
# File 'lib/fluent/plugin/parser_grok.rb', line 35 def initialize super @default_parser = Fluent::Plugin::NoneParser.new end |
Instance Method Details
#configure(conf = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fluent/plugin/parser_grok.rb', line 40 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fluent/plugin/parser_grok.rb', line 63 def parse(text) @grok.parsers.each do |name_or_index, parser| parser.parse(text) do |time, record| if time and record record[@grok_name_key] = name_or_index if @grok_name_key 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 |