Run Python script continuously from Logstash

Hi Team,

My requirement is to run python script in background from logstash, and the output I need to take as event in logstash how to achieve that.

Note: I am using exec input plugins, which eventually is not sending data until script exits, also it is running in interval.

let me know if you need any further detail to analyze my issue.

By running in background you mean let it running or execute the script in some scheduled interval?

The exec input executes a command in the scheduled interval and populates the field message with the output of the command.

If you need to make your python script running constantly, like a service, then I'm not sure you can do that from logstash.

I am running python script which is capturing snmptrap and printing the data in console whenever there is trap. But while running the script from logstash manually I can check python script running in background, it is not printing the data. Or to be more precise data is displaying only after closing the logstash process (which I am running manually)
I used exec and pipe input plugin, nothing worked. Please help me here.

So you need your script to keep running, isn't just something that you run and it prints an output and exit. As I said, I don't think you can use the exec input for scripts like that.

The exec input is for things that you run, execute some logic and prints an output, not for long running scripts that periodically print stuff, you will only get the script output after it stopped running, this is the expected behavior of the exec input.

If you want to use this python script you will need to change it and make it output to a file or to a port and configure your logstash to read from the file or listen on the port.

Thanks @leandrojmp for your suggestion. I am using pipe input plugins to long run python script, and also http input plugins to open a new port on local. Further python script is posting all the incoming event to that port (modified the print section in the python script itself)