我正在尝试使用正则表达式对/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机器上,而正则表达式用于collected的插件tail。

请您参考如下方法:

在收集的 .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> 


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!