Logstash动态变量不适用于rabbitmq插件

Logstash动态变量不适用于rabbitmq插件,logstash,Logstash,我正试图在Logstash(版本2.1.3)的帮助下处理Nginx访问日志 基于Nginx访问日志中发现的不同端点,我希望在不同的队列中发送数据,有时在不同的RabbitMQ服务器中发送数据 以下是我的日志存储配置: input { stdin {} } filter { grok { match => { "message" => "(?<status>.*?)!~~!(?<req_tm>.*?)!~~!(?<time>.*?)!~~

我正试图在Logstash(版本2.1.3)的帮助下处理Nginx访问日志

基于Nginx访问日志中发现的不同端点,我希望在不同的队列中发送数据,有时在不同的RabbitMQ服务器中发送数据

以下是我的日志存储配置:

input {
  stdin {}
}
filter {

grok {
   match => { "message" => "(?<status>.*?)!~~!(?<req_tm>.*?)!~~!(?<time>.*?)!~~!(?<req_method>.*?)!~~!(?<req_uri>.*)" }
   tag_on_failure => ["first_grok_failed"]
}
if "/endpoint1" in [req_uri] {
      mutate { add_field => { "[queue]" => "endpoint_one" } }
      mutate { add_field => { "[rmqshost]" => "10.10.10.1" } }
}
else if "/endpoint2" in [req_uri] {
    mutate { add_field => { "[queue]" => "endpoint_two" } }
    mutate { add_field => { "[rmqshost]" => "10.10.10.2" } }
}
else {
    mutate { add_field => { "[queue]" => "endpoint_other" } }
    mutate { add_field => { "[rmqshost]" => "10.10.10.3" } }
}
}
output {
   rabbitmq {
            exchange => "%{[queue]}_exchange"
            exchange_type => "direct"
            host => "%{[rmqshost]}"
            key => "%{[queue]}_key"
            password => "mypassword"
            user=>"myuser"
            vhost=>"myvhost"
            durable=>false

    }

   stdout { 
    codec  => rubydebug 
   }
}
我正在运行日志存储,如下所示:

/opt/logstash/bin/logstash -f /etc/logstash/conf.d/nginx-filter.conf
使用以下示例数据:

200!~~!0.004!~~!14/Apr/2017:05:15:27 +0000!~~!GET!~~!/endpoint1?key1=val1
200!~~!0.004!~~!14/Apr/2017:05:17:25 +0000!~~!GET!~~!/endpoint2?key1=val2

因为我今天偶然发现了这个问题,所以我也做了一些深入的研究。sprintf替换仅适用于rabbitmq输出插件中的键字段

@hare_info.exchange.publish(message, :routing_key => event.sprintf(@key), :properties => symbolize(@message_properties.merge(:persistent => @persistent)))
实际连接是使用建立的,它不提供通过变量替换主机的选项:

:hosts => @host

因此,目前不支持此操作,只有key字段可能被logstash变量替换。

谢谢!我也做了一些研究,发现只有路由密钥是动态的。
:hosts => @host