在Logstash管道配置中使用条件

问题描述 投票:0回答:1

我正在尝试在管道输出配置的上下文中使用Logstash条件。基于有效负载中device字段的存在,我想将事件转发到Elasticsearch中的适当索引名称:

output {
    elasticsearch {
        hosts => ["10.1.1.5:9200"]
        if [device] ~= \.* {
          index => "%{[device][0]}-%{+YYYY.ww}"
        } else {
          index => "%{[beat][name]}-%{+YYYY.ww}"
        }
    }
}

以上代码将失败,并在日志中显示以下mgs,指示语法错误:

...
"Expected one of #, => at line 14, column 12 (byte 326) after output {\n    elasticsearch {\n        hosts => [\"10.1.1.5:9200\"]\n        if "
...

有人可以请教吗?

elasticsearch logstash filebeat
1个回答
0
投票

您应该在elasticsearch输出之前而不是在内部使用conditional

output {
    if [device] ~= \.* {  
        elasticsearch {
            hosts => ["10.1.1.5:9200"]
            index => "%{[device][0]}-%{+YYYY.ww}"
        }
    } else {  
        elasticsearch {
            hosts => ["10.1.1.5:9200"]
            index => "%{[beat][name]}-%{+YYYY.ww}"
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.