【问题标题】:Using conditionals in Logstash pipeline configuration在 Logstash 管道配置中使用条件
【发布时间】:2019-11-20 07:45:30
【问题描述】:

我正在尝试在管道输出配置的上下文中使用 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】:

    您应该在 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}"
            }
        }
    }
    

    【讨论】:

    • 我的管道配置如下所示:bash-4.2$ cat /usr/share/logstash/pipeline/output_main output { if [device] ~= \.* { elasticsearch { hosts => ["es-host:9200"] index => "%{[device][0]}-%{+YYYY.ww}" } } else { elasticsearch { hosts => ["es-host:9200"] index => "%{[beat][name]}-%{+YYYY.ww}" } } 仍然出现错误:"Expected one of #, in, not , ==, !=, <=, >=, <, >, =~, !~, and, or, xor, nand, { at line 12, column 15 (byte 253) after output {\n if [device] "
    • 用您当前的完整配置更新您的问题,而不仅仅是输出部分,并检查您的括号是否关闭。
    猜你喜欢
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 2020-01-02
    相关资源
    最近更新 更多