Forum Discussion
Peter__Draper_7
Nimbostratus
Jan 27, 2005Logging 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_127330Historic F5 AccountYou 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...
- Peter__Draper_7
Nimbostratus
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 - Peter__Draper_7
Nimbostratus
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 - Peter__Draper_7
Nimbostratus
For info the very basic rule iswhen 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 - Peter_Reilly
Nimbostratus
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? - Peter__Draper_7
Nimbostratus
Not sure but if you have $log_uri here it wont like the space.
Anyone else! - unRuleY_95363Historic F5 AccountI 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.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects