Linux

SyslogNG-如何優化過濾器和日誌語句?

  • October 9, 2018

以下是本地 Syslog-NG 日誌記錄的目前配置,

source s_network {
       udp(
               flags(syslog_protocol)
               keep_hostname(yes)
               keep_timestamp(yes)
               use_dns(no)
               use_fqdn(no)
       );
};

destination d_all_logs {
       file("/app/syslog-ng/custom/output/all_devices.log");

};

log {
       source(s_network);
       destination(d_all_logs);
};

轉發某些消息…下面是要添加的配置。

filter message_filter_string_1{ 
           match("01CONFIGURATION\/6\/hwCfgChgNotify\(t\)", value("MESSAGE"));
           }


filter message_filter_string_2{
           match("01SHELL\/5\/CMDRECORD", value("MESSAGE"));
           }

filter message_filter_string_3{
           match("10SHELL", value("MESSAGE"));
           }

filter message_filter_string_4{
           match("ACE-1-111008:", value("MESSAGE"));
           }

destination remote_log_server {
udp("192.168.0.20" port(25214));
};

log { source(s_network); filter(message_filter_string_1); destination(remote_log_server); };

log { source(s_network); filter(message_filter_string_2); destination(remote_log_server); };

log { source(s_network); filter(message_filter_string_3); destination(remote_log_server); };

log { source(s_network); filter(message_filter_string_4); destination(remote_log_server); };

實際上有80多個這樣的過濾器

Syslog-NG 配置是否允許編寫具有or orfilter匹配的單個語句的語法?regex1``regex2``regex3

(或者)

logSyslog-NG 配置是否允許編寫具有多個過濾器的單個語句的語法?

如果要組合多個匹配語句,請使用or

filter send_remote { 
           match("01CONFIGURATION\/6\/hwCfgChgNotify\(t\)", value("MESSAGE")) 
 or
           match("01SHELL\/5\/CMDRECORD", value("MESSAGE")) 
 or
           match("10SHELL", value("MESSAGE"))
 or
           match("ACE-1-111008:", value("MESSAGE"));

           }

…然後使用該過濾器名稱一次:

log { source(s_network); filter(send_remote); destination(remote_log_server); };

引用自:https://unix.stackexchange.com/questions/474305