Forum Discussion

Jeff_Morrison_4's avatar
Jeff_Morrison_4
Icon for Nimbostratus rankNimbostratus
Feb 15, 2006

Too iRule???

F5 support suggested that I post my iRule on Devcentral as they felt there were issues with the iRule. Support felt it was to long and that there might be a better solution.

 

 

The purpose of the iRule is so we can migrate from one pool to another pool. Thus, the first list will get smaller in time the second list pointing to the second pool will get larger. Eventually the list will be emiliated once the migration is complete.

 

 

The last rediret is to a ERROR.html that warnings the user to check their URL or contact support.

 

 

Any help would be appreciated!

 

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] contains "/Cust1"

 

or [HTTP::uri] contains "/Cust2"

 

or [HTTP::uri] contains "/Cust3"

 

or [HTTP::uri] contains "/Cust4"

 

or [HTTP::uri] contains "/Cust5"

 

or [HTTP::uri] contains "/Cust6"

 

or [HTTP::uri] contains "/Cust7"

 

or [HTTP::uri] contains "/Cust8"

 

or [HTTP::uri] contains "/Cust9"

 

or [HTTP::uri] contains "/Cust10"

 

or [HTTP::uri] contains "/Cust11"

 

or [HTTP::uri] contains "/Cust12"

 

or [HTTP::uri] contains "/Cust13"

 

or [HTTP::uri] contains "/Cust14"

 

or [HTTP::uri] contains "/Cust15"

 

or [HTTP::uri] contains "/Cust16"

 

 

 

... 17 through 56 omitted to safe space

 

 

 

or [HTTP::uri] contains "/Cust57"}{

 

pool Pool1

 

} elseif { [HTTP::uri] contains "/Cust58"}{

 

pool Pool2

 

} elseif { [HTTP::uri] contains "/Cust59"}{

 

HTTP::redirect https://www.somewebsite.com/

 

} else {

 

HTTP::redirect http://www.somewebsite.com/Error.html

 

}

 

}
  • You could turn timing on to see if your rule is overwhelming the system. Here's an alternative to your rule:

    
    class my_uri {
     "/cust1"
     "/cust2"
     "/cust3"
     "/cust4"
     <--omitted-->
     "/cust57"
    }
    when HTTP_REQUEST {
      if { [matchclass [string tolower [HTTP::uri]] contains $::my_uri] } {
        use pool Pool1
      } elseif { [HTTP::uri] contains "/Cust58"} {
          pool Pool2
      } elseif { [HTTP::uri] contains "/Cust59"} {
          HTTP::redirect https://www.somewebsite.com/
      } else {
          HTTP::redirect http://www.somewebsite.com/Error.html
      }
    }

  • Or... If you wanted to step on the wild side, you could play some fun and games with string manipulation.

    Assuming your uri always starts with "/Custxx" where xx is a number, then Something like this would be much more optimal.

    when HTTP_REQUEST {
       Parsing uri of the format /Custxx/path
      set error 1
      if { [HTTP::uri] starts_with "/Cust" } {
         Set ranges for old and new uris
        set LOW_RANGE_OLD 1
        set HIGH_RANGE_OLD 57
        set LOW_RANGE_NEW 58
        set HIGH_RANGE_NEW 58
         extract characters 5 to end from uri
         ie. xx/path
        set cust_num [string range [HTTP::uri] 5 end]
         Search for possible slash separator in uri
        set slash [string first "/" $cust_num]
        if { -1 != $slash } {
           Slash found so extract all characters up until the slash
          incr slash -1
          set cust_num [string range $cust_num 0 $slash]
        }
         Account for the case of the uri formatted as "/Cust"
        if { "" ne $cust_num } {
           Search range of old customer numbers
           New customer numbers, and customer singles
          if { ($cust_num >= $LOW_RANGE_OLD) && ($cust_num <= $HIGH_RANGE_OLD) } {
            set error 0
            pool Pool1
          } elseif { ($cust_num >= $LOW_RANGE_NEW) && ($cust_num <= $HIGH_RANGE_NEW) } {
            set error 0
            pool Pool2
          } elseif { $cust_num == 59 } {
            set error 0
            HTTP::redirect https://www.somewebsite.com/
          }
        }
      }
      if { 1 == $error } {
        HTTP::redirect http://www.somewebsite.com/Error.html
      }
    }

    *Disclaimer, this rule has not been tested. Also, moving forward, since it was unclear from your initial post what you do with the customer numbers when they move forward you may either need to special cast them (if they go to different uris) or group them in a range.

    If you special case them, then I'd recommend putting them in a string data group and using the findclass method to extract the target paths.

    Good luck!

    -Joe