Forum Discussion
Where is and Country
The goal is to add the rule to a VIP that will redirect to country specific folders on the same VIP. once a user hits the country specific folder they will get a cookie to identify the country choice so I do not want the rule to run very time but can't figure out how to get past the initial looping when a user does not have the country cookie.
The second part is the rule does not seem to work when I use country. Using the rule below I get get the redirect if I change $country to $state but no luck with Country
when CLIENT_ACCEPTED {
set country [class match -value [whereis [IP::client_addr]] equals CTS_COUNTRY]
set state [class match -value [whereis [IP::client_addr] abbrev] equals US_STATE]
log local0. "The country is [whereis [IP::client_addr] country] and the state is [whereis [IP::client_addr] abbrev]"
}
when HTTP_REQUEST {
if {[HTTP::cookie exists "SelectedCountryCode"]} {
log local0. "Cookie found [HTTP::cookie SelectedCountryCode]"
event HTTP_REQUEST disable }
elseif {($country ne "")}{
switch $country {
PA {HTTP::redirect http://www.testdomain.com/nsurvey}
US {HTTP::redirect http://www.testdomain.com/nsurvey}
CA {HTTP::redirect http://www.google.com}
AU {HTTP::redirect http://www.ctstestdomain.com/nsurvey}
GB {HTTP::redirect http://www.testdomain.com/nsurvey}
default {pool www.testdomain.com}
}
}
}
The logging does show Country and state but no redirect for country
: The country is US and the state is PA
: The country is GB and the state is 17
If I do away with the HTTP::cookie exists and use this I can get around the looping issue but the developers would like to use cookie
if { [class match [HTTP::uri] contains US_STATE]} {
event HTTP_REQUEST disable }
Any suggestions?
8 Replies
- Michael_Yates
Nimbostratus
I would suggest looking at the Heat Maps Tech Tip that Colin posted.
The continents post was in the second post of the series (http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1086353/Heatmaps-iRules-Style-Part2.aspx), but the entire series is worth reading.
The Wiki Entry for whereis could be useful too: http://devcentral.f5.com/wiki/iRules.whereis.ashx
whereis country
Returns a string containing the two-letter country code (JP) - boczon_108037
Nimbostratus
Thanks I'll take a look at the Heatmaps and I was able to valdate that the country code was being returned. - Colin_Walker_12Historic F5 AccountHere's the specific line Michael is referencing:
set cloc [whereis [IP::client_addr] country]
Thanks for the mention. 😉
Colin - boczon_108037
Nimbostratus
Thanks for the info but forgive me if I am missing the obvious. I was not able to determine where i was making a mistake in my rule. I am unsure why the rule would work for state but not country. - Kevin_Davies_40
Nacreous
when HTTP_REQUEST { set debug 1 if {[HTTP::cookie exists "SelectedCountryCode"]} { set country [HTTP::cookie "SelectedCountryCode"] if {$debug} { log local0. "SelectedCountryCode = [HTTP::cookie SelectedCountryCode ]" } } else { set country [whereis [IP::client_addr] country] } if {$debug} { log local0. "Country is $country" } switch $country { PA { set redirect http://www.testdomain.com/nsurvey} US { set redirect http://www.testdomain.com/nsurvey} CA { set redirect http://www.google.com} AU { set redirect http://www.ctstestdomain.com/nsurvey} GB { set redirect http://www.testdomain.com/nsurvey} default { if {$debug} { log local0. "Unmatched country was $country" } set redirect http://www.testdomain.com } } if {$debug} { log local0. "Redirected to $redirect" } HTTP::redirect $redirect}
I didn't see any data classes listed so took them out for this code. Test and check the logging to validate the results. Then you can add the classes back in. Is the last pool command in your code meant to be a redirect? The pool name looks like a website name. You can turn off logging by setting debug 0 on the second line.
Kevin (Jarvil) - boczon_108037
Nimbostratus
Thanks i'll give it a try the last pool command is just sending to a default pool. The name of the pool just happens to be the FQDN of the web site it is supporting. - Kevin_Davies_40
Nacreous
If its the default pool attached to the virtual then you don't need the pool command. It will go to that pool unless you redefine it somewhere.Kevin (Jarvil)
- Aaron_1015
Nimbostratus
By the way, I know this is an old thread, but I was looking for something related to whereis and came across this. I think the problem was that the first set command is missing the "country":
set country [class match -value [whereis [IP::client_addr]] equals CTS_COUNTRY]
Change that to:
set country [class match -value [whereis [IP::client_addr] country] equals CTS_COUNTRY]
And it may work as anticipated. The log command uses the "country" which is why that works, but the $country variable simply wasn't being set properly. Had the log command used the variable $country instead of doing another lookup, then the original poster would have seen the default "whereis" returning a TCL list of {continent country region city} since no modifier was used.
Since nobody else mentioned that specifically, I thought I'd reply to a stale thread.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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