It’s a good thing Your JoeDog is not very bright. If he were an intelligent man, then he’d realize the difficulty of the task he was about to undertake before he undertook it. He would look at that task and think, “I’m not good enough to code that.” Fortunately, he’s not very bright and that means fido has a new feature.
New feature? Exciting!
Beginning with version 1.1.4, fido can do regex capture and pass the back references to the program it should run. Let’s look at an example config to help us make some sense of this. The new feature is highlighted in red.
/var/log/httpd/joedog-access_log { rules = ^([0-9]+.[0-9]+.[0-9]+.[0-9]+).*GoogleBot action = /home/jeff/bin/googler $1 }
In this exercise, we want to find instances of GoogleBot in the access log, but we also want to verify that it’s actually the GoogleBot and not a crawler with a forged User-agent. To accomplish that, we want to capture the IP address and send it to our program for validation.
So let’s look at the rule:
^([0-9]+.[0-9]+.[0-9]+.[0-9]+).*GoogleBot
If a line being with an quartet of dot separated numbers, i.e., an IP address, and it contains GoogleBot, then we have a match. Notice that IP address is wrapped in parentheses? That’s our capture. Everything within the parens will be assigned to $1. (BTW: Writing that was a royal PITA.) If we had two sets of parens, then the second set would be assigned to $2.
Fido will assign variables by name so it doesn’t matter which order you pass them to your program.
/var/log/httpd/joedog-access_log { rules = ^([0-9]+.[0-9]+.[0-9]+.[0-9]+).*(GoogleBot) action = /home/jeff/bin/googler $2 $1 }
Will run: /home/jeff/bin/googler GoogleBot 198.14.14.6
I’ll release version 1.1.4 after the documentation is up-to-date. In the meantime, early adapters can grab the code from the source repository.
You’ll need autotools on your system. Inside the fido directory, run this command to build the configure script:
utils/bootstrap
Happy hacking.