Regex rsyslog模板-正则表达式中的分析失败
我正在尝试在rsyslog服务器中构造来自我的D-Link DAP-2310的日志。它有一个非标准的日志格式,我的想法是用rsyslog模板中的regex来解决这个问题。当我用rsyslogd-N1解析rsyslog.conf时,结果非常令人沮丧 消息数据项看起来像Regex rsyslog模板-正则表达式中的分析失败,regex,rsyslog,Regex,Rsyslog,我正在尝试在rsyslog服务器中构造来自我的D-Link DAP-2310的日志。它有一个非标准的日志格式,我的想法是用rsyslog模板中的regex来解决这个问题。当我用rsyslogd-N1解析rsyslog.conf时,结果非常令人沮丧 消息数据项看起来像AA:BB:CC:DD:EE][app name]日志消息 第一部分是mac地址,第一部分“[00:”放在另一个数据项中,不要问为什么。第二部分“[app name]”是发送消息的应用程序/实例。最后一部分“log message”是
AA:BB:CC:DD:EE][app name]日志消息
第一部分是mac地址,第一部分“[00:”放在另一个数据项中,不要问为什么。第二部分“[app name]”是发送消息的应用程序/实例。最后一部分“log message”是记录的操作
有趣的部分是i)应用程序名称和ii)日志消息
我已经在验证了下面的正则表达式,它们的工作方式都很有魅力
template(name=”AP_tmpl” type=”list”) {
property(name=”timestamp”)
constant(value=” “)
property(name=”hostname”)
constant(value=” “)
property(name=”msg”
regex.type=”ERE”
regex.submatch=”1”
regex.expression=”\[(.+)\]--end”
regex.nomatchmode=”BLANK”
)
constant(value=” “)
property(name=”msg”
regex.type=”ERE”
regex.submatch=”1”
regex.expression=”\[.+\](.+)$--end”
regex.nomatchmode=”BLANK”
)
constant(value=”\n“)
}
当我解析conf文件时,它会抱怨转义字符
tobias@ubuntutest:~$ sudo rsyslogd -N1
rsyslogd: version 7.4.4, config validation run (level 1), master config /etc/rsyslog.conf
rsyslogd: error during parsing file /etc/rsyslog.d/41-AP.conf, on or before line 20: invalid character '"' in object definition - is there an invalid escape sequence somewhere? [try http://www.rsyslog.com/e/2207 ]
rsyslogd: error during parsing file /etc/rsyslog.d/41-AP.conf, on or before line 20: invalid character '\' in object definition - is there an invalid escape sequence somewhere? [try http://www.rsyslog.com/e/2207 ]
rsyslogd: error during parsing file /etc/rsyslog.d/41-AP.conf, on or before line 20: invalid character '.' in object definition - is there an invalid escape sequence somewhere? [try http://www.rsyslog.com/e/2207 ]
rsyslogd: error during parsing file /etc/rsyslog.d/41-AP.conf, on or before line 20: invalid character '*' in object definition - is there an invalid escape sequence somewhere? [try http://www.rsyslog.com/e/2207 ]
rsyslogd: error during parsing file /etc/rsyslog.d/41-AP.conf, on or before line 20: invalid character '\' in object definition - is there an invalid escape sequence somewhere? [try http://www.rsyslog.com/e/2207 ]
rsyslogd: error during parsing file /etc/rsyslog.d/41-AP.conf, on or before line 20: syntax error on token ']' [try http://www.rsyslog.com/e/2207 ]
rsyslogd: CONFIG ERROR: could not interpret master config file '/etc/rsyslog.conf'. [try http://www.rsyslog.com/e/2207 ]
rsyslogd: run failed with error -2207 (see rsyslog.h or try http://www.rsyslog.com/e/2207 to learn what that number means)
我不明白为什么,正则表达式没有任何错误。什么都没有给出。有什么想法吗?当你写“\[(.+)\]--end”
,\[
应该是一个特殊字符(比如\n
),而不是。为了避免反斜杠的特殊用法,应该用另一个反斜杠来转义。因此,虽然真正的正则表达式是\[(.+)\]
和\[.+\](.+)
,但必须使用的字符串是:“\\[(.+)\]”
和“\[.+\](.+)”
另外,要小心双引号,你可能想
“
”,而不是“
这样做\[(.+)\]
,而这个\[.+\](.+)
解析器不会有任何错误,太好了。但我没有找到匹配项。我在nano中编辑,使用普通的双引号(“).rsyslog确实需要类似perl/sed的语法,以便更自然地编写正则表达式。或者是这样,或者更好地使用转义规则,或者区分“和”引号。