【问题标题】:Logstash: 1 input & multiple output filesLogstash:1个输入和多个输出文件
【发布时间】:2021-09-06 13:02:19
【问题描述】:

我们有一个正在运行的软件,它通过 Apache Kafka 发布信息。由于客户要求,所有信息都被收集并写入 txt 和 csv 文件。到目前为止,客户只有一个项目,但他们现在想添加第二个项目,并希望将信息过滤到 2 个单独的文件中。事实上,他们希望像现在一样继续将 1 个项目推送到 txt 文件中,但将第二个项目的信息直接推送到数据库中。这可能吗?谁能指点我在哪里可以找到更多信息?

input {
  kafka {
    bootstrap_servers => ["10.1.83.132:9192"]
    group_id => ["my_plugin_id"]
    topics => "survey-result"
    codec => json
    security_protocol => ["SSL"]
    ssl_truststore_location => ["/home/bitnami/kafka.client.truststore.jks"]
    ssl_truststore_password => ["changeit"]
    ssl_endpoint_identification_algorithm => [""]
    auto_offset_reset => "earliest"
    }
}
output {
   elasticsearch {
      hosts => ["127.0.0.1:9200"]
      index => "survey-result"
      workers => 1
      codec => json
    }
   file {
        path => "/sadata/saexport-%{+YYYY-MM-dd}.txt"
        # codec => line { format => "custom format: %{message}"}
 }

   csv {
        # elastic field name
        fields => ["data.integrationName", "data.contextData.UCID", "data.contextData.ANI", "data.reason.reason", "data.status"]
        # separator => ","
        # This is path where we store output.   
        path => "/sadata/saexport.%{+YYYY-MM-dd-hh}.csv"
  }
}

谢谢

【问题讨论】:

    标签: logstash logstash-configuration


    【解决方案1】:

    是的,这是可能的,您需要在输出中使用条件来根据一个或多个字段将消息定向到正确的目的地。

    例如:

    output {
        if [fieldName] == "stringA" {
            output for this type of message
        }
        if [fieldName] == "stringB" {
            output for this type of message
        }
        if [fieldName] == "stringN" {
            output for this type of message
        }
    }
    

    您将需要一个字段进行过滤,此字段可以出现在文档中,或者如果您要使用多个输入,则可以使用common options 中的common options 中的common options 选项添加它所有输入。

    这个part of the documentation 有一些关于使用条件的例子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-16
      • 2019-09-09
      • 2016-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多