Forum Discussion
irules optimization
Hi,
I am trying to optimize the irules below (to a for each loop, if possible) im modifying and need some programming help 🙂
if { ([HTTP::host] contains "env-1") || ([HTTP::host] contains "1.1.1.1") } {
log local0. "ENV-1, HEADER=[HTTP::header Host], URI=[HTTP::uri]"
set AA_pool env-1_AA_11
set BB_pool env-1_BB_88
elseif { ([HTTP::host] contains "env-2") || ([HTTP::host] contains "1.1.1.2") } {
log local0. "ENV-2, HEADER=[HTTP::header Host], URI=[HTTP::uri]"
set AA_pool env-2_AA_22
set BB_pool env-2_BB_88
elseif { ([HTTP::host] contains "env-3") || ([HTTP::host] contains "1.1.1.3") } {
log local0. "ENV-3, HEADER=[HTTP::header Host], URI=[HTTP::uri]"
set AA_pool env-3_AA_33
set BB_pool env-3_BB_88
elseif......til env-10
Is that possible ?? Thanks in advance.
can you try something like this?
when HTTP_REQUEST { switch -glob [HTTP::host] { "*env-1" - "1.1.1.1*" { Do something } "*env-2*" - "1.1.1.2*" { Do something } default { Do something } } }
- nitass_89166Noctilucent
can you try something like this?
when HTTP_REQUEST { switch -glob [HTTP::host] { "*env-1" - "1.1.1.1*" { Do something } "*env-2*" - "1.1.1.2*" { Do something } default { Do something } } }
- annielee_13548Nimbostratusjust tried.. when the HTTP::host = 1.1.1.1, it works but not env-1, we need if the HTTP:host is env-1 or 1.1.1.1, then do the same thing.. (which is setting the pool variable accordingly)
- nitassEmployee
can you try something like this?
when HTTP_REQUEST { switch -glob [HTTP::host] { "*env-1" - "1.1.1.1*" { Do something } "*env-2*" - "1.1.1.2*" { Do something } default { Do something } } }
- annielee_13548Nimbostratusjust tried.. when the HTTP::host = 1.1.1.1, it works but not env-1, we need if the HTTP:host is env-1 or 1.1.1.1, then do the same thing.. (which is setting the pool variable accordingly)
- nitassEmployee
when the HTTP::host = 1.1.1.1, it works but not env-1, we need if the HTTP:host is env-1 or 1.1.1.1, then do the same thing
sorry i missed one asterisk after env-1. can you try one more time?
when HTTP_REQUEST { switch -glob [HTTP::host] { "*env-1*" - "1.1.1.1*" { Do something } "*env-2*" - "1.1.1.2*" { Do something } default { Do something } } }
- annielee_13548Nimbostratusnow it works ! (thanks) but is that the better irules than for each ? (if there is any) ?
- nitass_89166Noctilucent
when the HTTP::host = 1.1.1.1, it works but not env-1, we need if the HTTP:host is env-1 or 1.1.1.1, then do the same thing
sorry i missed one asterisk after env-1. can you try one more time?
when HTTP_REQUEST { switch -glob [HTTP::host] { "*env-1*" - "1.1.1.1*" { Do something } "*env-2*" - "1.1.1.2*" { Do something } default { Do something } } }
- annielee_13548Nimbostratusnow it works ! (thanks) but is that the better irules than for each ? (if there is any) ?
- nitass_89166Noctilucent
but is that the better irules than for each ? (if there is any) ?
i think it is better but you may evaluate it.
iRules Optimization 101 - 05 - Evaluating iRule Performance by Deb Allen
- annielee_13548Nimbostratusthanks for the link, will try to 'evaluate' the irules.. and also thanks for making my irules better :-)
- nitassEmployee
but is that the better irules than for each ? (if there is any) ?
i think it is better but you may evaluate it.
iRules Optimization 101 - 05 - Evaluating iRule Performance by Deb Allen
- annielee_13548Nimbostratusthanks for the link, will try to 'evaluate' the irules.. and also thanks for making my irules better :-)
- annielee_13548Nimbostratus
can i ask can the below exist ? multiple switch -glob
when HTTP_REQUEST { switch -glob [HTTP::host] { "*env-1" - "1.1.1.1*" { Do something } "*env-2*" - "1.1.1.2*" { Do something } default { Do something } switch -glob [HTTP::uri] { "aaa" do AAA } }
- nitassEmployee
can i ask can the below exist ? multiple switch -glob
if you mean something like this, yes.
when HTTP_REQUEST { switch -glob [HTTP::host] { "*env-1*" - "1.1.1.1*" { Do something } "*env-2*" - "1.1.1.2*" { Do something } default { switch -glob [string tolower [HTTP::uri]] { "*aaa*" { Do something } default { Do something } } } } }
- annielee_13548Nimbostratusnot really.. coz in the existing irules now, there are a lot of IFs and some ifs are comparing the URI (with equals, ends with, contains), some comparing variables, some comparing headers. I would like to modify the rules to be 'better', hence you recommended the switch -glob
- nitass_89166Noctilucent
can i ask can the below exist ? multiple switch -glob
if you mean something like this, yes.
when HTTP_REQUEST { switch -glob [HTTP::host] { "*env-1*" - "1.1.1.1*" { Do something } "*env-2*" - "1.1.1.2*" { Do something } default { switch -glob [string tolower [HTTP::uri]] { "*aaa*" { Do something } default { Do something } } } } }
- annielee_13548Nimbostratusnot really.. coz in the existing irules now, there are a lot of IFs and some ifs are comparing the URI (with equals, ends with, contains), some comparing variables, some comparing headers. I would like to modify the rules to be 'better', hence you recommended the switch -glob
- nitassEmployee
coz in the existing irules now, there are a lot of IFs and some ifs are comparing the URI (with equals, ends with, contains), some comparing variables, some comparing headers. I would like to modify the rules to be 'better', hence you recommended the switch -glob
i do not think switch is always the best. you do not need to change all condition check to switch. it should be pretty fine as long as irule is easy to understand and maintain.
Comparing iRule Control Statements by Joe Pruitt
just my 2 cents.
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