我正在尝试通过 rsyslog 使用来自 mongodb 4.4.2 的数据向 loggly 发送信息。但是,我无法以可以操纵它并清除某些信息的方式获取数据。当我按照 Loggly 站点上的指南进行操作时,它适用于非 mongodb 信息。如果我将 %$!msg% 保留为 %msg% 我会得到 mongodb 数据,但我无法操作它。
用于读取 mongo 日志的配置文件
module(load="imfile")
#RsyslogGnuTLS
$DefaultNetstreamDriverCAFile /etc/ssl/certs/ca-bundle.crt
# Input for FILE1
input(type="imfile" tag="mongo_lou_qa" ruleset="filelog" file="/var/log/mongodb/mongod.log") #wildcard is allowed at file level only
$template LogglyFormat,"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [token@41058 tag=\"tag1\" tag=\"tag2\" ] %$!msg%"
set $!msg = $msg;
if re_match($!msg,'([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])')
then
{
set $!ext = re_extract($!msg,'([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9])',0,1,"");
set $!msg= replace($!msg, $!ext, "xxxxxxxxx");
}
ruleset(name="filelog"){
action(type="omfwd" protocol="tcp" target="logs-01.loggly.com" port="6514" template="LogglyFormat" StreamDriver="gtls" StreamDriverMode="1" StreamDriverAuthMode="x509/name" StreamDriverPermittedPeers="*.loggly.com")
}
MongoDB示例日志
{"t":{"$date":"2021-01-01T00:00:00.000-00:00"},"s":"I", "c":"ACCESS", "id":20000, "ctx":"conn79","msg":"Successful authentication","attr":{"mechanism":"ABC","principalName":"__system","authenticationDatabase":"local","client":"0.0.0.0:00000"}}