在这种使用情况下,如何在配置文件中使用正则表达式? [英] How to use regex for config files in this use case?

查看:119
本文介绍了在这种使用情况下,如何在配置文件中使用正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LogStash,该工具接受来自日志文件的数据,该日志文件具有不同类型的日志.

I am using LogStash which accepts data from a log file, which has different types of logs.

我尝试过:

filter {
  grok {
    match => { "message" => "%{WORD:tag} %{WORD:message} %{WORD:value}
  }
}        

但这是行不通的.

推荐答案

我正在使用grok过滤器来检查日志行是否为一种格式.

I am using the grok filter to check if the log line is of one format.

如果grok过滤器无法解析日志行(例如json行),则_grokparsefailure将添加到标签中.然后,您可以使用此标记来区分这两种日志类型.

If the grok filter cannot parse the log line (such as with the json lines), _grokparsefailure will be added to the tags. You can then use this tag to differentiate between the two log type.

filter { 
    grok {
        match => {
        "message"=> 
            "tag: %{GREEDYDATA:tag} message: %{GREEDYDATA:message} value: %{WORD:value}"
        }
    }

    if "_grokparsefailure" in [tags] {
        json {
            source => message
        }
    }
}

要测试您的grok模式, Grok构造器是一个很好的工具.

To test your grok pattern, Grok Constructor is a good tool.

这篇关于在这种使用情况下,如何在配置文件中使用正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆