在logstash过滤条件中使用ruby变量

时间:2017-06-29 08:38:59

标签: logstash logstash-configuration

我有以下logstash配置:

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"
  }
}

但是当我尝试使用此配置文件运行logstash时,我收到此错误:

[ERROR][logstash.agent] Cannot create pipeline {:reason=>"Expected one of #, ( at line 30, column 10 (byte 923) after filter {\n  # grok...

如何在if指令中使用ruby代码块(event ['keep_line'])中设置的变量?

1 个答案:

答案 0 :(得分:1)

如果Logstash中的条件过滤,则不能使用否定。尝试将布尔条件转换为正数。