I am working on some code to send a number of files from a series of folders to logstash to be filtered and then added to elasticsearch. I have some Ruby code that identifies the log file type and I then want to send it to logstash with the correct filter and let it handle the file. I am struggling to figure out the best way to do this.
Should I use the logstash input filter? Or perhaps filebeat? I do not see any documentation that would allow me to send files from a Ruby script to logstash. Any suggestions of examples would be very welcome.
I use Ruby to do some additional work as well so the file will either go to logstash or somewhere else in theory. I have the following code to send data to logstash. Would filebeat work the same?
host = 'localhost'
port = 5400
size = 1024 * 1024 * 10
TCPSocket.open(host, port) do |socket|
File.open(curPath, 'rb') do |file|
while chunk = file.read(size)
socket.write(chunk)
end
end
end
Thanks. I have a socket in Ruby. Ruby is doing some things, one of which is to establish the different log formats. The next steps are to send this to logstash, however different formats of logs require different conf files and filters.
My challenge is how to manage this. I understand in the conf I can run if else statements based on a path for example but because I am sending raw file data via TCP I cannot do that. I guess what I need is a way to send a message with the log file data and say 'IIS, DATABLOCK' and then 'IIS' message is sent to the conf file and used in the filter.
Just send the raw message wrapped in JSON and use the json codec on the receiving end. Then you can supply any tags or fields to Logstash in addition to the message itself.
But I still don't understand why you can't do the log detection in Logstash. That would make things so much easier.
Right now I have the different formats going on different ports and a series of statements in the config file. Perhaps a bad way of doing it.
In response to your questions - I am very new to this so do not know how I would wrap the message in JSON. Nor do I know how to use logstash for format detection.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.