Getting regex for grok filter?
1 answer
You can do this with a simple Perl script that reads the templates file and replaces the stuff with the %{PATTERN}
actual regex it's based on - you'll have to tweak it a bit, but it shows you how to do it:
#!/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";
+2
source to share