Forum Discussion
naladar_65658
Altostratus
Nov 20, 2008A Problem with Datagroup Usage
I am having problems with an iRule that uses datagroups. For some reason it just doesn't seem to work at all. Would you fellas mind taking a look at it and maybe point out any grammatical or logic errors it may have? I have ran it through the iRule Editor and the syntax checks out, but I feel like I am missing something basic that the editor just doesn't pick up...
when HTTP_REQUEST {
set header_uri [string tolower [HTTP::uri]]
if {[matchclass $header_uri starts_with $::www8_uri]} {
pool WWW8_Pool
} elseif {[matchclass $header_uri starts_with $::oam_uri]} {
HTTP::redirect "https://blank.blank.com/oam/main/oamMain.jsp"
} elseif {[matchclass $header_uri starts_with $::hello_uri]} {
pool Hello_Pool
} elseif {[matchclass $header_uri starts_with $::maui_uri]} {
pool Maui_Pool
} elseif {[matchclass $header_uri starts_with $::publicSite_app_uri]} {
pool PublicSite_App_Pool
} elseif {[matchclass $header_uri starts_with $::calli_web_uri]} {
pool Calli_Web_Pool
} elseif {[matchclass $header_uri starts_with $::true_web_uri]} {
pool True_Web_Pool
} elseif {[matchclass $header_uri starts_with $::documentum_uri]} {
pool Documentum_Pool
} else {
pool WWW2_Pool
}
}
- hoolio
Cirrostratus
The syntax looks fine. Can you add logging to see what's happening? Are all requests hitting the default else? If so, can you post an anonymized sample of the datagroup that your test requests should match? - naladar_65658
Altostratus
Unfortunately I cannot add it back into production with logging turned on for at least another week as that is when our next service window is. This rule is replacing an older iRule that does not use datagroups. - hoolio
Cirrostratus
Maybe you can create a test VIP on the live BIG-IPs? If you're on 9.4 or higher, you could even create a test VIP on a non-routable IP and test from the command line of the BIG-IP itself using curl: - naladar_65658
Altostratus
I checked all of the datagroups that I am trying to hit and they are all in lower case. I wonder if maybe I need to use equals or contains rather than the starts_with... or maybe use brackets to enclose the $header_uri variable in each statement? - hoolio
Cirrostratus
If the URI's start with the datagroup members, then 'matchclass $header_uri starts_with $::dg_name' is the right format. Using []'s would try to execute the value of the URI, so that wouldn't work.when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::uri]" set header_uri [string tolower [HTTP::uri]] log local0. "[IP::client_addr]:[TCP::client_port]: \$header_uri: $header_uri" if {[matchclass $header_uri starts_with $::www8_uri]} { log local0. "[IP::client_addr]:[TCP::client_port]: Matched www8_uri dg" pool WWW8_Pool } elseif {[matchclass $header_uri starts_with $::oam_uri]} { log local0. "[IP::client_addr]:[TCP::client_port]: Matched oam_uri dg" HTTP::redirect "https://blank.blank.com/oam/main/oamMain.jsp" ... } else { log local0. "[IP::client_addr]:[TCP::client_port]: No match" log local0. "[IP::client_addr]:[TCP::client_port]: dg's: \$::www8_uri: $::www8_uri, \$::oam_uri: $::oam_uri, etc" pool WWW2_Pool } }
- HTTP::uri always starts with a slash. Even for an empty URI (ie. http://www.foo.com), the URI will be "/".
http://www.foo.com/dco
- hoolio
Cirrostratus
HTTP::uri returns the full URI. For a URL like:when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::uri]" set header_uri [string tolower [HTTP::uri]] log local0. "[IP::client_addr]:[TCP::client_port]: \$header_uri: $header_uri" if {[matchclass $header_uri starts_with $::www8_uri]} { log local0. "[IP::client_addr]:[TCP::client_port]: Matched www8_uri dg" pool WWW8_Pool } elseif {[matchclass $header_uri starts_with $::oam_uri]} { log local0. "[IP::client_addr]:[TCP::client_port]: Matched oam_uri dg" HTTP::redirect "https://blank.blank.com/oam/main/oamMain.jsp" } else { log local0. "[IP::client_addr]:[TCP::client_port]: No match" log local0. "[IP::client_addr]:[TCP::client_port]: dg's: \$::www8_uri: $::www8_uri, \$::oam_uri: $::oam_uri" pool WWW2_Pool } }
- naladar_65658
Altostratus
Thank you for the excellent example and for all the help fellas. I will turn on logging and run a few tests using the info that you provided and then I will post the results. - naladar_65658
Altostratus
First off, my apologizies on posting this in the wrong forum! DOH! I should have posted this under iRules, not iControl. - Not likely but there are some issues with ending spaces if you carry your start curly brace over to a new line but you didn't do that in your original post.
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