2016-05-15 57 views
1

如何根據字段值在logstash中動態翻譯字典? 比如我目前的配置是:如何根據字段值在logstash中動態翻譯字典?

if [host] == "1.1.1.1" { 
    translate { 
     field => "[netflow][input_snmp]" 
     destination => "[netflow][interface_in]" 
     dictionary_path => "/etc/logstash/yaml/1.1.1.1.yml" 
    } 
} 
if [host] == "2.2.2.2" { 
      translate { 
        field => "[netflow][input_snmp]" 
        destination => "[netflow][interface_in]" 
        dictionary_path => "/etc/logstash/yaml/2.2.2.2.yml" 
      } 
} 

有沒有一種通用的方法來實現這一目標? Logstash版本2.2.4

感謝

回答

1

我想你可以使用它作爲:

translate { 
    field => "[netflow][input_snmp]" 
    destination => "[netflow][interface_in]" 
    dictionary_path => "/etc/logstash/yaml/%{host}.yml" 
} 

檢查:https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#sprintf

+1

看來我不能這樣使用它:{翻譯 #此設置必須爲路徑 #文件不存在或無法打開/etc/logstash/yaml/%{host}.yml dictionary_path =>「/etc/logstash/yaml/%{host}.yml」 – eladelad

+0

在這裏,字段佔位符似乎沒有在dictionary_path中工作。 @alpert任何其他想法? – sermolaev

+0

您是否嘗試使用「/etc/logstash/yaml/%{[host]}.yml」@sermolaev – alpert