2016-08-15 163 views
1

由于类似的问题已经重复,我仔细看过以前的答案,不幸的是它还没有解决我的问题。通过logstash进行日志分析,没有产生字段

通过下面提到的logstash的过滤配置,我期望在解析日志之后生成字段线程,日志级别和消息。

我试过这个过滤器https://grokdebug.herokuapp.com/和输出生成过滤器中提到的字段。

但是除了消息之外,在输出JSON/Kibana上没有显示的字段。解析时没有错误。

如果有人能指出这里的错误,会有所帮助。谢谢!

过滤配置

filter { 
    if [type] == "reporting" { 
    grok { 
     match => { "message" => "\[(?<timestamp>%{TIMESTAMP_ISO8601})\] - %{NOTSPACE:thread} - %{LOGLEVEL:loglevel} (?<logger>[A-Za-z0-9$_.]+) - %{GREEDYDATA:message}$"} 
    } 
    } 
} 

日志示例

[2016-08-15 09:44:36,858] - RServer - INFO transformation - [01] starting the process for day 2016-06-06 

生成JSON

{ 
    "_index": "filebeat-2016.08.15", 
    "_type": "log", 
    "_id": "xxx", 
    "_score": null, 
    "_source": { 
    "message": "[2016-08-15 09:44:36,858] - RServer - INFO transformation - [01] starting the process for day 2016-06-06", 
    "@version": "1", 
    "@timestamp": "2016-08-15T09:44:37.700Z", 
    "source": "/xxx/yyy/main.log", 
    "count": 1, 
    "fields": { 
     "application": "reporting", 
     "category": "main" 
    }, 
    "beat": { 
     "hostname": "xxx", 
     "name": "xxx" 
    }, 
    "offset": 5033597, 
    "type": "log", 
    "input_type": "log", 
    "host": "xxx", 
    "tags": [ 
     "beats_input_codec_plain_applied" 
    ] 
    }, 
    "fields": { 
    "@timestamp": [ 
     1471254277700 
    ] 
    }, 
    "sort": [ 
    1471254277700 
    ] 
} 
+1

它看起来不像你设置的类型变量,因此你的过滤器永远不会被调用。删除if,然后再试一次。 – pandaadb

+0

@pandaadb所以你的评论触发了一个想法来检查FileBeat的配置(因为Logstash中的if条件是有意的)。我发现其中一个字段'output_type'缺失。我添加了它,现在这些字段正在出现。谢谢你的帮助! – Srikanta

+0

没问题:)或者,你可以在你的输入中做类似type =>“reporting”的事情,这也可以设置 – pandaadb

回答

0

得益于来自@pandaadb的评论,我想到检查FileBeat的配置,并意识到一个字段“output_type”丢失。这意味着进入的日志没有被过滤,因为过滤器期待某种类型。

使用“output_type”,会添加一个关键字并由筛选器根据上述GROK表达式来解析日志。由于FileBeat的相同实例正在转发不同类别的日志,因此它将在转发器本身进行标记,而不是在Logstash的输入配置中进行标记。