如何在logstash中删除空行

Vad*_*imo 8 logstash logstash-grok

在我的logstash日志中,我有时空行或只有空格的行.

要删除空行,我创建了一个dropemptyline过滤器文件

# drop empty lines
filter {
    if [message] =~ /^\s*$/ {
        drop { }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是空行过滤器没有按预期工作,主要是因为这个特定的过滤器在链中的其他过滤器之后有过滤器.

00_input.conf
05_syslogfilter.conf
06_dropemptylines.conf
07_classifier.conf
Run Code Online (Sandbox Code Playgroud)

所以我认为我的特定过滤器可以工作,如果它是唯一的,但不是.

2015-02-11 15:02:12.347  WARN 1 --- [tp1812226644-23] o.eclipse.jetty.servlet.ServletHandler   : 

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]
Run Code Online (Sandbox Code Playgroud)

我的问题是如何退出所有过滤器并直接输出?

Suf*_*ori 2

您可以使用过滤器完全忽略空行grok

%{GREEDYDATA:1st}(\n{1,})%{GREEDYDATA:2nd}
Run Code Online (Sandbox Code Playgroud)

它将生成,

{
  "1st": [
    [
      "2015-02-11 15:02:12.347  WARN 1 --- [tp1812226644-23] o.eclipse.jetty.servlet.ServletHandler   : "
    ]
  ],
  "2nd": [
    [
      "org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]"
    ]
  ]
}
Run Code Online (Sandbox Code Playgroud)

或者更优雅的方式,

(?m)%{GREEDYDATA:log}
Run Code Online (Sandbox Code Playgroud)

输出:

{
  "log": [
    [
      "2015-02-11 15:02:12.347  WARN 1 --- [tp1812226644-23] o.eclipse.jetty.servlet.ServletHandler   : \n\n\n\norg.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongo:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.UnknownHostException: mongo: unknown error}}]"
    ]
  ]
}
Run Code Online (Sandbox Code Playgroud)