Forum Discussion

Peter__Draper_7's avatar
Peter__Draper_7
Icon for Nimbostratus rankNimbostratus
Jan 27, 2005

Logging requested URI on a 404 redirect rule

I am starting to use iRules on 9.0.3 and am redirecting to a static IP of a virtual server when a 404 is received. I am logging the fact that a 404 has ben seen but would like to add in the requested url/uri to the log statement so I can then know what to look at for the missing location on the suspect server.

 

 

Any assistance appreciated.

 

 

7 Replies

  • drteeth_127330's avatar
    drteeth_127330
    Historic F5 Account
    You need to save the URI in a variable in HTTP_REQUEST and then log it using the log command in HTTP_RESPONSE. Hope this helps...
  • Thanks for the tip. How to I save in the HTTP_REQUEST and then Reference the saved information in the log section.

     

     

    Thanks in advance. Sorry for the dumb questions......

     

     

    PD

     

  • Just sorted it. Thanks - was not aware you gcould do a set to a variable the call on that variable later.

     

     

    thanks for the help anyway

     

     

    PD
  • For info the very basic rule is

     
     when HTTP_REQUEST {  
        set log_uri [HTTP::uri]  
     }  
        
     when HTTP_RESPONSE {  
        set debug "1"  
        if {[HTTP::status] equals "404"} { HTTP::redirect "http://10.10.8.106"  
           if $debug {log local0. "404 error $log_uri -redirected to 10.10.8.106"}  
        }  
     }  
     

    Thanks

  • I'm trying to do some similar logging on HTTP status, but when I use this syntax, the variable ($log_uri here) is not showing up in the log message as the content of the variable but rather as a literal string. I've tried bracketing it, closing the quotes, etc but nothing works...everything I put after the {log local0. statement is just printed literally in the log. Any ideas?
  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    I might suggest you try removing the debug cruft and just try this:

     
     when HTTP_REQUEST { 
        set log_uri [HTTP::uri] 
     } 
     when HTTP_RESPONSE { 
        if { [HTTP::status] eq "404" } { 
           HTTP::redirect "http:://10.10.10.1" 
           log "404 error $log_uri - redirected to 10.10.8.106" 
        } 
     } 
     

    You do not need to supply the local0. in v9 (this was fixed). The default facility.level is local0.info (you can still specify it if you want to though). If you continue to have trouble then I would suggest you try bracketing the variable with {}, as in ${log_uri}. This is how you deal with embedding a variable in the middle of another word.

    For example:

    "mybigfatgreek$log_uriwedding" will not work, it will print that string literally. However, if you say "mybigfatgreek${log_uri}wedding" it will work just fine.

    Hope any of this helps you debug through your problem.