当我有规则
if ($msg contains "foobah"
OR re_match($msg, '(authmgr|cli)\[[0-9]+\]:')
)
then {
rsyslog最终会引发分段错误。即使我注释掉包含re_match
的行,它仍然会抛出一个分段错误。
rsyslogd 8.24.0-34.el7, compiled with:
PLATFORM: x86_64-redhat-linux-gnu
PLATFORM (lsb_release -d):
FEATURE_REGEXP: Yes
GSSAPI Kerberos 5 support: Yes
FEATURE_DEBUG (debug build, slow code): No
32bit Atomic operations supported: Yes
64bit Atomic operations supported: Yes
memory allocator: system default
Runtime Instrumentation (slow code): No
uuid support: Yes
Number of Bits in RainerScript integers: 64
我希望此规则匹配包含authmgr[123]:
或cli:[456]:
的事件。
有人可以确认正则表达式是否格式正确并解释为什么注释掉该行会导致分段错误?
答案似乎是你需要在字符串中转义反斜杠,所以这应该工作:
re_match($msg, '(authmgr|cli)\\[[0-9]+\\]:')
在我的rsyslog版本,8.30.0中,如果你不这样做,你会得到一条错误信息,提供一个线索:表达式中的无效字符''' - 某处有无效的转义序列吗?
有一个online tool正确逃脱字符串。如果你提供a\b
它会生成a\\b
。