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


20

我需要通过echo向graylog2服务器发送一条消息,以测试设施的%{@ type}是否正确,但是一旦执行echo操作,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 --debug模式不显示任何内容。它甚至看不到该消息。

编辑:

Graylog2输入是为GELF TCP设置的,并显示活动的连接,当我尝试回显时,它会升高,但消息未到达任何服务器。


1
此命令对我有用。唯一的区别是我在graylog上使用UDP端口。因此,我将-u参数添加到nc。
阿姆拉2014年

Answers:


29

在每个Gelf消息的末尾,似乎GELF TCP输入需要一个空字符。

因此,您应该发送:

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问题讨论中找到了这个答案。


12
添加-u参数以nc使用UDP
rsilva4

7

当我试图验证Logstash实例是否正确侦听GELF输入时,我发现了该线程。

这是一条适用于UDP的Logstash + Gelf的命令:

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
  • 邮件已压缩,否则您将Could not find parser for header: [123, 34]在Logstash日志中收到此错误:
  • netcat通过UDP发送
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.