I have the case where..
Sometimes my log has a block of JSON.
Sometimes that block of JSON has a field (Lets call it "IPAddress")
Sometimes the field "IPAddress" has a valid IP, other times, I've seen it with the value "unknown" or an empty string.
I want to..
If the "IPAddress" field exists..
If the field contains a valid IP address..
THEN, apply the geoip filter to it.
I know that there is a %{IP} defined pattern for Grok.
What I would like to do is something similar to..
if [IPAddress] =~ %{IP} {
#Do stuff
}
However there are few caveats I've seen.
-
It doesn't seem to work that way. In place of that, I found the base regex that comprises the %{IP} pattern, and now have done this:
if [IPAddress] =~ /Long horrible string of regex.. seriously like 8 lines/
That works. But, its messy. -
What kind of performance impact does this present, if any? And would any performance be gained by replacing the long regex string with %{IP}?
So overall, I would argue that a more readable config file, using Grok patterns for situations like this, is a benefit.
What do you guys think?
And, maybe this is just a horrible way to approach my problems. What might be some other ways to solve this?
Thanks!
Edit: Post had multiple items as a numbered list... all with the same number. Fixed. Also changed some words and emphasized some text for clarity