Am 23.10.2019 um 18:33 schrieb Martin T:
Hi, I have a following Apache virtual host configuration where custom call_Google_MP_API script receives the IP address and HTTP User-Agent string as standard input if https://www.example.com/doc.pdf is downloaded: <IfModule ssl_module> <VirtualHost *:443> /* configuration removed for brevity */ SetEnvIf Request_URI "^/doc\.pdf$" pdfdoc LogFormat "%h %{User-agent}i" ga CustomLog "|/usr/local/bin/call_Google_MP_API" ga env=pdfdoc </VirtualHost> </IfModule> As my web server had setenvif_module and log_config_module already loaded, then I used SetEnvIf directive to set the "pdfdoc" internal variable when doc.pdf is downloaded, LogFormat directive to set the nickname "ga" for specific log format and finally CustomLog directive to pipe this custom log format to call_Google_MP_API script if "pdfdoc" variable is set, i.e https://www.example.com/doc.pdf URL is accessed. While this seems to work fine, then is this the correct/optimal way to accomplish this? I'm using Apache version 2.4.38 on Debian 10.
You could also use mod_log_debug: https://httpd.apache.org/docs/2.4/en/mod/mod_log_debug.htmlDespite it's name it is very useful not only for debugging but adding general custom log messages. The output goes to the ErrorLog though (which can be a pipe). The log messages generated can include references to request details, like e.g. %{REMOTE_ADDR} and %{HTTP_USER_AGENT}:
https://httpd.apache.org/docs/2.4/en/expr.html and can be generated inside Location blocks.Furthermore one can control, at what point in time during request processing the message is generated.
Since it goes to the error log, you would need to send it to a piped process separatig these log lines from the remaining error log lines, because I guess you want to only send the new log lines to your script and the remaining ones still to rotatelogs or similar.
Regards, Rainer --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx