syslog-ng匹配和过滤器不能按我想要的方式工作

时间:2017-06-02 19:51:51

标签: syslog-ng

我有以下消息

1)"customer1"," 5","0","".....
2)"customer2"," 5","0",""....
3)"customer3"," 5","0",""...
4)""," 5","0",""
5)""," 5","0",""

我想要实现的是基于双引号中的第一个值我想创建文件夹然后只在相应的文件夹中写日志,每当双引号为空时将这些日志发送到Others文件夹中。通过以下配置,我能够创建像(customer1,customer2和customer3)这样的文件夹。问题当我在第一个位置有空值如log 4和5时发生。

系统日志-ng.conf是否

filter c1 {match('(^“”)'flags(“store-matches”)type(“pcre”)value(“MESSAGE”));}; 目的地d1 {file(“/ opt / data / cef / other / $ {DAY} $ {MONTH} $ {YEAR} _other.log”);}; log {source(s_udp); filter(c1); destination(d1);};

filter c2 {match('(?< =“)([\ w \ s] *)(?=”)'flags(“store-matches”)type(“pcre”)value(“MESSAGE”) ));}; 目的地d2 {file(“/ opt / data / cef / $ 1 / $ {DAY} $ {MONTH} $ {YEAR} _ $ 1.log”);}; log {source(s_udp); filter(c2); destination(d2);};

第一个过滤器检查第一个双引号是否为空或只是像“”并将它们写入Others文件夹。问题是第二个过滤器它匹配“”之间的所有内容。因此,如果它有值,它可以正常工作,但如果它是空的则行为不正确。因此它将此日志写入/ opt / data / cef文件夹中名为03_06_2017.log的文件。我不确定为什么要创建一个单独的文件。

请帮忙。

此致 VG

1 个答案:

答案 0 :(得分:0)

我认为使用csv-parser会更容易:https://www.balabit.com/documents/syslog-ng-ose-latest-guides/en/syslog-ng-ose-guide-admin/html/csv-parser.html

如果消息中的列数不同,并且您只需要过滤器的第一列,那么您可以使用贪婪标记来处理其他列。