- Add MongoDB output

This commit is contained in:
Jordan Sissel 2010-10-18 00:07:36 +00:00
parent 6805a6ef03
commit 4c38c9d8fe

24
lib/outputs/mongodb.rb Normal file
View file

@ -0,0 +1,24 @@
require "logstash/namespace"
require "logstash/event"
require "uri"
require "em-mongo"
class LogStash::Outputs::Mongodb
def initialize(url, config={}, &block)
@url = url
@url = URI.parse(url) if url.is_a? String
@config = config
end
def register
# Port?
# Authentication?
db = @url.path[1..-1] # Skip leading '/'
@mongodb = EventMachine::Mongo::Connection.new(@url.host).db(db)
end # def register
def receive(event)
puts "Got: #{event}"
@mongodb.collection("events").insert(event.to_hash)
end # def event
end # class LogStash::Outputs::Websocket