1

我正在尝试/var/log/secure使用正则表达式对字符串进行数学运算,以获取是否存在 ssh 身份验证失败。

如果身份验证失败,它在日志文件中将如下所示:

Oct 31 07:52:41 logserver sshd[17041]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=localhost

我试着做这样的事情:

"\\<sshd[^:]*: pam_unix(sshd:auth): authentication failure; ./* \\>"

但它不起作用。如果有人可以帮助我处理正则表达式,我将不胜感激。

这是在 CentOS 7 机器上,正则表达式用于 collectd 的 plugin tail

4

1 回答 1

1

collectd 中 .conf,您可能会使用以下内容之一:

<Plugin "tail">
  <File "/var/log/secure">
    ...
    <Match>

选项1:

    Regex "authentication failure"

选项 2:

    Regex "sshd:auth[^:]*: authentication failure;"

选项 3:

    Regex "authentication failure|authentication|failure"

其中选项 1 和 2 应该是最精确的匹配,而选项 3 更通用。选项 1 找到确切的短语authentication failure,选项 2 找到确切的短语以及 (sshd:auth): 在它之前,选项 3 找到确切的短语或“身份验证”或“失败”。

    </Match>
  </File>
</Plugin>
于 2015-10-31T12:58:43.493 回答