Forum Discussion
Rob_Wotton_8024
Nimbostratus
Oct 21, 2009Multiple Pool Redirection Based on IP
Hi
I am struggling with an iRule at the moment, in simple English when the URI starts with /product1 and is from IP address 1.1.1.1 we need to use pool product1-CustomerA. If the URI starts with /product1 and is requested by any other IP address then it needs to use pool product1.
I have written the below iRule but it only works if the IP is 1.1.1.1, the else statement doesn't seem to work, I am also not sure the rest of my syntax is correct as sometimes it works and other times it doesn't.
Anyhelp would be appreciated.
Thanks
Rob
when HTTP_REQUEST {
if { [IP::addr [IP::client_addr]/32 equals 1.1.1.1] } {
switch [string tolower [HTTP::uri]] {
"/product1" {
pool product1-CustomerA
}
"/product2" {
pool product2-CustomerA
}
"/product3" {
pool product2-CustomerA
}
default {
pool standardpool-CustomerA
}
else {
switch [string tolower [HTTP::uri]] {
"/product1" {
pool product1
}
"/product2" {
pool product2
}
"/product3" {
pool product2
}
default {
pool standardpool-CustomerB
}
}
}
}
}
}
}
- hoolio
Cirrostratus
Hi Rob,when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::host][HTTP::uri]" if { [IP::addr [IP::client_addr]/32 equals 1.1.1.1] } { log local0. "[IP::client_addr]:[TCP::client_port]: Matched IP check for 1.1.1.1" switch -glob [string tolower [HTTP::uri]] { "/product[1-3]" { log local0. "[IP::client_addr]:[TCP::client_port]: Matched /product1-3 check" pool product1-CustomerA } default { log local0. "[IP::client_addr]:[TCP::client_port]: No match on /product1-3 check" pool standardpool-CustomerA } } } else { switch -glob [string tolower [HTTP::uri]] { "/product1" { log local0. "[IP::client_addr]:[TCP::client_port]: No IP match. Matched /product1 check" pool product1 } "/product[2-3]" { log local0. "[IP::client_addr]:[TCP::client_port]: No IP match. Matched /product2-3 check" pool product2 } default { log local0. "[IP::client_addr]:[TCP::client_port]: No IP match. No product check" pool standardpool-CustomerB } } } }
- Rob_Wotton_8024
Nimbostratus
Thanks Aaron - I will try that now. - hoolio
Cirrostratus
One other thing I meant to ask about: the URI tokens you have listed in the switch cases are equals comparisons. I assume the URIs won't always be exactly /product. Do you want to select the pool based on the URI starting with /product? If so, try adding a * to the end of each switch case: - hoolio
Cirrostratus
You can view the logs in the GUI under System | Logs | Local Traffic. Or more ideally, access the CLI via SSH and run 'tail -f /var/log/ltm' without the single quotes to follow the end of the ltm log file. You can type Ctrl+c to stop the tail from running.when RULE_INIT { switch -glob "/test" { "/test*" {log local0. "matched"} default {log local0. "no match"} } }
- Rob_Wotton_8024
Nimbostratus
Thanks for the logs, have found those. - hoolio
Cirrostratus
Hi Rob, - Rob_Wotton_8024
Nimbostratus
Hi Aaron.
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