Created
October 26, 2012 13:21
-
-
Save feylya/3958782 to your computer and use it in GitHub Desktop.
Run grok regex against log line
This file contains 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 | |
require 'rubygems' | |
require 'grok-pure' | |
grok = Grok.new | |
Dir["/vol/logstash/patterns/patterns"].each { |p| grok.add_patterns_from_file(p) } | |
text = 'Oct 26 06:49:36 logstash puppet-agent[4443]: Finished catalog run in 7.02 seconds' | |
puts grok.discover(text) | |
pattern = "Invalid user %{USER:user} from %{IP:ip}" | |
puts text | |
puts pattern | |
grok.compile(pattern) | |
match = grok.match(text) | |
if match | |
puts match.captures | |
else | |
puts match.inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment