【问题标题】:Using Rsyslog sending to Loggly and scrub mongodb log data使用 Rsyslog 发送到 Loggly 并清理 mongodb 日志数据
【发布时间】:2021-06-08 15:03:10
【问题描述】:

我正在尝试通过 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"}}

【问题讨论】:

  • 我在您的示例日志中没有看到任何 9 位数字的字符串来匹配 re 模式。另外,我知道您需要先定义ruleset(),然后才能将其与input(ruleset=) 一起使用,但这可能只是用于旧版本。
  • @meuh 是的,示例中没有 9 位数字,所以我希望看到返回的完整字符串,但我什至没有看到。
  • @meuh - 这解决了这个问题。谢谢 - 我有什么办法可以投票或将您的答案作为答案?

标签: mongodb rsyslog loggly


【解决方案1】:

rulesets 用于对输入进行分区,以便只有一些规则适用于它们。似乎$!msg$.msg 之类的变量对于每个规则集都是本地的,因此将它们设置在规则集之外不会影响规则集中的操作中的值。文档并不清楚规则集中还需要什么,例如模板可能不需要。

【讨论】:

    【解决方案2】:

    您可以使用jq 从您的日志文件中提取或操作数据。

    注意,您也可以通过设置生成系​​统日志消息

    systemLog:
       destination: syslog
    

    那么您不必写入文件并再次读取它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-28
      • 2022-07-29
      • 1970-01-01
      • 2015-12-15
      • 2020-04-03
      • 2013-07-27
      • 2012-05-24
      • 2019-01-05
      相关资源
      最近更新 更多