add mongodb authentication

This commit is contained in:
Evgeny Zislis 2011-05-26 02:09:39 +03:00
parent c48efe849c
commit 30c631a9f1

View file

@ -14,6 +14,9 @@ class LogStash::Outputs::Mongodb < LogStash::Outputs::Base
# The database to use
config :database, :validate => :string, :required => true
config :username, :validate => :string, :required => false
config :password, :validate => :string, :required => false
# The collection to use. This value can use %{foo} values to dynamically
# select a collection based on data in the event.
config :collection, :validate => :string, :required => true
@ -21,9 +24,16 @@ class LogStash::Outputs::Mongodb < LogStash::Outputs::Base
public
def register
require "mongo"
# TODO(petef): support authentication
# TODO(petef): check for errors
@mongodb = Mongo::Connection.new(@host, @port).db(@database)
db = Mongo::Connection.new(@host, @port).db(@database)
auth = true
if @username then
auth = db.authenticate(@username, @password) if @username
end
if not auth then
raise RuntimeError, "MongoDB authentication failure"
end
@mongodb = db
end # def register
public