rsyslog:通过过滤系统日志将日志发送到不同的文件

rsyslog:通过过滤系统日志将日志发送到不同的文件

我有一个基于 CentOS 的 rsyslog 服务器,它具有以下设置,它从多个主机获取所有远程 NATing 事件。

$template TmplcpFW, "/var/log/%HOSTNAME%.log"
if ($hostname == ["CP1CGNAT","CP2CGNAT"]) then ?TmplcpFW
& ~

/var/log/CP1CGNAT 中的示例日志输出

<150>1 2018-12-20T16:07:00.482369+01:00 2018-12-20 15 - - - 06:59: CP1CGNAT_O_Poland{OR_NAT}[jservices-nat]: JSERVICES_NAT_RULE_MATCH: proto 6 (TCP) application: any, xe-1/0/1.1718:100.70.0.2:59794 -> 109.32.8.15:80, Match NAT rule-set: (null), rule: OR_NAT_Poland, term: t1
<150>1 2018-12-20T16:07:00.482369+01:00 2018-12-20 15 - - - 06:59: CP1CGNAT_O_France{OR_NAT}JSERVICES_SESSION_OPEN: application:none, xe-1/0/1.1718 100.70.0.2:59794 [55.93.69.53:26620] ->  109.32.8.15:80 (TCP) 
<150>1 2018-12-20T16:07:11.091313+01:00 2018-12-20 15 - - - 07:10: CP1CGNAT_O_UK{OR_NAT}JSERVICES_SESSION_CLOSE: application:none, xe-1/0/1.1718 100.70.0.2:59778 [55.93.69.60:40136] ->  109.32.8.15:80 (TCP) 

我已将 NAT 设备服务配置为前缀为“syslog host 10.10.10.10 log-prefix CP1CGNAT_O_Poland”

现在我想根据带有时间戳的前缀值将上述日志分离到不同的目录/文件中,例如 -

/Poland/Logs_Poland_2018-12-20, /France/Logs_France_2018-12-20, /UK/Logs_UK_2018-12-20

您能建议如何在 rsyslog 中实现这一目标吗?


从评论中获取的更新:

我使用了不同的日志前缀(在 NAT 设备中配置)作为过滤条件,并在模板中使用为(总共 10 个类似模板):

$template TmplcpFW_P, "/var/log/NIPFW/Poland/Poland_%HOSTNAME%_%$year%.%$month%.%$day%.log" 
if ($hostname == ["CP1CGNAT","CP2CGNAT"]) and $msg contains 'CP1CGNAT_O_Poland' then ?TmplcpFW_P 
$template TmplcpFW_F, "/var/log/NIPFW/France/France_%HOSTNAME%_%$year%.%$month%.%$day%.log" 
if ($hostname == ["CP1CGNAT","CP2CGNAT"]) and $msg contains 'CP1CGNAT_O_France' then ?TmplcpFW_F

现在我希望上述条件中的所有匹配日志都进入相应的目录/文件,并将剩余日志放入 /var/log/messages 中。

相关内容