Forum Discussion

vallesm77_95699's avatar
vallesm77_95699
Icon for Nimbostratus rankNimbostratus
Feb 14, 2012

foreach v11

hello,

 

 

I want to check in dataGroup the correspondence between URI and all records to my DataGroup

 

 

 

foreach entry [class get $ActionBasedOnUrl] {

 

log local0. "$theurl starts_with [getfield $entry " " 1]"

 

if { $theurl starts_with [getfield $entry " " 1]} {

 

set new_len [string length [getfield $entry " " 1]]

 

if {$new_len > $match_len} {

 

set myrow $entry

 

set match_len $new_len

 

}

 

}

 

}

 

 

if { $theurl starts_with [getfield $entry " " 1]} don't work because [getfield $entry " " 1] return always the record with de prefix"{"

 

 

 

 

Tue Feb 14 14:10:11 CET 2012 info tmm tmm[6817] Rule /Common/WLS : / starts_with {/

 

 

 

How to get the record without the prefix " { " ?

 

 

Thanks

 

  • is there anything i missed?

    root@ve1110(Active)(/Common)(tmos) list ltm data-group internal ActionBasedOnUrl
    ltm data-group internal ActionBasedOnUrl {
        records {
            /hungry {
                data go-7-11
            }
            /sleepy {
                data go-home
            }
        }
        type string
    }
    root@ve1110(Active)(/Common)(tmos) list ltm rule myrule
    ltm rule myrule {
        when RULE_INIT {
            log local0. "\[class get ActionBasedOnUrl\]: [class get ActionBasedOnUrl]"
            foreach entry [class get ActionBasedOnUrl] {
                    log local0. "\[getfield $entry \" \" 1\]: [getfield $entry " " 1]"
            }
    }
    }
    
    [root@ve1110:Active] config  cat /var/log/ltm
    Feb 14 06:07:37 tmm info tmm[7321]: Rule /Common/myrule : [class get ActionBasedOnUrl]: {/hungry go-7-11} {/sleepy go-home}
    Feb 14 06:07:37 tmm info tmm[7321]: Rule /Common/myrule : [getfield /hungry go-7-11 " " 1]: /hungry
    Feb 14 06:07:37 tmm info tmm[7321]: Rule /Common/myrule : [getfield /sleepy go-home " " 1]: /sleepy
    
  • thanks for your response.

     

    I see the difference..In my datagroup I don't have values

     

     

    ltm data-group internal /Common/ActionBasedOnUrl {

     

    records {

     

    "/ wls cookie1 pool_internet" { }

     

    "/docs wls cookie2 pool_internet" { }

     

    }

     

    type string

     

    }

     

     

    if I create a new datagroup, example :

     

     

    ltm data-group internal /Common/NEWActionBasedOnUrl {

     

    records {

     

    "/ " {wls cookie1 pool_internet }

     

    "/docs " {wls cookie2 pool_internet }

     

    }

     

    type string

     

    }

     

     

    I can to get the first field without "{"...but If want to get the second field (ex: for first record wls) I have always the "{"

     

     

    (This irules works in V9)

     

  • root@ve1110(Active)(/Common)(tmos) list ltm data-group internal ActionBasedOnUrl
    ltm data-group internal ActionBasedOnUrl {
        records {
            "/ wls cookie1 pool_internet" { }
            "/docs wls cookie2 pool_internet" { }
        }
        type string
    }
    root@ve1110(Active)(/Common)(tmos) list ltm rule myrule
    ltm rule myrule {
        when RULE_INIT {
       set init [class get ActionBasedOnUrl]
       log local0. $init
    
       foreach entry $init {
          log local0. $entry
          foreach item $entry {
             if {$item ne ""} {
                for {set i 0} {$i < [llength $item]} {incr i} {
                   log local0. [lindex $item $i]
                }
             }
          }
       }
    }
    }
    
    [root@ve1110:Active] config  cat /var/log/ltm
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : {{/ wls cookie1 pool_internet} {}} {{/docs wls cookie2 pool_internet} {}}
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : {/ wls cookie1 pool_internet} {}
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : /
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : wls
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : cookie1
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : pool_internet
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : {/docs wls cookie2 pool_internet} {}
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : /docs
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : wls
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : cookie2
    Feb 14 06:59:34 tmm info tmm[7321]: Rule /Common/myrule : pool_internet
    
  • Thank you very much.

     

    Please, can you to explain to me the lines :

     

    for {set i 0} {$i < [llength $item]} {incr i} {

     

    log local0. [lindex $item $i]

     

     

     

    And, after, If want to "recreate" a new variable wich contains on the same line all the values.

     

    ex:

     

     

    varall = / wls cookie1 pool_internet

     

     

    How do you do ?
  • Please, can you to explain to me the lines :

    for {set i 0} {$i < [llength $item]} {incr i} {

    log local0. [lindex $item $i] sorry to confuse you. actually, it is same as foreach loop.

    root@ve1110(Active)(/Common)(tmos) list ltm rule myrule
    ltm rule myrule {
        when RULE_INIT {
       set init [class get ActionBasedOnUrl]
       log local0. "\$init: $init"
    
       foreach entry $init {
          log local0. "\$entry: $entry"
          foreach item $entry {
             if {$item ne ""} {
                log local0. "\$item: $item"
                foreach x $item {
                   log local0. "\$x: $x"
                }
             }
          }
       }
    }
    }
    
    [root@ve1110:Active] config  cat /var/log/ltm
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $init: {{/ wls cookie1 pool_internet} {}} {{/docs wls cookie2 pool_internet} {}}
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $entry: {/ wls cookie1 pool_internet} {}
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $item: / wls cookie1 pool_internet
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $x: /
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $x: wls
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $x: cookie1
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $x: pool_internet
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $entry: {/docs wls cookie2 pool_internet} {}
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $item: /docs wls cookie2 pool_internet
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $x: /docs
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $x: wls
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $x: cookie2
    Feb 14 08:32:49 tmm info tmm[7321]: Rule /Common/myrule : $x: pool_internet
    
  • And, after, If want to "recreate" a new variable wich contains on the same line all the values. iRules 101 - 15 - TCL List Handling Commands by Jason

     

    http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/342/iRules-101--15--TCL-List-Handling-Commands.aspx