Logstash,为项目中的每个包添加索引

时间:2017-01-03 18:26:58

标签: logstash logstash-grok logstash-configuration

我有来自不同包的日志,

例如,

com.example.package1.subpackage1.MyClass
com.example.package1.subpackage2.MyClass
com.example.package2.subpackage1.MyClass  
com.example.package2.subpackage2.MyClass

我想为package1package2

创建索引

目前的logstash配置如下:

filter {
    if "package1" in [logger_name] {
      mutate {
        add_tag => "package1"
      }
    }

    if "package2" in [logger_name] {
      mutate {
        add_tag => "package2"
      }
    }
}

output {
    if "package1" in [tags] {
      elasticsearch {
        index => "package1"
      }
    }

    if "package2" in [tags] {
      elasticsearch {
        index => "package2"
      }
    }
}

但每次,当我添加新包时,我需要使用新配置重启logstash,是否可以创建更通用的配置?

1 个答案:

答案 0 :(得分:0)

使用grok {}过滤器将名称拉出到logstash字段中,然后您可以在output {}节中引用它。