通过GELF TCP 12201端口发送回显消息给graylog2

我需要通过echo向graylog2服务器发送一条消息,以testing设备的%{@ type}是否正确,但是一旦我在GELF支持中做了回显,就没有到达我的graylog2服务器。 如果它重新启动graylog2,那么开始的消息到达graylog2服务器。

回声消息的示例:

echo '{"version": "1.1","host":"example.org","short_message":"A short message that helps you identify what is going on","full_message":"Backtrace here\n\nmore stuff","level":1,"_user_id":9001,"_some_info":"foo","_some_env_var":"bar"}' | nc -w 1 my.graylog.server 12201 

我究竟做错了什么? graylog – debugging模式不显示任何内容。 它甚至没有看到消息进来。

编辑:

Graylog2input设置为GELF TCP,并显示活动的连接,当我尝试回显时引发,但没有任何信息到达服务器。

看起来,GELF TCPinput在每个Gelf消息的末尾需要一个空字符。

所以你应该发送:

 echo -e '{"version": "1.1","host":"example.org","short_message":"Short message","full_message":"Backtrace here\n\nmore stuff","level":1,"_user_id":9001,"_some_info":"foo","_some_env_var":"bar"}\0' | nc -w 1 my.graylog.server 12201 

这个答案发现在讨论Graylog的问题 。

正如我试图validation一个Logstash实例正确听取GELFinput,我发现这个线程。

这是一个可以在Logstash + Gelf over UDP上运行的命令:

 echo '{"version": "1.1","host":"example.org","short_message":"A short message that helps you identify what is going on","full_message":"Backtrace here\n\nmore stuff","level":1,"_user_id":9001,"_some_info":"foo","_some_env_var":"bar"}' | gzip | nc -u -w 1 127.0.0.1 12201 

请注意:

  • 一个简单的echo就足够了,不需要-e
  • 该消息是gziped,否则你会得到这个错误: Could not find parser for header: [123, 34] 123,34 Could not find parser for header: [123, 34]在Logstash日志
  • netcat通过UDP发送