Forum Discussion
Bret_McGinnis_1
Nimbostratus
Apr 28, 2006matchclass
Hi,
Is there a way to tell which entry in the Data Group was matched by the matchclass function.
Regards,
6 Replies
- Colin_Walker_12Historic F5 AccountThe matchclass function should return the value of the record selected from the class by default. If you then log or otherwise display this value, you should see what's selected with each iterration of the command.
Colin - Bret_McGinnis_1
Nimbostratus
Hi,
If I set a variable with the matchclass the variable contains the index into the Data Group. Is there a way to get the entry in the Data Group? Or did I not understand your response.
Example:
class color {
blue
red
white }
set test [matchclass [HTTP::uri] contains $::color]
http://xxx.com/red
The result I get is:
test = 2
What I want is:
test = red
Regards, - Data groups can be treated by TCL lists. To extract a item from a TCL list by index, you can use the lindex command.
when HTTP_REQUEST { set idx [matchclass [HTTP::uri] contains $::color] if { -1 != $idx } { set val [lindex $::color [expr $idx - 1]] log local0. "Found match index = $idx; value = $val" } else { log local0. "Didn't find a match" } }
Keep in mind that the matchclass returns a index based at 1 while the lindex command expects a 0 based index. So, you'll have to throw in a [expr $found -1] to decrement to account for this.
-Joe - Bret_McGinnis_1
Nimbostratus
Hi,
Using your example I came of with this code:
set m_i [matchclass [HTTP::uri] contains $::t_i]
if { $m_i > 0 } {
set r_i [lindex $::t_i [expr $m_i - 1]]
It works fine on 9.1.1 with some hotfixes on a LTM 1500 and 3400.
It fails on a 6400 with 9.1.1 base (no hotfixes).
I get a TCL runtime error:
list element in braces followed by "" instead of space
Any suggestions?
Regards - That most likely was a bug that was fixed in one of your hotfixes. I'm not aware of that issue but there are a few things you could try. I'd try to break apart your rule into smaller elements and see if that makes a difference.
set m_i [matchclass [HTTP::uri] contains $::t_i] if { $m_i > 0 } { set new_index [expr $m_i - 1] set r_i [lindex $::t_i $new_index] }
If that doesn't work, then you'll more than likely need to upgrade your base 9.1.1.
-Joe - unRuleY_95363Historic F5 AccountAccessing a class/datagroup as a Tcl list was definitely broken (with your observed behavior) in 9.1.1 and requires a hotfix.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
