Forum Discussion
FishNiX_29746
Nimbostratus
Jan 25, 2010HOST/URI to pool mapping via iRule and class and trailing /
Greetings -
I'm attempting to write a generic iRule to send traffic for a URI to a specific pool. I will use this over "many" virtuals with "many" URIs.
I've ...
hoolio
Cirrostratus
Jan 26, 2010It sounds like FishNiX wants to get the longest match though. You could loop through the class row by row and track the curent longest match of the host and URI until you get through all rows. Or another option would be to combine the first two columns of the class and then use lindex -index -descending to sort the class as a list. This would probably only work in 9.x though, as you can't access a datagroup/class as a standard TCL list in 10.x.
Here is a rough example of the second option for 9.x:
when HTTP_REQUEST {
Class order isn't guaranteed to come back in the order entered in the bigip.conf...
log local0. "list: $::host_uri_pool_selector_class"
log local0. "lsort: [lsort -decreasing -index 0 $::hooleya_host_uri_pool_selector_class]"
Sort the datagroup on the first field, with longest lengths first
foreach row [lsort -decreasing -index 0 $::host_uri_pool_selector_class] {
log local0. "\$row: $row"
if {[string tolower [HTTP::host]][HTTP::uri]] starts_with [getfield $row " " 1]}{
log local0. "Found longest match: $line; pool: [getfield $row " " 2]"
break
}
}
}
For an example of manually tracking the longest match, you can use Deb's example below. This example would also work with the class command in v10.
http://devcentral.f5.com/wiki/default.aspx/iRules/FindclassAgainstVariableLengthURI.html
http://devcentral.f5.com/wiki/default.aspx/iRules/class
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
