Forum Discussion

John's avatar
John
Icon for Altostratus rankAltostratus
Apr 19, 2011

Issue with classes with only one item and [class get datagroupname[

Ok, I'm having an issue with an irule using the [class get ]. If my class is defined with only one item, the class get command will return two items. Is it counting a null value as an item? Tried on 10.2.1 Build 297 final and 10.2.1 Build 496 HF2.

 

 

iRule:

 

when HTTP_REQUEST {

 

set clientRequestedURI [string tolower [HTTP::uri]]

 

 

how many items

 

log "size = [class size john-test-group]"

 

 

iterate through class

 

foreach {element} [class get john-test-group] {

 

log "url=$clientRequestedURI element=$element"

 

}

 

}

 

 

 

My class from bigip.conf:

 

class john-test-group {

 

"item1"

 

}

 

 

Output:

 

Rule john-test-data-group : size = 1

 

Rule john-test-data-group : url=/dns.html element=item1

 

Rule john-test-data-group : url=/dns.html element=

 

 

 

Class with > 2 items (odd that it adds extra "{}" in the bigip.conf):

 

class john-test-group {

 

{

 

"item1"

 

"item2"

 

}

 

}

 

Rule john-test-data-group : size = 2

 

Rule john-test-data-group : url=/dns.html element=item1 {}

 

Rule john-test-data-group : url=/dns.html element=item2 {}

 

 

 

 

Even with values defined, gives same result, except the value does show up as the second item when class with one item:

 

 

 

class john-test-group {

 

"item1"

 

}

 

Rule john-test-data-group : size = 1

 

Rule john-test-data-group : url=/dns.html element=item1

 

Rule john-test-data-group : url=/dns.html element=

 

 

 

class john-test-group {

 

{

 

"item1" { "value1" }

 

"item2" { "value2" }

 

}

 

}

 

Rule john-test-data-group : size = 2

 

Rule john-test-data-group : url=/dns.html element=item1 value1

 

Rule john-test-data-group : url=/dns.html element=item2 value2

 

 

 

Second oddity, if the string has spaces, one list item is not enclosed in {} in log:

 

 

class john-test-group {

 

"item1 sub1-1 sub1-2"

 

}

 

Rule john-test-data-group : size = 1

 

Rule john-test-data-group : url=/dns.html element=item1 sub1-1 sub1-2

 

Rule john-test-data-group : url=/dns.html element=

 

 

class john-test-group {

 

{

 

"item1 sub1-1 sub1-2"

 

"item2 sub2-1 sub2-2"

 

}

 

}

 

Rule john-test-data-group : size = 2

 

Rule john-test-data-group : url=/dns.html element={item1 sub1-1 sub1-2} {}

 

Rule john-test-data-group : url=/dns.html element={item2 sub2-1 sub2-2} {}

 

 

 

 

Any ideas?

 

 

thanks

 

john

 

 

2 Replies

  • Hi John,

     

     

    Post 10.1, the value is always implied even if it's not set. You can use -name to get the name or -value to get the value. To get the first element name of a datagroup, you can use class element -name. Likewise to get the first value: class element -value.

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/class

     

     

    Aaron
  • John's avatar
    John
    Icon for Altostratus rankAltostratus
    hmmm, doesn't seem consistent. a "class size" gives 1, but a "class get" gives 2. So if I want to iterate a list I can't use "class get"? Or I have to put a conditional if count >2, then use get? Or should I be using search?

     

     

     

    class get [-nocase] []

     

     

    Returns a list containing the names or a list of the name and value currently found in .

     

    An optional may be specified to restrict the list to names that match the Tcl glob pattern. Additionally, the switch -nocase may be specified to enable case-insensitive pattern matching.

     

    This command provides a way to access the class as a Tcl list similar to previously access the global variable named the same as the list.