Last active
September 2, 2020 02:21
-
-
Save jeffgeiger/d60b62a569c84108900e to your computer and use it in GitHub Desktop.
Test grok patterns without launching logstash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
=begin | |
USAGE: | |
cat example.log | ruby grokparse.rb | |
=end | |
require 'rubygems' | |
require 'grok-pure' | |
require 'pp' | |
grok = Grok.new | |
# Make sure these point to your pattern files | |
grok.add_patterns_from_file("/usr/local/share/grok/patterns/base") | |
grok.add_patterns_from_file("/usr/local/share/grok/patterns/bro") | |
pattern = '%{BROHTTP}' | |
grok.compile(pattern) | |
puts "PATTERN: #{pattern}" | |
while a = gets | |
puts "IN: #{a}" | |
match = grok.match(a) | |
if match | |
puts "MATCH:" | |
pp match.captures | |
else | |
puts "No Match." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment