Forum Discussion

Jason_Hook_4092's avatar
Jason_Hook_4092
Icon for Nimbostratus rankNimbostratus
Dec 03, 2009

Looking for peer review on a "simple" iRule

We have a need to direct traffic to different pools based on a header value.

We have a string data group called SysPools with the following entries (here's a couple for example):

001 TTSHE-SysG

013 TTSHE-SysO

015 TTSHE-SysO

030 TTSHE-SysB

This is the iRule on the VIP:

 
 when HTTP_REQUEST { 
  Set the default target pool 
 set defaultTarget "TTSHE-SysD" 
  
 if {[HTTP::header exists "BETAFirm"]} { 
  Set $firm to the value of the header 
 set firm [HTTP::header "BETAFirm"] 
 log local0.info "Set Firm to $firm" 
  Set $target to the pool name from the lookup table 
 set target [findclass $firm $::SysPools " "] 
 log local0.info "Set Target to $target" 
  check for a mismatch resulting in a blank pool name and set to default if blank 
 if { $target eq "" }{ 
 log local0.info "Setting Target to default $defaultTarget" 
 set target $::defaultTarget 
 } 
  Forward request to the set pool 
 log local0.info "Forwarding request to pool $target" 
 pool $target 
 } else { 
  No Header found...send to default pool 
 log local0.info "No Header...Forwarding to default pool $defaultTarget" 
 pool $defaultTarget 
 } 
 } 
 

Comments? I'm looking for a few comments to find out if this is the "best" way to accomplish what I'm trying to do. Is this efficient? Is there a different/better way?

Any/all comments are welcome.

Thank you!

Jason
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi Jason,

     

     

    That looks very good. Which LTM version are you using the rule with? For 9.4.4 and higher, you can remove the $:: prefix from the class name in order to help keep the rule CMP compatible (assuming you're on a hardware platform that supports CMP Click here).

     

     

    Aaron
  • So I can simply change it to this:

     

     

    set target [findclass $firm SysPools " "]

     

     

    v10 and yes, that was thought I had about CMP.

     

     

    thanks!
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Yep. Or you could use the new class (Click here) command. findclass has been deprecated in v10, but will still work in current 10.x versions.

     

     

    Aaron
  • Maybe I'm just reading the Wiki incorrectly, but I change the look up line to:

     

     

    set target [class match -value $firm equals SysPools]

     

     

    and changed the data group values to:

     

     

    001:=TTSHE-SysG

     

    013:=TTSHE-SysO

     

    015:=TTSHE-SysO

     

    030:=TTSHE-SysB

     

     

    and it's not finding a value and drops into the default.

     

     

  • I think I have it...

    data group is back to original space delimited

    when HTTP_REQUEST { 
      Set the default target pool 
     set defaultTarget "TTSHE-SysD" 
      
     if {[HTTP::header exists "BETAFirm"]} { 
      Set $firm to the value of the header 
     set firm [HTTP::header "BETAFirm"] 
     log local0.info "Set Firm to $firm" 
      Set $target to the pool name from the lookup table 
     set pair [class search -name SysPools starts_with $firm] 
     log local0.info "Returned '$pair' pair from search" 
     set target [getfield $pair " " 2] 
     log local0.info "Set Target to '$target' from table" 
      check for a mismatch resulting in a blank pool name and set to default if blank 
     if { $target eq "" }{ 
     log local0.info "Setting Target to default $defaultTarget" 
     set target $::defaultTarget 
     } 
      Forward request to the set pool 
     log local0.info "Forwarding request to pool $target" 
     pool $target 
     } else { 
      No Header found...send to default pool 
     log local0.info "No Header...Forwarding to default pool $defaultTarget" 
     pool $defaultTarget 
     } 
     }

    This works as expected.

    Thank you for your assistance.