Cosby_17532
Feb 23, 2011Nimbostratus
Using wildcards with classes
I'm in desperate need of help with an iRule for a customer. They are converting a working 9.x rule to 10.x. In the process we changed it from an array to a class. The class calls an external file with 8998 lines (I know it's rather large). What they are doing is redirecting on the HTTP Response. They read the name from the class and then redirect (301) with the value.
The redirection portion works perfectly. The problem is that the name portion has a lot of wildcard URIs and I can't figure out how to deal with them.
I'm posting a portion of a test data set, the current iRule, and the class commands from the config. I would really appreciate any help I can get.
testdatagroup_file
"/A1/" := "http://192.168.201.250/a.html",
"/A1/*" := "http://192.168.201.250/Athens/a.html",
"/B1/" := "http://192.168.201.250/b.html",
"/B1/*" := "http://192.168.201.250/Boston/b.html",
"/C1/" := "http://192.168.201.250/c.html",
"/C1/*" := "http://192.168.201.250/Chicago/c.html",
"/D1/" := "http://192.168.201.250/d.html",
"/D1/*" := "http://192.168.201.250/Dallas/d.html",
"/E1/" := "http://192.168.201.250/e.html",
"/E1/*" := "http://192.168.201.250/Elvira/e.html",
"/F1/" := "http://192.168.201.250/f.html",
"/F1/*" := "http://192.168.201.250/Franklin/f.html",
"/g/" := "http://192.168.201.250/g.html",
"/g/*" := "http://192.168.201.250/Gulf/g.html",
"/h/" := "http://192.168.201.250/h.html
"/h/*" := "http://192.168.201.250/Hanover/h.html
"/i/" := "http://192.168.201.250/i.html
"/i/*" := "http://192.168.201.250/indigo/i.html
class testdatagroup {
type string
filename "/config/testdatagroup_file"
separator ":="
}
redirectirule
Set debug to non-zero in the events you want to debug
debug levels: 0 - warnings only, 1 - testing, 2 - verbose
WARNING: verbose logging will be enormous with production dataset
when HTTP_REQUEST {
set debug 2
Set data variables
set HTTP_URI [HTTP::uri]
set HTTP_HOST [HTTP::host]
foreach element testdatagroup {
if {[string match -nocase $element $HTTP_URI]}{
log local0.notice "Element $element"
break
}
}
if { $debug > 0 } {log local0.notice "HTTP_URI set to [HTTP::uri] and HTTP_HOST set to [HTTP::host]."}
HTTP Redirect if correct
if { [string tolower ${HTTP_URI}] starts_with "/search?" and [URI::query ${HTTP_URI}] != ""} {
set my_query [URI::query ${HTTP_URI}]
if {$debug > 0} {log local0. "Redirecting ${HTTP_URI} to http://[HTTP::host]/Search/?${my_query}"}
HTTP::redirect "http://[HTTP::host]/Search/?${my_query}"
return
}
}
when HTTP_RESPONSE {
set dgname "testdatagroup"
if { $debug > 0 } {log local0.notice "Data Group: $dgname"}
log local0.notice "URIPATH [URI::path $HTTP_URI]"
set DG_name [class search -name testdatagroup contains $HTTP_URI ]
log local0.notice "DG_name: $DG_name"
if { [string match "\*" "${DG_name}"]} {
set name [class match -name $HTTP_URI starts_with testdatagroup ]
set value [class match -value $HTTP_URI contains testdatagroup]
if { $debug > 0 } {log local0.notice "Name Value: $name"}
} else {
set name [class match -name $HTTP_URI starts_with testdatagroup ]
set value [class match -value $HTTP_URI contains testdatagroup]
if { $debug > 0 } {log local0.notice "Name Value: $name"}
}
set newmap [class search -value testdatagroup equals [class match -name $HTTP_URI starts_with testdatagroup ]]
if { $debug > 0 } {log local0.notice "Redirect: $newmap"}
HTTP::respond 301 Location "$newmap"
}
Once again, I would appreciate any help at all.
Cosby