Forum Discussion
I don't understand [class match ... nor [class search - pls help
Hi Christian,
the [class] command always compares a given input string with your datagroup entries names. It never uses the data portion of the containing entries for comparsion.
There isn't even an option to do so. There are just options to match the input using a starts_with, ends_with, contains or equals or to control the output of the comparsion (e.g. bolean true/false, data value, etc.). In addition you have to keep in mind that you can't combine starts_with and equals in a single execution nor specify -regex or -glob style patterns to make the search patterns more accurate...
To resolve your issue with the provided [class] functionality, you may want to execute two nested [class] commands. The outer [class] execution will query a equals datagroup and the inner [class] execution will query a starts_with datagroup.
Another option would be to add an additional flag into datagroup result and perform additional checks/actions based on this flag. In this case you could use a single datagroup for both equals and starts_with matches. Below is an example how this could be done...
Datagroup entries:
"equals_searchstring" = "optional_operator target"
"normal_searchstring" = "target"
"/" = "equals /folder/index.html"
"/a" = "/folder/a.html"
"/b" = "/folder/b.html"
"/c" = "/folder/c.html"
iRule Code:
Format of [class match -element] after [join] is "searchstring optional_operator target" or just "searchstring target"
set redirectrule [join [class match -element [HTTP::path] starts_with path_dg]]
Check if the "equals" operator is present
if { [lindex $redirectrule 1] eq "equals" } then {
"equals" operator is present. Compare if datagroup item "equals" HTTP::path
if { [lindex $redirectrule 0 ] eq [HTTP::path] } then {
HTTP::path "equals" entryname. Sending redirect...
set redirectrule [lindex $redirectrule 2]
} else {
HTTP::path does not equals entryname. Skipping redirect...
set redirectrule ""
}
} else {
"equals" operator is not present...
set redirectrule [lindex $redirectrule 1]
}
Hope this helps..
Update: Streamlined the code example and corrected some typos...
Cheers, Kai
Recent Discussions
Related Content
* 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