-
-
Save marvin/e210c4189e1c1bbc9c31 to your computer and use it in GitHub Desktop.
watches a logfile and drops the new lines into mongodb
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
def watch_for(file) | |
f = File.open(file,"r") | |
f.seek(0,IO::SEEK_END) | |
while true do | |
select([f]) | |
line = f.gets | |
if line != nil | |
if file == "/var/log/syslog" | |
line.gsub!(/^(\w+.\d+.\d+:\d+:\d+)/u,"") | |
print line | |
else | |
line = f.gets | |
end | |
logentry = Log.create( | |
:jid => "0", | |
:logdate => Time.now, | |
:logfile => file, | |
:logentry => line | |
) | |
if logentry.errors | |
logentry.errors.each do |e| | |
puts e | |
end | |
end | |
end | |
end | |
end | |
Thread.new do | |
watch_for("/var/log/syslog") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment