I'm trying to save the logs to my local mongoDB with logstash. this is my configuration in logstash:
input {
tcp {
port => 5001
codec => "json_lines"
}
}
output {
file {
path => "/var/log/some.log"
}
mongodb {
id => "logstash-mongo"
collection => "logs"
database => "somelogs"
uri => "mongodb://my-user:my-password@127.0.0.1:27017/somelogs"
codec => "json"
}
stdout { codec => rubydebug }
}
For output to file its actually works, but not for output to mongoDB. I setup the mongoDB using authentication. I created both admin and basic user for read and write to the specific db. I tried to run logstash but its give me this:
2021-10-29T06:37:51,798][WARN ][logstash.outputs.mongodb ][main][logstash-mongo] Failed to send event to MongoDB, retrying in 3 seconds {:event=>#<LogStash::Event:0x2f0b40c8>, :except
ion=>#<Mongo::Auth::Unauthorized: User my-user is not authorized to access somelogs.>}
[2021-10-29T06:37:54,887][WARN ][logstash.outputs.mongodb ][main][logstash-mongo] Failed to send event to MongoDB, retrying in 3 seconds {:event=>#<LogStash::Event:0x2f0b40c8>, :except
ion=>#<Mongo::Error::OperationFailure: command insert requires authentication (13)>}
I'm using both user to access the mongoDB but its still give me this output. Any suggestion what I have to do with this issue? many thanks
NOTE: I've done install output plugins for mongodb
My mistake, the uri must be
uri => "mongodb://my-user:my-password@127.0.0.1:27017
instead of
uri => "mongodb://my-user:my-password@127.0.0.1:27017/somelogs
The logstash running well now