0

我正在尝试将 GELF 消息(通过 HTTP 客户端)发送到 Logstash。

logstash.conf 文件如下所示:

input {
  gelf {
    use_tcp => true
  }
}

output {
  elasticsearch { hosts => ["10.32.0.80:9200"] }
}

在 Grafana 中,日志显示如下: 在此处输入图像描述

如您所见,我得到了一个 _jsonparsefailure 标记,该标记也与 logstash 日志一起记录。

logstash 日志:

[INFO ] 2021-04-14 14:36:54.155 [Agent thread] agent - Pipelines running {:count=>1, 
:running_pipelines=>[:main], :non_running_pipelines=>[]}
[ERROR] 2021-04-14 14:51:12.025 [Ruby-0-Thread-39: :1] gelf - JSON parse failure. Falling back to 
plain-text {:error=>#<LogStash::Json::ParserError: Unrecognized token 'PUT': was expecting ('true', 
'false' or 'null')
at [Source: (byte[])"PUT / HTTP/1.1
Content-Type: application/json; charset=utf-8
Host: 10.32.8.133:12201
Content-Length: 371
Expect: 100-continue
Connection: Keep-Alive

{"version":"1.1","host":"postch-msm-order-statistics-test","short_message":"B2, total shipments: 
999","full_message":"National: 999\nInternational: 0\nCollect: 
0","level":6,"_event_type":"ShipmentDeclarationSent","_order_hash":"RGhktM2k6iH7n5MbxzzAsQ==","_product_type":"B2","_national_shipments_count":999,"_international_shipments_count":0,""[truncated 28 bytes]; line: 1, column: 5]>, :data=>"\"PUT / HTTP/1.1\\r\\nContent-Type: application/json; charset=utf-8\\r\\nHost: 10.32.8.133:12201\\r\\nContent-Length: 371\\r\\nExpect: 100-continue\\r\\nConnection: Keep-Alive\\r\\n\\r\\n{\\\"version\\\":\\\"1.1\\\",\\\"host\\\":\\\"postch-msm-order-statistics-test\\\",\\\"short_message\\\":\\\"B2, total shipments: 999\\\",\\\"full_message\\\":\\\"National: 999\\\\nInternational: 0\\\\nCollect: 0\\\",\\\"level\\\":6,\\\"_event_type\\\":\\\"ShipmentDeclarationSent\\\",\\\"_order_hash\\\":\\\"RGhktM2k6iH7n5MbxzzAsQ==\\\",\\\"_product_type\\\":\\\"B2\\\",\\\"_national_shipments_count\\\":999,\\\"_international_shipments_count\\\":0,\\\"_collect_shipments_count\\\":0}\""}

有谁知道我为什么会收到这个错误?我相信 Logstash Gelf Input 插件必须知道 HTTP 请求(以 gelf 消息作为正文)的样子。为什么我会收到此解析错误?我必须在不使用任何过滤器的情况下解决这个问题。有任何想法吗?

4

1 回答 1

0

Graylog 支持多种输入类型。它将接受基于UDP、TCP 或 HTTP 的GELF 。logstash gelf 输入不支持 HTTP 请求,仅支持 UDP 或 TCP 上的 NUL 分隔消息。您可以改用 HTTP 输入。如果内容类型为 application/json,则 JSON 将使用 json 编解码器自动解析。

输入重新映射了几个字段,并且可以选择从字段名称中去除下划线。您可以使用 ruby​​ 过滤器在管道中实现相同的更改。

于 2021-04-14T16:18:05.613 回答