我尝试在某些事件上从 rsyslog(使用 ommail 模块)发送电子邮件,但无论我做什么,邮件正文始终是空的。
我的配置文件说:
module(load="ommail")
template (name="mailBody" type="string" string="RSYSLOG Alert\\r\\nmsg='%msg%'")
template (name="mailSubject" type="string" string="lti problem on %hostname%")
if $syslogseverity <= 4 and $syslogfacility-text == 'local1' then {
action(type="ommail" server="localhost" port="25"
mailfrom="[email protected]"
mailto="[email protected]"
subject.template="mailSubject")
}
这是从以下示例中复制而来的https://www.rsyslog.com/doc/v8-stable/configuration/modules/ommail.html
邮件已发送,但正文为空。如何解决此问题?
答案1
尝试一下这个:
module(load="ommail")
template (name="mailBody" type="string" string="%msg%")
template (name="mailSubject" type="string" string="lti problem on %hostname%")
if $syslogseverity <= 4 and $syslogfacility-text == 'local1' then {
action(type="ommail" server="localhost" port="25"
mailfrom="[email protected]"
mailto="[email protected]"
subject.template="mailSubject"
body.enable="on"
template="mailBody")
}
查看mailBody
模板值%msg%
和参数body.enable="on"
和template="mailBody"
。
答案2
您必须在操作子句中专门设置模板(使用 template="mailBody")。示例中缺少此设置。您可能还需要 body.enable="on",尽管这应该是默认设置。
module(load="ommail")
template (name="mailBody" type="string" string="RSYSLOG Alert\\r\\nmsg='%msg%'")
template (name="mailSubject" type="string" string="lti problem on %hostname%")
if $syslogseverity <= 4 and $syslogfacility-text == 'local1' then {
action(type="ommail" server="localhost" port="25"
mailfrom="[email protected]"
mailto="[email protected]"
subject.template="mailSubject"
template="mailBody")
}