Forum Discussion

Kalyan_Reddy_Da's avatar
Kalyan_Reddy_Da
Icon for Nimbostratus rankNimbostratus
Sep 03, 2010

Irule with Datagroup External file is not working. Please help

Hi friends,

 

I am new for writing irules.

 

 

I have a requirement where we have 1000 pools and for each pool users will be accessign with different URI's.

 

 

Example:

 

Pool1 : /uri1

 

Pool2 : /uri2 ... and so on.

 

 

As my pools are growing i can't use a simple Switch case irule with HTTP URI .

 

 

The following is the irule i have written using Data Groups "External File" with Type "String"

 

 

External File

 

-------------

 

 

[admin@server1:Active] config cat dg1

 

"uri1" := "uri1",

 

"uri2" := "uri2",

 

 

Irule

 

-------

 

when HTTP_REQUEST {

 

 

set URIPOD [string tolower [getfield [HTTP::uri] "/" 2] ]

 

log local0. "URIPOD: $URIPOD"

 

 

if { [matchclass $URIPOD equals $::dg1] } {

 

log local0. "In IF Loop"

 

set myPool [findclass $URIPOD $::dg1 " "]

 

log local0. "Pool Name: $myPool"

 

pool $myPool

 

}

 

 

}

 

 

This irule is not checking the values against the external file.

 

 

Please suggest if there is any best way

 

 

I used below irule to ensure it is not checking against external file

 

when HTTP_REQUEST {

 

if {[catch {[set match [matchclass [HTTP::uri] contains $::dg1]]} errmsg]} {

 

log local0. "Fail - $errmsg"

 

} else {

 

if { $match } {

 

log local0. "In IF Loop"

 

} else {

 

log local0. "In ELSELoop"

 

}

 

}

 

}

 

 

 

 

  • The below is version i am using

     

    Kernel:

     

    Linux 2.6.18-164.2.1.el5.1.0.f5app

     

    Package:

     

    BIG-IP Version 10.1.0 3341.1084

     

    Final Edition

     

     

  • First things first I would convert that over to use the new class match syntax to avoid any weirdness you may be experiencing by using $:: in your iRule. I am not an iRule guru by any means, but here is a good post that explains the switch over from matchclass to class match:

     

     

    http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/aft/1172225/afv/topic/aff/5/asg/50/showtab/groupforums/Default.aspx

     

  • So I think it would look like this rewritten:

    when HTTP_REQUEST {
        set URIPOD [string tolower [getfield [HTTP::uri] "/" 2] ]
        if {  [class match -value $URIPOD equals dg1] } {   
            set myPool [class get $URIPOD  dg1 " "]
            pool $myPool
        }
    }
    
    Edit: Added -value and class get
  • Hi Naladar,

     

     

    Thanks a lot for reply.

     

     

    I am getting the follwoing error in ltm log when i try this irule

     

     

     

     

    : TCL error: Payforce - expected boolean value but got "" while executing "if { [class match -value $URIPOD equals kalyan2] } { set myPool [findclass $URIPOD kalyan2 " "] pool $myPool }"

     

     

  • I do not have a version 10.x unit I can test with at the moment, but the wiki page for the class command outlines something almost exactly like what you are looking for if I understand your requirements right. They just go about doing it in a little different way:

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

    The recommend setting up your data group like this:

    /config/app_class.dat:

    "/trxdef/" := "trx_pool",

    "/aaa/" := "aaa_pool",

    "/abscon/" := "abs_pool",

    class app_class {

    type string

    filename app_class.dat

    }

     
       when HTTP_REQUEST {
          set app_pool [class match –value [HTTP::uri] starts_with app_class]
          if {$app_pool ne ""} {
             pool $app_pool
          } else {
             pool default_pool
          }
       }
    }