Unable to start logstash using mongoDB config?

2019-09-11 22:44发布

I am using logstash-1.5.2 with mongodb 3.0.4. and I am trying to start the logstash with below configuration which is not working.


input{
    stdin{
    }
}

output {
  mongodb {
    database => "logdb"    
    collection => "plain" 
    uri => "mongodb://localhost:27017" 
  } }

I am facing below errror :

./logstash -f conf/mongo.conf

The error reported is: uninitialized constant Mongo::URIParser

Please help.

1条回答
等我变得足够好
2楼-- · 2019-09-11 23:22

The problem is caused by a bug in the latest version of logstash-output-mongodb. Please see the issue reported on github. It can be fixed by changing a few lines inside the mongodb plugin. (Please be careful, as this is a hacky solution which neither supports authentication nor remote servers.)

Change the lines of your mongo.rb file as mentioned here. (path should be something like /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-mongodb-0.1.4/lib/logstash/outputs/mongodb.rb You can find the exact path in your error message.)

Replace:

    uriParsed=Mongo::URIParser.new(@uri)
    conn = uriParsed.connection({})
    if uriParsed.auths.length > 0
      uriParsed.auths.each do |auth|
        if !auth['db_name'].nil?
          conn.add_auth(auth['db_name'], auth['username'], auth['password'], nil)
        end 
      end
      conn.apply_saved_authentication()
    end
    @db = conn.db(@database)

by:

    client = Mongo::Client.new([ '127.0.0.1:27017' ])
    @db = client.use(@database)

And replace:

@db.collection(event.sprintf(@collection)).insert(document)

by:

@db.database.collection(event.sprintf(@collection)).insert_one(document)

I had this issue myself in several logstash setups. Changing the lines did the trick for me everytime.

查看更多
登录 后发表回答