Forum Discussion
irule to distribute based on user agent
Hello ;
could you please help me creating irule to send traffic to specific pool if its comes from IE6,7 and 8 and rest to default pool .
Your kind assistance is highly appreciated.
mbamusa
17 Replies
- nitass
Employee
e.g.
Virtual server with multiple pools - distribute based on browser types
https://devcentral.f5.com/questions/virtual-server-with-multiple-pools-distribute-based-on-browser-types- mbamusa_59409
Nimbostratus
thank you for your reply . i created the following (can we combine the first 3 conditions in 1 using OR). when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" }{ pool Pool1 } elseif {[string tolower [HTTP::header User-Agent]] contains "msie7" }{ pool Pool } elseif {[string tolower [HTTP::header User-Agent]] contains "msie8" }{ pool Pool1 }else { pool Pool2 } } - nitass
Employee
you can use "or" e.g. if { [...] or [...] or [...] } { - mbamusa_59409
Nimbostratus
will this work ? when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" or "msie7" or "msie8"}{ pool Pool1 }else { pool Pool2 } }
- nitass_89166
Noctilucent
e.g.
Virtual server with multiple pools - distribute based on browser types
https://devcentral.f5.com/questions/virtual-server-with-multiple-pools-distribute-based-on-browser-types- mbamusa_59409
Nimbostratus
thank you for your reply . i created the following (can we combine the first 3 conditions in 1 using OR). when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" }{ pool Pool1 } elseif {[string tolower [HTTP::header User-Agent]] contains "msie7" }{ pool Pool } elseif {[string tolower [HTTP::header User-Agent]] contains "msie8" }{ pool Pool1 }else { pool Pool2 } } - nitass_89166
Noctilucent
you can use "or" e.g. if { [...] or [...] or [...] } { - mbamusa_59409
Nimbostratus
will this work ? when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" or "msie7" or "msie8"}{ pool Pool1 }else { pool Pool2 } }
- Kevin_Stewart
Employee
Try:
when CLIENT_ACCEPTED { set default_pool [LB::server pool] } when HTTP_REQUEST { if { [string tolower [HTTP::header User-Agent]] contains "blah" } { pool ms_pool } else { pool $default_pool } }Change "blah" to a unique value in the IE User-Agent header, and change ms_pool to the name if your MS pool.
- nitass_89166
Noctilucent
will this work ? when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" or "msie7" or "msie8"}{ pool Pool1 }else { pool Pool2 } }
you have to repeat [string tolower [HTTP::header User-Agent]] (or set it to variable first and re-use it later) in if-condition.
e.g.
set uagent [string tolower [HTTP::header User-Agent]] if { $uagent contains "msie6" or $uagent contains "msie7" or $uagent contains "msie8"} {or you may use switch instead of if-condition.
e.g.
[root@ve11a:Active:Not All Devices Synced] config tmsh list ltm rule myrule ltm rule myrule { when HTTP_REQUEST { switch -glob [HTTP::header value "User-Agent"] { "*MSIE 6*" - "*MSIE 7*" - "*MSIE 8*" { pool qux } default { pool [LB::server pool] } } } }- mbamusa_59409
Nimbostratus
Thank you Nitass , is the below OK ? set uagent [string tolower [HTTP::header User-Agent]] if { $uagent contains "msie6" or $uagent contains "msie7" or $uagent contains "msie8"}{ pool Pool1 } else { pool Pool2 } } - nitass_89166
Noctilucent
it looks okay to me. - Colin_Walker_12Historic F5 AccountThat looks logically sound to me, but you might want to think about using a switch statement, as nitass showed above, if you start expanding it to include any more options for User-Agent. The or conditional forces iRules to effectively run multiple if comparisons, one for each or clause, and after a handful of those you'll start seeing switch perform more efficiently. Not to mention switch is way prettier to look at, and we all like pretty code, right? Right. Colin
- nitass
Employee
will this work ? when HTTP_REQUEST { if {[string tolower [HTTP::header User-Agent]] contains "msie6" or "msie7" or "msie8"}{ pool Pool1 }else { pool Pool2 } }
you have to repeat [string tolower [HTTP::header User-Agent]] (or set it to variable first and re-use it later) in if-condition.
e.g.
set uagent [string tolower [HTTP::header User-Agent]] if { $uagent contains "msie6" or $uagent contains "msie7" or $uagent contains "msie8"} {or you may use switch instead of if-condition.
e.g.
[root@ve11a:Active:Not All Devices Synced] config tmsh list ltm rule myrule ltm rule myrule { when HTTP_REQUEST { switch -glob [HTTP::header value "User-Agent"] { "*MSIE 6*" - "*MSIE 7*" - "*MSIE 8*" { pool qux } default { pool [LB::server pool] } } } }- mbamusa_59409
Nimbostratus
Thank you Nitass , is the below OK ? set uagent [string tolower [HTTP::header User-Agent]] if { $uagent contains "msie6" or $uagent contains "msie7" or $uagent contains "msie8"}{ pool Pool1 } else { pool Pool2 } } - nitass
Employee
it looks okay to me. - Colin_Walker_12Historic F5 AccountThat looks logically sound to me, but you might want to think about using a switch statement, as nitass showed above, if you start expanding it to include any more options for User-Agent. The or conditional forces iRules to effectively run multiple if comparisons, one for each or clause, and after a handful of those you'll start seeing switch perform more efficiently. Not to mention switch is way prettier to look at, and we all like pretty code, right? Right. Colin
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com