简体   繁体   中英

Logstash ruby filter and event fields

I am trying to capture IP address field from incoming logstash event and pass it on to a shell script to compare against a static black list. The issue is, I am able to print the IP addr using puts but not able to capture to pass it on to system() call in ruby filter. Here is my sample config.

I am using logstash 2.0

Sample input = {"name":"xyz", "source_ip":"8.8.8.8"}

input {

        stdin {
        codec => json
        }
}

filter {

        ruby {
        code => "
        # puts event['source_ip']  # This always works
        ip = event['source_ip']
        system('echo ${ip}')       # This echoes ${ip} instead of value !
        "
        }
}

I also tried ' echo #${ip} ' but it just prints 0 .

Instead of system('echo ${ip}') use below syntax to run shell commands:

puts `echo #{ip}`

Calling shell commands from Ruby

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM