Sample Header Ad - 728x90

logstash: Trying to extract substrings from path

1 vote
0 answers
1112 views
I'm trying to extract substrings from my path field in my logstash config. The 'path' field looks like this: /storage/logs/deployment/servers/hostname.example.com/server.log Inside a filter section I have this: ruby { code => "event.set('log_filename', event.get('path').split('/').last)" } This works fine. I get a new field called 'log_filename' However I'm also interested in the server name (hostname.example.com) So I tried this: ruby { code => "event.set('log_filename', event.get('path').split('/').[-1]) event.set('server_name', event.get('path').split('/').[-2])" } This does not work at all. I don't get any errors in my logstash log but no logstash data is seen. I'm after the filename and the field before it, which represents the host it came from. Is there something wrong with my syntax?
Asked by Aditya K (2260 rep)
Jul 7, 2017, 11:44 AM
Last activity: Jul 7, 2017, 11:47 AM