iRule - A lot of urls with single VIP

Hi gents

I need to create a iRule for multiple urls with single VIP. Could you please let me get your knowledge?

The following is the URL structure.

*.(application)-(environment).test.com

The examples of URLs requested by users are;

test10.test-t10.test.com

test20.test_api-t10.test.com

testbranch11.lab-t10.test.com

testbranch22.lab_api-t10.test.com

The first part of URL like “test10”, “test20” can change anytime.

We have mutiple servers from T10 to T20. More servers(T21, T22…) will be added later

According to the server number, the urls will be like the followings.

[T10]

*.test-t10.test.com

*.test_api-t10.test.com

*.lab-t10.test.com

*.lab_api-t10.test.com

[T11]

*.test-t11.test.com

*.test_api-t11.test.com

*.lab-t11.test.com

*.lab_api-t11.test.com

The other servers(T12 to T20) will provide internet service with the same URL patterns above.

After F5 LTM checks HTTP request, LTM will load balance to a proper pool.

[exmaple]

*.test-t10.test.com ==> Go to pool named “PL_test-t10.test.com”

*.test_api-t10.test.com ==> Go to pool named “PL_test_api-T10.test.com”

*.lab-t10.test.com ==> Go to pool named “PL_lab-t10.test.com”

*.lab_api-t10.test.com ==> Go to pool named “PL_lab_api-t10.test.com”

*.test-t11.test.com ==> Go to pool named “PL_test-t11.test.com”

*.test_api-t11.test.com ==> Go to pool named “PL_test_api-T11.test.com”

*.lab-t11.test.com ==> Go to pool named “PL_lab-t11.test.com”

*.lab_api-t11.test.com ==> Go to pool named “PL_lab_api-t11.test.com”

The other servers from T12 to T20 will be the same load balancing patterns.

I have created a rule for this request. Could you please advise me if this irule works correctly? The main idea of the iRUle is that I do not want to update the iRule when any server is added to the load balancing pool.

[iRule]

when HTTP_REQUEST { if {[scan [string tolower [HTTP::host]] “test-t%2d.test.com” boxnumber] == 1 } { pool “PL_test-T${boxnumber}.test.com” unset boxnumber }

elseif {[scan [string tolower [HTTP::host]] “test_api-t%2d.test.com” boxnumber] == 1 } { pool “PL_test_api-T${boxnumber}.test.com” unset boxnumber }

elseif {[scan [string tolower [HTTP::host]] “lab-t%2d.test.com” boxnumber] == 1 } { pool “PL_lab-T${boxnumber}.test.com” unset boxnumber }

elseif {[scan [string tolower [HTTP::host]] “lab_api-t%2d.test.com” boxnumber] == 1 } { pool “PL_lab_api-T${boxnumber}.test.com” unset boxnumber } }

Hi, You can also use ltm policies (prior 11.4 http classes) instead of an irule to accomplish this

Regards

Michael

Richard,

Like Michael said you can you policies in 11.4 and up.

In an iRule you can do it many ways but using the switch is cleaner and will be more efficient. Something like:

when HTTP_REQUEST {
                set http_host [string tolower [HTTP::host]]
                set pool1 "poola"
                set pool2 "poolb"
                set pool3 "poolc"
                set default "default_pool"
                switch -glob [$http_host] {
                  "*.test.a.com" {
                               pool $pool1
                   }
                   "*.test.b.com" -
                   "b.com" {
                               pool $pool2
                   } 
                   "www.c.com" {
                                pool $pool3
                   }
                   default {
                              pool $default         
                   }
        }
}

Switch: https://devcentral.f5.com/articles/irules-101-04-switch

-Chad