当特定消息(匹配例如正则expression式)到达UDP端口(系统日志格式)时,我需要执行给定的操作。 如何做到这一点(即通过使用已经可用的软件而不是手写)?
也许你应该看看rsyslog 。 它的语法比syslogd更加灵活和简单。 整体来说也更加强大。
无论如何,你想在rsyslog中想要什么
if ( regex ) then action & another_action # This line could be ignored if you want only one action
Syslog-ng可以通过如下方式实现:
destination d_special { program("/usr/local/bin/script"); }; filter f_special { match("regex"); }; log { source (s_all); filter(f_special); destination(d_special); };
我想这个链接到logwatch的manpage将是有用的。
您可以使用OSSEC来观察特定模式,并使用主动响应function来执行您所需的操作。