File: test.rb

package info (click to toggle)
grok 1.20110708.1-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,388 kB
  • sloc: ansic: 3,469; ruby: 987; makefile: 276; sh: 124; yacc: 106
file content (30 lines) | stat: -rw-r--r-- 744 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env ruby
#

require "rubygems"
require "grok"
require "pp"

grok = Grok.new

# Load some default patterns that ship with grok.
# See also: 
#   http://code.google.com/p/semicomplete/source/browse/grok/patterns/base
grok.add_patterns_from_file("../..//patterns/base")

# Using the patterns we know, try to build a grok pattern that best matches 
# a string we give. Let's try Time.now.to_s, which has this format;
# => Fri Apr 16 19:15:27 -0700 2010
input = "2010-04-18T15:06:02Z"
pattern = "%{TIMESTAMP_ISO8601}"
grok.compile(pattern)
grok.compile(pattern)
puts "Input: #{input}"
puts "Pattern: #{pattern}"
puts "Full: #{grok.expanded_pattern}"

match = grok.match(input)
if match
  puts "Resulting capture:"
  pp match.captures
end