我有一个复杂的Grok过滤器表达式... 是否可能获取此过滤器转换为的正则表达式?
%{PATTERN}
替换为实际基于正则表达式的内容 -- 你需要进行一些自定义,但这说明了如何做到这一点:#!/usr/bin/perl
# this is the path to your grok-patterns file
open(F,"patterns/grok-patterns");
while (<F>) {
chomp;
if (/^(\S+) (.*)/) {
$pattern{$1} = $2;
}
}
close(F);
# this is the grok pattern I want to expand
$pattern='%{IP:junk} %{COMBINEDAPACHELOG:junk2}';
while ($pattern =~ /(%\{([^:\}]+):?[^\}]*\})/) {
$name = $2;
substr($pattern,$-[0],$+[0]) = $pattern{$name};
}
print $pattern,"\n";