Forum Discussion
Kent_Perrier_50
Nimbostratus
Mar 16, 2011Data Groups for dummies
Is there an article out there that I can use as a data groups for dummies guide?
Do to a bug in 10.2.0 irule array processing, I need to rewrite an irule to use data groups instead and I have no idea how.
Thanks!
21 Replies
- Michael_Yates
Nimbostratus
I don't think that there are any wiki entries for Data Groups.
These are a couple of discussions about them. There is a good base example in the second link.
v9 Command: matchclass
v10 Command: class match (matchclass is still usable but prevents some new v10 functionality).
http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/afv/topic/aft/1172225/aff/5/showtab/groupforums/Default.aspx
http://devcentral.f5.com/Forums/tabid/1082223/asg/50/showtab/groupforums/afv/topic/aff/5/aft/1176925/Default.aspx
Let me know if this helps. - JRahm
Admin
Colin wrote one a while back: http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/138/iRules-101--08--Classes.aspx Click Here
Definitely reference the class command wiki entry (Click Here) and pay particular attention the formatting of class entries for v10 versus v9. I wish all the documentation sources would pick one name or the other (datagroup versus class).
Maybe I'll write a v9->v10 class converter for internal/external classes. - Kent_Perrier_50
Nimbostratus
Thanks! This information, the v10proxypass iRule, and some searching of devcentral has moved me forward!
I am having a problem that I am hoping I can get another hand with. I have figured out how to access the data group and iterate across it. (Which may or may not be the best way of trying to match a value inside the data group.) Unfortunately the values I get back from the the date group have quotes around them, like this "/foo". I am guessing this is why my code that sets the pool name based on the start of the URI is failing. How do I remove the quotes?
Here is my data group:
/foo := pool1
/bar := pool2
And here is my code:when HTTP_REQUEST { set static::debug "1" set the data group name set clname "AppVersion[virtual name]" log local0. "clname is $clname" set the default pool set default_pool "pool999" log local0. "default_pool set to $default_pool" if there isn't a data group with the above name, set the pool to default and exit if {! [class exists $clname]} { if { $static::debug } { log local0. "Data group $clame not found, using default_pool $default_pool" } pool $default_pool return } iterate over the members of the data group, looking for a context root that matches the start of the URI set searchID [class startsearch $clname] log local0. "search ID is $searchID" while { [class anymore $clname $searchID] } { log local0. "inside the while loop" set list [class nextelement $clname $searchID ] log local0. "list is $list" set foo [split $list] set length [llength $foo] log local0. "foo is $foo" log local0. "length is $length" for {set x 0} {$x<= $length} {incr x} { set value [lindex $foo $x] log local0. "position $x of foo is $value" } set cxt_root [lindex $foo 0] set app_pool [lindex $foo 2] foreach { cxt_root junk app_pool } $foo { log local0. "inside the foreach loop" log local0. "values are cxt_root $cxt_root ; app_pool $app_pool" log local0. "URI is [HTTP::uri]" if the URI starts with the context root from the data class, set the pool if { [HTTP::uri] starts_with $cxt_root} { if { $static::debug } { log local0. "data group values: $cxt_root $app_pool" log local0. "setting pool to $app_pool" } pool $app_pool return } } } we don't match the context roots in the data class pool $default_pool }
I have left some of the code I have started with, but I think you can see where I am going with this. From the commented out for loop, I know that element 0 of the list foo is the URI and element 2 is the pool name, but the quotes around the entries is messing up my if block as /foo/stuff does not start with "/foo"
Any pointers?
Kent - Kent_Perrier_50
Nimbostratus
Well, I have found part of my problem. ;) When I created the data group I used quotes around the values. Once I removed those, the stopped appearing in the syslog debug info. The if statement is still not matching, so I have to figure that out.
Any pointers are welcome! - Kent_Perrier_50
Nimbostratus
I finally got this working. It turns out one of the things I was beating my head against was the data group itself. I had created it with the data group editor inside of the iRule Editor. Looking at it from the web gui, it looked ok, but something was not right as I could not access the data the way I thought I should. After I deleted the existing entries from the gui and reentered them, every thing worked.
Here is what I ended up with. Any coding tips are appreciated!when HTTP_REQUEST { set static::debug "0" set the data group name set clname "AppVersion[virtual name]" set the default pool set default_pool "defpool01" if there isn't a data group with the above name, set the pool to default and exit if {! [class exists $clname]} { if { $static::debug } { log local0. "Data group $clame not found, using default_pool $default_pool" } pool $default_pool return } iterate over the members of the data group, looking for a context root that matches the start of the URI set searchID [class startsearch $clname] while { [class anymore $clname $searchID] } { set list [class nextelement $clname $searchID ] set foo [split $list] set cxt_root [lindex $foo 0] set app_pool [lindex $foo 1] if the URI starts with the context root from the data class, set the pool if { [HTTP::uri] starts_with "$cxt_root"} { if { $static::debug } { log local0. "data group values: $cxt_root $app_pool" log local0. "setting pool to $app_pool" } pool $app_pool return } } we don't match the context roots in the data class if { $static::debug } { log local0. "fell through to the default pool" } pool $default_pool } - hoolio
Cirrostratus
Hi Kent,
That looks like a great start. You don't actually have to iterate through the datagroup manually to do a starts_with comparison. You can use class search to do this:when RULE_INIT { Log debug to /var/log/ltm? 1=yes, 0=no set static::debug 0 } when CLIENT_ACCEPTED { Save the VS default pool name before it's changed set default_pool "defpool01" set the data group name set clname "AppVersion[virtual name]" } when HTTP_REQUEST { if there isn't a data group with the above name, set the pool to default and exit if {[class exists $clname]} { Search the datagroup for a name that starts with the URI set pool_name [class search -value $clname starts_with [HTTP::uri]] if { $pool_name eq ""} { we don't match the context roots in the data class if { $static::debug } { log local0. "fell through to the default pool" } pool $default_pool } else { if { $static::debug } { log local0. "Matched $app_pool" } pool $app_pool } } else { if { $static::debug } { log local0. "Data group $clame not found, using default_pool $default_pool" } pool $default_pool } }
Aaron - Kent_Perrier_50
Nimbostratus
Thanks! - Brian_Thompson
Nimbostratus
I will post a thread in the main but there are ZERO examples of using an external datagroup in the "address" format, there are lots of examples of the string format (key/value pair) but none that I can find of a 10.x compliant address format, and unfortunately I'm stuck with this error:
01070626:3: The IP class external file (/config/addressCLASS) has an invalid format, line: 1. - JRahm
Admin
I've tried every incantation I can think of and I get the same result. Let me do some digging and I'll get back to you. - JRahm
Admin
hoolio suggested I RTFM...sigh.
From 'b class help'
[blockqoute]
type Specifies the type of data want to add to, modify, display, or delete from an external
class. This setting is required for external classes. Specify the type by including a list
of strings, values, or IP addresses. When running the command from the system prompt,
strings must be surrounded by escaped quotation marks. When running the command from the
bigpipe shell, strings must be surrounded by quotation marks (not escaped). A value is a
number that can be either positive or negative. IP addresses can be in any of the following
formats:
-- network mask < ip mask>
-- network prefixlen
-- network /
-- host
[/blockquote]
An example that saved for me:host 192.168.1.1, host 192.168.1.2 := "host2", network 192.168.2.0 mask 255.255.255.0, network 192.168.3.0 mask 255.255.255.0 := "network2", network 192.168.4.0/24 := "network3",
Note that the CIDR notation doesn't seem to work with spaces as shown in the help, at least in my 10.2.1 HF1 version.
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
