使用grok分割邮件

时间:2018-09-17 18:08:48

标签: elasticsearch logstash logstash-grok filebeat

我的日志格式为:

2018-09-17 15:24:34;Count of files in error folder in;C:\Scripts\FOLDER\SUBFOLDER\error;1

我想在单独的字段中放入文件夹的路径以及后面的数字。 像

dirTEST=C:\Scripts\FOLDER\SUBFOLDER\
count.of.error.filesTEST=1

dir=C:\Scripts\FOLDER\SUBFOLDER\
count.of.error.files=1

我在logstash配置中使用此grok模式:

if  "TestLogs" in [tags] {
    grok{
    match => { "message" => "%{DATE:date_in_log}%{SPACE}%{TIME:time.in.log};%{DATA:message.text.log};%{WINPATH:dir};%{INT:count.of.error.files}" }
    add_field => { "dirTEST" => "%{dir}" } 
    add_field => { "count.of.error.filesTEST" => "%{count.of.error.files}" }
    }

}

logstash日志中没有错误。

但是在Kibana中,我得到了没有新字段的常规日志。 enter image description here

1 个答案:

答案 0 :(得分:0)

这里有几点注意事项。首先,必须说解决方案似乎正在按照您的期望进行操作,所以可能的问题是您的索引模式尚未使用新字段进行更新。为此,您可以在Kibana中转到管理-> Kibana->索引模式,然后刷新右上角的字段列表(在“删除索引模式”按钮旁边)。

第二,您必须考虑到使用点分隔术语会使结构化数据看起来像这样:

{
  "date_in_log": "18-09-17",
  "count": {
    "of": {
      "error": {
        "files": "1"
      }
    }
  },
  "time": {
    "in": {
     "log": "15:24:34"
    }
  },
  "message": {
    "text": {
      "log": "Count of files in error folder in"
    }
  },
  "dir": "C:\\Scripts\\FOLDER\\SUBFOLDER\\error"
}

我不知道这是否是您要如何表示数据的方式,但是也许您应该考虑使用其他解决方案来更改grok模式中字段的命名。