0

我試圖用我的logstash配置中的另一個IP 10.100.240.199替換10.100.251.98,我試過使用mutate函數的過濾器,但是我無法獲取語法wrtielogstash mutate替換輸出中的字段值

Sep 25 15:50:57 10.100.251.98 mail_logs: Info: New SMTP DCID 13417989 interface 172.30.75.10 address 172.30.75.12 port 25 
Sep 25 15:50:57 10.100.251.98 local_mail_logs: Info: New SMTP DCID 13417989 interface 172.30.75.10 address 172.30.75.12 port 25 
Sep 25 15:51:04 10.100.251.98 cli_logs: Info: PID 35559: User smaduser login from 10.217.3.22 on 172.30.75.10 
Sep 25 15:51:22 10.100.251.98 cli_logs: Info: PID 35596: User smaduser login from 10.217.3.22 on 172.30.75.10 

這裏是我的代碼:

input { file { path => "/data/collected" } } 

filter { 
    if [type] == "syslog" { 
     mutate { 
     replace => [ "@source_host", "10.100.251.99" ] 
     } 
    } 
} 

output { 

    syslog { 
     facility => "kernel" 
     host => "10.100.250.199" 
     port => 514 
    } 
} 

回答

1

我注意到關於你的配置幾件事情。首先,你沒有任何日誌解析。如果它不存在,您將無法替換該字段。爲此,您可以在輸入模塊中使用codec或使用grok filter。我添加了一個簡單的grok過濾器。

您還檢查if [type] == "syslog"。你從來沒有設置類型,所以檢查總是失敗。如果你想設置一個類型,你可以在你的輸入塊中做到這一點input { file { path => "/data/collected" type => "syslog} }

這裏是我用於測試grok模式和替換IP的示例配置。

input { tcp { port => 5544 } } 

filter { 
    grok { match => { "message" => "%{CISCOTIMESTAMP:log_time} %{IP:@source_host} %{DATA:log_type}: %{DATA:log_level}: %{GREEDYDATA:log_message}" } } 
    mutate { 
     replace => [ "@source_host", "10.100.251.199" ] 
    } 
} 

output { 
    stdout { codec => rubydebug } 
} 

其輸出這樣的:

{ 
     "message" => "Sep 25 15:50:57 10.100.251.98 mail_logs: Info: New SMTP DCID 13417989 interface 172.30.75.10 address 172.30.75.12 port 25", 
     "@version" => "1", 
     "@timestamp" => "2016-09-25T14:03:20.332Z", 
      "host" => "0:0:0:0:0:0:0:1", 
      "port" => 52175, 
     "log_time" => "Sep 25 15:50:57", 
    "@source_host" => "10.100.251.199", 
     "log_type" => "mail_logs", 
     "log_level" => "Info", 
    "log_message" => "New SMTP DCID 13417989 interface 172.30.75.10 address 172.30.75.12 port 25" 
}