elasticsearch - 要在Logstash中解析的多个模式

标签 elasticsearch logstash elastic-stack logstash-grok

我的日志文件具有多个模式,包括JSON格式的日志。我想解析grok插件中的多个模式,但它似乎不起作用。

'filter {grok {  break_on_match => false 
match =>[ "message", "%{TIMESTAMP_ISO8601:LogDate} %{LOGLEVEL:loglevel} (?<threadName>[^:]+):%{NUMBER:ThreadID} - %{GREEDYDATA:Line}",
           "message","%{TIMESTAMP_ISO8601:LogDate} %{LOGLEVEL:loglevel} (?<threadName>[^:]+):%{NUMBER:ThreadID} - %{IP:Clicnet} - - %{GREEDYDATA:Line}"]}
           json {source => "Line"}mutate{remove_field => [ "Line","ThreadID" ]}}'

即使成功解析JSON字符串的行,也有grokparsefailure标记。

2017-01-27 11:54:48 INFO PropertiesReader:33-{“timestamp”:1485518878968,“h”:“2972​​68184dde”,“l”:“INFO”,“cN”:“org.com.logstash。演示”,“mN”:“loadProperties”,“m”:“从/ var / tmp / conf加载属性文件”}
{
       "message" => "2017-01-27 11:54:48 INFO PropertiesReader:33 - {\"timestamp\":1485518878968,\"h\":\"297268184dde\", \"l\":\"INFO\", \"cN\":\"org.com.logstash.demo\", \"mN\":\"loadProperties\", \"m\":\"load property file from /var/tmp/conf\"}",
      "@version" => "1",
    "@timestamp" => "2017-03-20T17:19:16.316Z",
          "type" => "stdin",
          "host" => "ef3b82",
       "LogDate" => "2017-01-27 11:54:48",
      "loglevel" => "INFO",
    "threadName" => "PropertiesReader",
          "tags" => [
        [0] "_grokparsefailure"
    ],
     "timestamp" => 1485518878968,
             "h" => "297268184dde",
             "l" => "INFO",
            "cN" => "org.com.logstash.demo",
            "mN" => "loadProperties",
             "m" => "load property file from /var/tmp/conf"
}

没有JSON的第二行完全失败

2017-01-20 15:46:16 INFO RequestLog:60-10.252.134.34--[20 / Jan / 2017:15:46:16 +0000]“OPTIONS //127.0.0.0:8080/ HTTP / 1.1” 404237 1
Error parsing json {:source=>"Line", :raw=>["10.252.134.34 - - [20/Jan/2017:15:46:16 +0000] \"OPTIONS //127.0.0.0:8080/ HTTP/1.1\" 404 237  1", "[20/Jan/2017:15:46:16 +0000] \"OPTIONS //127.0.0.0:8080/ HTTP/1.1\" 404 237  1"], :exception=>java.lang.ClassCastException: org.jruby.RubyArray cannot be cast to org.jruby.RubyIO, :level=>:warn}
{
       "message" => "2017-01-20 15:46:16 INFO  RequestLog:60 - 10.252.134.34 - - [20/Jan/2017:15:46:16 +0000] \"OPTIONS //127.0.0.0:8080/ HTTP/1.1\" 404 237  1",
      "@version" => "1",
    "@timestamp" => "2017-03-20T17:19:51.175Z",
          "type" => "stdin",
          "host" => "ef3b82",
       "LogDate" => [
        [0] "2017-01-20 15:46:16",
        [1] "2017-01-20 15:46:16"
    ],
      "loglevel" => [
        [0] "INFO",
        [1] "INFO"
    ],
    "threadName" => [
        [0] " RequestLog",
        [1] " RequestLog"
    ],
       "Clicnet" => "10.252.134.34",
          "tags" => [
        [0] "_jsonparsefailure"
    ]
}

最佳答案

花了5个小时后,我设法找到了解决方案。在以下模式下使用,该模式成功解析了两条日志行

/opt/logstash/bin/logstash -e 'filter {grok  { match =>{ "message" =>["%{TIMESTAMP_ISO8601:LogDate} %{LOGLEVEL:loglevel} (?<threadName>[^:]+):%{NUMBER:ThreadName} - %{IP:Client} - - %{GREEDYDATA:LogMessage}", "%{TIMESTAMP_ISO8601:LogDate} %{LOGLEVEL:loglevel} (?<threadName>[^:]+):%{NUMBER:ThreadID} - %{GREEDYDATA:Line}"]}}  json {source => "Line"} mutate{remove_field => [ "Line","ThreadID" ]}}'

关于elasticsearch - 要在Logstash中解析的多个模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42909708/

相关文章:

python - Elasticsearch 没有给出准确的结果python

java - Elasticsearch 将多个字段与 AND 运算符匹配不起作用

docker - 在docker-compose期间,Kibana数据已丢失

java - Spark submit --files 无法将信任库文件复制到 google dataproc 中的工作节点

amazon-ec2 - Logstash 架构决策

linux - Supervisorctl 无法启动 Logstash

javascript - Delete By Query API 以 curl 方式工作,但不在 Node-Red 中

java - ElasticSearch - RestHighLevelClient - 等待 [30000] 毫秒后监听器超时

elasticsearch - Kibana仪表板显示了空的可视化,但可视化本身有效

elasticsearch - 如何限制 Elasticsearch 的结果