使用 man ascii 来查看 ASCII 表。

一个input的数据如何通过判断输出到多个output

Logstash | 作者 elastic_daniel | 发布于2021年07月13日 | 阅读数:1305

nginx的access log和error log收集到了一个kafka的topic中,在logstash配置中如何将这个input的的数据 通过判断每条数据的内容而写到不同的文件当中呢?

目前我的配置:
input {
    kafka {
       type => "test1"
       group_id => "test1"
       client_id => "XXX"
       bootstrap_servers => "127.0.0.1:9300"
       security_protocol => "SASL_PLAINTEXT"
       sasl_mechanism => "PLAIN"
       jaas_path => "/data/www/kafka-jaas.conf"
       topics => ["test1"]
       codec => plain {}
    }
}

output {
if ([type] == "test1") {
file {
      path => "/data/www/applog/google.com/applog.log"
      codec => line {
         format => "%{message}"
      }
  }
 }
}
已邀请:

elastic_daniel - 小菜鸟

赞同来自: bossLeon

这个问题我解决了,在filter的时候先用正则表达式过滤下符合条件的数据,给这个数据打个tag,在输出的时候先判断下input的type然后再判断tag 就解决了
 
input {
  kafka {
    type              => "aaa"
    group_id          => "aaa"
    client_id         => "logstash_110_aaa"
    bootstrap_servers => "xxx:9110"
    security_protocol => "SASL_PLAINTEXT"
    sasl_mechanism    => "PLAIN"
    jaas_path         => "/data/workspace//kafka-jaas.conf"
    topics            => ["aaa"]
    codec             => plain {}
  }
}

filter {
  grok {
    match => { "message" => "这里面是你的正则,比如过滤包含new这个单词" }
    add_tag => [ "new" ]
    tag_on_failure => [] # prevent default _grokparsefailure tag on real records
  }

  grok {
    match => { "message" => "这里面是你的正则,比如过滤包含show这个单词" }
    add_tag => [ "show" ]
    tag_on_failure => [] # prevent default _grokparsefailure tag on real records
  }
}

output {
  if ([type] == "aaa" and "new" in [tags]) {
    file {
      path => "/data/www/applog/new.log"
      codec => line {
          format => "%{message}"
      }
    }
  }
  if ([type] == "aaa" and "show" in [tags]) {
    file {
      path => "/data/www/applog/show.log"
      codec => line {
          format => "%{message}"
      }
    }
  }

}

tongchuan1992 - 学无止境、学以致用

赞同来自:

可以在filter插件中进行关键字匹配,增加新的字段,在output中对这个字段进行区分。

要回复问题请先登录注册