mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
add mongodb authentication
This commit is contained in:
parent
c48efe849c
commit
30c631a9f1
1 changed files with 12 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue