Unable to start logstash using mongoDB config?

萝らか妹 提交于 2019-12-25 16:50:57

问题


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:


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.



来源:https://stackoverflow.com/questions/31652436/unable-to-start-logstash-using-mongodb-config

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!