rsyslog是强大的,但它的文档不是那么明确。 我无法弄清楚如何parsing日志文件,并以GELF格式直接将其路由到Graylog。
我已经find有关在rsyslog中输出gelf的文档,但我不知道如何继续。
到目前为止,它试图将下面的configuration文件放在/etc/rsyslog.d/01-access.conf但似乎没有工作…
template(name="gelf" type="list") { constant(value="{\"version\":\"1.1\",") constant(value="\"host\":\"") property(name="hostname") constant(value="\",\"short_message\":\"") property(name="msg" format="json") constant(value="\",\"timestamp\":\"") property(name="timegenerated" dateformat="unixtimestamp") constant(value="\",\"level\":\"") property(name="syslogseverity") constant(value="\"}") } input(type="imfile" File="/var/log/apache2/access.log" Tag="apache-access" ) if $programname == 'apache-access' then { action( type="omfwd" Target="GRAYLOG-IP" Port="12201" Protocol="tcp" template="gelf" ) stop }
由于Gelf的空字节消息定界符规范,您遇到此问题,因为通过tcp发送不与rsyslog工作。 从官方的rsyslog文档:( http://www.rsyslog.com/doc/v8-stable/tutorials/gelf_forwarding.html )“请注意,上面的情况只适用于UDP传输。当使用TCP时,Graylog期望Nullbyte作为消息分隔符,这在rsyslog中是不可能的。“ 你的例子应该通过udp工作。
一个忠告,我肯定会推荐检查rsyslog过滤规则,因为邮件处理将继续您的示例(检查波浪号字符)。