12-Oct-2015
13:21
- last edited on
02-Jun-2023
15:56
by
JimmyPackets
In using an External Data Group everything seems to work except for the pulling up of the second data area.
when RULE_INIT { Turn Debug on or off (0=off 1=on) Turn debug off in prod set static::redir_debug 0 } when HTTP_REQUEST { Use following to match against datagroup set match_string [string tolower [HTTP::host]] append match_string [string tolower [HTTP::path]] if {$static::redir_debug}{log local0. "Match String: $match_string"}
Lookup the redirect or pool based upon match_sting value
set goto [class lookup $match_string www_ou_edu_redir_class]
if {$static::redir_debug}{log local0. "Goto: $goto"}
if { [getfield $goto "," 1] equals "pool" }{
if {$static::redir_debug}{log local0. "Pool declaration detected. Going to: [getfield $goto "," 2]"}
pool [getfield $goto "," 2]
} else {
if {$static::redir_debug}{log local0. "Redirect declaration detected. Redirecting to: [getfield $goto "," 2]"}
HTTP::redirect https://[getfield $goto "," 2]
}
}
12-Oct-2015
13:23
- last edited on
02-Jun-2023
15:56
by
JimmyPackets
when RULE_INIT {
Turn Debug on or off (0=off 1=on)
Turn debug off in prod
set static::redir_debug 0
}
when HTTP_REQUEST {
Use following to match against datagroup
set match_string [string tolower [HTTP::host]]
append match_string [string tolower [HTTP::path]]
if {$static::redir_debug}{log local0. "Match String: $match_string"}
Lookup the redirect or pool based upon match_sting value
set goto [class lookup $match_string www_ou_edu_redir_class]
if {$static::redir_debug}{log local0. "Goto: $goto"}
if { [getfield $goto "," 1] equals "pool" }{
if {$static::redir_debug}{log local0. "Pool declaration detected. Going to: [getfield $goto "," 2]"}
pool [getfield $goto "," 2]
} else {
if {$static::redir_debug}{log local0. "Redirect declaration detected. Redirecting to: [getfield $goto "," 2]"}
HTTP::redirect https://[getfield $goto "," 2]
}
}
12-Oct-2015 13:34
12-Oct-2015
13:38
- last edited on
22-Nov-2022
07:12
by
JimmyPackets
Your code looks reasonable. Are you just not returning a value into $goto? The class lookup command uses an implied "equals" comparison, so you might just not be making an exact match. Try this instead:
set goto [class match -value $match_string starts_with www_ou_edu_redir_class]
where the data group is the least specific URL pattern. You can also simplify some of your code by getting rid of a few variables:
set goto [class match -value [string tolower [HTTP::host][HTTP::path]] starts_with www_ou_edu_redir_class]
12-Oct-2015
14:20
- last edited on
02-Jun-2023
15:56
by
JimmyPackets
The [HTTP::uri] command will always return at least "/", even if no URL path is specified, so most of your samples won't ever match. You should see that in your log statement:
if {$static::redir_debug}{log local0. "Match String: $match_string"}
With a call to "admissions.ou.edu", which should return:
admissions.ou.edu/
If in your log statement you see, for example:
Goto: pool,ouwww_bostitch,
But you see nothing from:
[getfield $goto "," 2]
then there's another issue that might be better solved with a list function. But I'm more inclined to think its a data group matching issue still.
12-Oct-2015
15:36
- last edited on
02-Jun-2023
15:56
by
JimmyPackets
but doesn't the "redirection declaration detected. Redirecting to:" show that it is infact matching ?
That's inside an else clause, so no.
if { [getfield $goto "," 1] equals "pool" }
which it never does because $goto is empty.
13-Oct-2015
12:02
- last edited on
02-Jun-2023
15:55
by
JimmyPackets
Here is the final version of the iRule
when RULE_INIT {
Turn Debug on or off (0=off 1=on)
Turn debug off in prod
set static::redir_debug 1
}
when HTTP_REQUEST {
Use following to match against datagroup
Lookup the redirect or pool based upon match_string value
set goto [class match -value [string tolower [HTTP::host][HTTP::path]] starts_with www_ou_edu_redir_class]
if {$static::redir_debug}{log local0. "Goto: $goto"}
if { [getfield $goto "," 1] equals "pool" }{
if {$static::redir_debug}{log local0. "Pool declaration detected. Going to: [getfield $goto "," 2]"}
pool [getfield $goto "," 2]
} else {
if {$static::redir_debug}{log local0. "Redirect declaration detected. Redirecting to: [getfield $goto "," 2]"}
HTTP::redirect http://[getfield $goto "," 2]
}
}
and then here is a sample of the external Datagroup file that goes with the rule that works.
ags.ou.edu := "redir,www.ou.edu/ags.html",
ags.ou.edu/~ := "redir,parker.ou.edu",
airport.ou.edu := "redir,www.ou.edu/airport.html",
alc.ou.edu := "pool,ouwww_bostitch",
so what i was missing, which was pointed out here was the fact that the F5 was unable to pull out the second part of the data. encapsulating the data in Double Quotes enabled that to work.
13-Oct-2015
13:01
- last edited on
02-Jun-2023
15:55
by
JimmyPackets
so what i was missing, which was pointed out here was the fact that the F5 was unable to pull out the second part of the data. encapsulating the data in Double Quotes enabled that to work
Great that it works, but that most likely was not the reason. You changed your class command:
set goto [class match -value [string tolower [HTTP::host][HTTP::path]] starts_with www_ou_edu_redir_class]
which gave you a little more depth in the search. For example, if your incoming host was
ags.ou.edu
and there was no specified URI, which made "/" the default path, then your search string would have been
ags.ou.edu/
If then you're doing an EXACT match with the [class lookup ] command, feeding it this pattern, but you only have the following in the data group
ags.ou.edu
then it would never match, as you witnessed. If you then switch to a [class match -value $pattern starts_with datagroup] search, your more generic data group entry matches because the input "ags.ou.edu/" does indeed start with "ags.ou.edu".
The data group entries themselves don't need to be encapsulated in double quotes.