Logstash输出部分如何区分文件和UDP?

huangapple go评论56阅读模式
英文:

How to differentiate file and udp in Logstash output section?

问题

I'm new to Elasticsearch and Logstash.

在Logstash配置文件中,如果我同时将“file”和“udp”作为输入的源,如何在输出中区分它们?

例如:

input {
file {
path => ["/sample/data.log"]
}
udp {
port => 9999
}
}

如何编写输出部分以区分它们,以便将它们保存到Elasticsearch的两个不同索引中?

英文:

I'm new to Elasticsearch and Logstash.

In the Logstash conf file, if I have both "file" and "udp" as the source of the input, how do I differentiate them in the output?

For example:

input {
  file {
       path => ["/sample/data.log"]
 }
  udp {
       port => 9999
 }
}

How do I write the output part to differentiate them so I can save them in two different indices of Elasticsearch?

答案1

得分: 1

You can simply tag each document coming in from each input

input {
  file {
    path => ["/sample/data.log"]
    tags => ["file"]
  }
  udp {
    port => 9999
    tags => ["udp"]
  }
}
output {
  if "file" in [tags] {
    elasticsearch {
      index => "file-index"
      ...
    }
  }
  else if "udp" in [tags] {
    elasticsearch {
      index => "udp-index"
      ...
    }
  }
}
英文:

You can simply tag each document coming in from each input

input {
  file {
       path => ["/sample/data.log"]
       tags => ["file"]
  }
  udp {
       port => 9999
       tags => ["udp"]
  }
}
output {
  if "file" in [tags] {
    elasticsearch {
      index => "file-index"
      ...
    }
  }
  else if "udp" in [tags] {
    elasticsearch {
      index => "udp-index"
      ...
    }
  }
}

huangapple
  • 本文由 发表于 2023年5月7日 22:43:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76194596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定