Sha256: e6dc22eff83dbb10d4f9d37f64f841e8fe2447115d368eb00b884c5b0a5a56eb

Contents?: true

Size: 1 KB

Versions: 10

Compression:

Stored size: 1 KB

Contents

require "Grok"
require "pp"

patterns = {}

matches = [
  #"%{SYSLOGBASE} Accepted %{NOTSPACE:method} for %{DATA:user} from %{IPORHOST:client} port %{INT:port}",
  #"%{SYSLOGBASE} Did not receive identification string from %{IPORHOST:client}",
  #"%{SYSLOGBASE} error: PAM: authentication error for %{DATA:user} from %{IPORHOST:client}",
  "%{SYSLOGBASE} .*"
  #"%{COMBINEDAPACHELOG}",
  #"%{UNINDEXED}hello (?=%{GREEDYDATA})%{WORD}"
  
  #"( *%{DATA:key}:%{NOTSPACE:value})+"
]

groks = matches.collect do |m|
  g = Grok.new
  g.add_patterns_from_file("../patterns/base")
  g.compile(m)
  g
end

bytes = 0
time_start = Time.now.to_f
$stdin.each do |line|
  groks.each do |grok|
    m = grok.match(line)
    if m
      #data = Hash.new { |h,k| h[k] = Array.new }
      #m.each_capture do |key, value|
        #data[key] << value
      #end
      #pp data
      pp m.captures
      #bytes += line.length
      break
    end
  end
end

#time_end = Time.now.to_f
#puts "parse rate: #{ (bytes / 1024) / (time_end - time_start) }"

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
jls-grok-0.2.3091 sample.rb
jls-grok-0.2.3089 sample.rb
jls-grok-0.2.3071 sample.rb
jls-grok-0.1.3068 sample.rb
jls-grok-0.1.2840 sample.rb
jls-grok-0.1.2824 sample.rb
jls-grok-0.1.2823 sample.rb
jls-grok-0.1.2821 sample.rb
jls-grok-0.1.2787 sample.rb
jls-grok-0.1.2786 sample.rb