Linux rsyslog 7搜索和替换邮件内容
在rsyslog中,我试图在日志消息中搜索某个关键字并替换为另一个关键字,但似乎遇到了问题。环顾四周,发现很少有这样的例子,但无法找出我做错了什么 我在myrsyslog.conf文件中有以下内容Linux rsyslog 7搜索和替换邮件内容,linux,unix,centos,rsyslog,Linux,Unix,Centos,Rsyslog,在rsyslog中,我试图在日志消息中搜索某个关键字并替换为另一个关键字,但似乎遇到了问题。环顾四周,发现很少有这样的例子,但无法找出我做错了什么 我在myrsyslog.conf文件中有以下内容 template(name="logline" type="string" string="%timegenerated% %HOSTNAME% %syslogtag% %$!msg%\n") if re_match($msg,'APP_MAJOR_ALERT$') then { set $
template(name="logline" type="string" string="%timegenerated% %HOSTNAME% %syslogtag% %$!msg%\n")
if re_match($msg,'APP_MAJOR_ALERT$')
then {
set $!msg = replace($msg, "APP_MAJOR_ALERT", "APP_MINOR_ALERT");
} else {
set $!msg = $msg;
}
action(type="omfile" file="/tmp/logfile" template="logline")
现在,这与其他浮动的示例类似,我使用re_match搜索以搜索关键字(APP_MAJOR_ALERT)结尾的行,如果匹配,我将用MINOR替换MAJOR。else部分只按原样打印消息,似乎工作正常
但是,在匹配的情况下,我看到日志只是将“0”打印为消息。浏览rsyslog(版本7.4.10)文档表明replace函数应该返回修改后的字符串,但在我的例子中,它返回一个“0”
提供的测试输入是
logger "ERROR o.s.c.c.d.h.DiscoveryClientHealthIndicator - Error com.ecwid.consul.v1.OperationException: OperationException(statusCode=500, statusMessage='Internal Server Error', statusContent='rpc error: rpc error: No cluster leader' svc_APP_GROUP,id_APP_NAME,APP_MAJOR_ALERT"
我想不出我错在哪里。也许是一个愚蠢的错误,但却无法发现。很少有人会在这里帮忙。可能是发布此信息的更好地方。也添加到Unix和Linux,希望找到答案。您不是缺少了一个
集
,如集$!msg=replace…
?不知何故,我的复制粘贴中缺少了这些内容。检查了我的配置,它为两个分配都设置了“set$!msg”。更正了我的问题。好的,查看rsyslog 7()的文档表明,替换函数当时不可用。因此,我可能必须找到另一种方法,因为我的CentOs与rsyslog 8不兼容。
logger "ERROR o.s.c.c.d.h.DiscoveryClientHealthIndicator - Error com.ecwid.consul.v1.OperationException: OperationException(statusCode=500, statusMessage='Internal Server Error', statusContent='rpc error: rpc error: No cluster leader' svc_APP_GROUP,id_APP_NAME,APP_MAJOR_ALERT"