【问题标题】:Send GELF messages via HTTP to Logstash通过 HTTP 向 Logstash 发送 GELF 消息
【发布时间】:2021-04-14 15:44:32
【问题描述】:

我正在尝试将 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 消息为正文)的样子。为什么我会收到此解析错误?我必须在不使用任何过滤器的情况下解决这个问题。有什么想法吗?

【问题讨论】:

    标签: http elasticsearch logstash logstash-configuration gelf


    【解决方案1】:

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

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

    【讨论】:

    • 真的吗?那么 Gelf Input Plugin 是如何使用的呢? Gelf 消息是如何传输到 logstash 的?
    • GELF 消息可以通过 UDP 或 TCP 发送,具体取决于 logstash 输入的配置方式。它不接受 HTTP。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 2017-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多