Logstash Grok Filter - 解析自定义文件

Logstash Grok Filter - parsing custom file

我发现 logstash 不喜欢我的过滤器。有第二组眼睛关注它会很好。

首先 - 我的日志文件 - 包含以下条目,每个卷都有新行。

/vol/vol0/ 298844160 6916836 291927324 2%  /vol/vol0/

我的配置文件如下所示:

输入

file {
   type => "testing"
   path => "/opt/log_repo/ssh/netapp/*"
   tags => "netapp"
   start_position => "beginning"
   sincedb_path => "/dev/null"
}

过滤器

if [type] == "testing" {
   grok{
        match => [ "@message", "{UNIXPATH:volume}%{SPACE}%{INT:total}%{SPACE}%{INT:used}%{SPACE}%{INT:avail}%{SPACE}%{PROG:cap}%{SPACE}%{UNIXPATH:vols}"]
   }
}

输出

if [type] == "testing" {
     elasticsearch {
         action => "index"
         hosts => ["http://localhost:9200"]
         index => ["testing4-%{+YYYY.MM.dd}"]
     }
}

当我 运行 它告诉我它有一个错误的配置文件。如果我将过滤器更改为:

match => [ "@message", "{UNIXPATH:volume}" ]

它使用卷名称创建一个名为卷的新字段。我正在使用 space 组件,因为日志根本不一致。有些卷在可用 space 之间会有 4 space 秒,有些卷或多或少取决于卷名称和大小。

为了获得此配置,我利用了以下站点: https://grokdebug.herokuapp.com/discover?# http://grokconstructor.appspot.com/do/constructionstep

仍在为我所缺少的东西苦苦挣扎....任何帮助将不胜感激。

更新:在下面添加建议后,它仍然没有创建新字段。

_index      string              
message     string              
type    string              
tags    string              
path    string              
@timestamp      date                
@version    string              
host    string              
_source     _source             
_id     string              
_type   string              
_score  

您的模式与示例日志不匹配,原因非常简单和愚蠢 - 您在模式的开头缺少 %。如果您将添加它,那么它就像一个魅力:

所以完整的过滤器是:

if [type] == "testing" {
   grok{
        match => [ "@message", "%{UNIXPATH:volume}%{SPACE}%{INT:total}%{SPACE}%{INT:used}%{SPACE}%{INT:avail}%{SPACE}%{PROG:cap}%{SPACE}%{UNIXPATH:vols}"]
   }
}