Reputation: 889
I have the following logstash config:
input { stdin { } }
output {
elasticsearch { hosts => ["localhost:9200"] }
stdout { codec => rubydebug }
}
filter {
ruby {
code => "
@@exists_pattern = ['foo', 'bar'].any?{ |pattern| event.get('message').include?(pattern) }
event.add('keep_line', @@exists_pattern)
"
}
if not [keep_line] { drop { } }
grok {
match => {
"message" => '%{IP:serverip} \[%{HTTPDATE:my_timestamp}\]'
}
}
date {
match => [ "my_timestamp", "dd/MMM/YYYY:HH:mm:ss Z"]
target => "@timestamp"
}
}
But when I try to run logstash with this config file I get this error:
[ERROR][logstash.agent] Cannot create pipeline {:reason=>"Expected one of #, ( at line 30, column 10 (byte 923) after filter {\n # grok...
How can I do to use the variable that was set in ruby code block (event['keep_line']) in an if instruction?
Upvotes: 2
Views: 1028
Reputation: 4114
You cannot use negation in if conditions in Logstash filter. Try to convert boolean condition to be positive.
Upvotes: 2