You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Martin T <m4...@gmail.com> on 2019/10/23 16:33:11 UTC

[users@httpd] Optimal way to trigger logging if certain URL is accessed

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.


thanks,
Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimal way to trigger logging if certain URL is accessed

Posted by Rainer Jung <ra...@kippdata.de>.
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.html

Despite 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@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimal way to trigger logging if certain URL is accessed

Posted by Anil Kumar P <na...@gmail.com>.
Nope only on server and vhost levels.

Thanks,
Anil

> On Oct 23, 2019, at 11:52 AM, Colin 't Hart <co...@gmail.com> wrote:
> 
> Are logging directives allowed inside a Location or LocationMatch directive?
> 
> /Colin
> 
> Sent from my iPhone
> 
>> On 23 Oct 2019, at 18:41, Martin T <m4...@gmail.com> wrote:
>> 
>> 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.
>> 
>> 
>> thanks,
>> Martin
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimal way to trigger logging if certain URL is accessed

Posted by Colin 't Hart <co...@gmail.com>.
Are logging directives allowed inside a Location or LocationMatch directive?

/Colin

Sent from my iPhone

> On 23 Oct 2019, at 18:41, Martin T <m4...@gmail.com> wrote:
> 
> 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.
> 
> 
> thanks,
> Martin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimal way to trigger logging if certain URL is accessed

Posted by Martin T <m4...@gmail.com>.
Ok, thanks for replies!


regards,
Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Optimal way to trigger logging if certain URL is accessed

Posted by Eric Covener <co...@gmail.com>.
On Wed, Oct 23, 2019 at 12:41 PM Martin T <m4...@gmail.com> wrote:
>
> 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?

It is a little weird but pretty neat.

A RewriteMap of type prg: is maybe a little better.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org