使用 HTTP POST 请求作为输入的 Logstash 的 Grok 模式

Grok pattern for Logstash using HTTP POST request as input

我正在使用 Logstash 处理我的日志并将它们存储到 Elastic Search。 我正在使用 http 作为我的 logstash 的输入插件。

我的 http post 请求是:

$http.post(url, {type: 'reference error', message: 'y is not defined'});

我想在 Elastic Search 中将类型和消息键存储为不同的字段。

目前所有 post 数据都存储为单个字段,例如:

"message":"{\"type\":\"ReferenceError\",\"message\":\"y is not defined\"}"

我认为这可以使用 grok 过滤器来完成,但我还没有找到方法。

非常感谢任何帮助。 谢谢

EDIT: As Alain mentioned it is the best way to use the json codec which can be set directly in your http input plugin. If that is not possible for some reason you can use the grok filter.

如果我理解正确的话,你的传入事件如下所示:

{"type": "reference error", "message": "y is not defined"}

那么相应的 grok 模式将如下所示:

{"type": %{QUOTEDSTRING:http_type}, "message": %{QUOTEDSTRING:http_message}}

在您的 logstash 配置中:

grok {
    match => [ "message", "{\"type\": %{QUOTEDSTRING:http_type}, \"message\": %{QUOTEDSTRING:http_message}}" ]
}

那么结果会有http_typehttp_message两个字段。

如果您使用 json codec,信息应该会自动拆分成字段。