Class: Fluent::Grok
- Inherits:
-
Object
- Object
- Fluent::Grok
- Defined in:
- lib/fluent/plugin/grok.rb
Defined Under Namespace
Classes: GrokPatternNotFoundError
Constant Summary collapse
- PATTERN_RE =
Much of the Grok implementation is based on Jordan Sissel’s jls-grok See github.com/jordansissel/ruby-grok/blob/master/lib/grok-pure.rb
/%\{ # match '%{' not prefixed with '\' (?<name> # match the pattern name (?<pattern>[A-z0-9]+) (?::(?<subname>[@\[\]A-z0-9_:.-]+?) (?::(?<type>(?:string|bool|integer|float| time(?::.+?)?| array(?::.)?)))?)? ) \}/x
Instance Attribute Summary collapse
-
#multiline_start_regexp ⇒ Object
readonly
Returns the value of attribute multiline_start_regexp.
-
#parsers ⇒ Object
readonly
Returns the value of attribute parsers.
Instance Method Summary collapse
- #add_patterns_from_file(path) ⇒ Object
-
#initialize(plugin, conf) ⇒ Grok
constructor
A new instance of Grok.
- #setup ⇒ Object
Constructor Details
#initialize(plugin, conf) ⇒ Grok
Returns a new instance of Grok.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fluent/plugin/grok.rb', line 24 def initialize(plugin, conf) @pattern_map = {} @parsers = {} @multiline_mode = false @conf = conf @plugin = plugin if @plugin.respond_to?(:firstline?) @multiline_mode = true end if @plugin.respond_to?(:multiline_start_regexp) && @plugin.multiline_start_regexp @multiline_start_regexp = Regexp.compile(@plugin.multiline_start_regexp[1..-2]) end if @plugin.respond_to?(:keep_time_key) @keep_time_key = @plugin.keep_time_key end if @plugin.respond_to?(:time_format) @time_format = @plugin.time_format end end |
Instance Attribute Details
#multiline_start_regexp ⇒ Object (readonly)
Returns the value of attribute multiline_start_regexp.
22 23 24 |
# File 'lib/fluent/plugin/grok.rb', line 22 def multiline_start_regexp @multiline_start_regexp end |
#parsers ⇒ Object (readonly)
Returns the value of attribute parsers.
21 22 23 |
# File 'lib/fluent/plugin/grok.rb', line 21 def parsers @parsers end |
Instance Method Details
#add_patterns_from_file(path) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/fluent/plugin/grok.rb', line 44 def add_patterns_from_file(path) File.open(path, "r:utf-8:utf-8").each_line do |line| next if line[0] == "#" || /^$/ =~ line name, pat = line.chomp.split(/\s+/, 2) @pattern_map[name] = pat end end |
#setup ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fluent/plugin/grok.rb', line 52 def setup if @plugin.grok_pattern @parsers[:grok_pattern] = (@plugin.grok_pattern, @conf) else @plugin.grok_confs.each.with_index do |grok_conf, index| @parsers[grok_conf.name || index] = (grok_conf) end end @parsers.reject! do |key, parser| parser.nil? end if @parsers.empty? raise Fluent::ConfigError, 'no grok patterns. Check configuration, e.g. typo, configuration syntax, etc' end end |