Forum Discussion
F_Ducloux_29246
Nimbostratus
Aug 04, 2008iRule help request
Hi Guys, I'm very new at this and I just joined a company that is using F5 BigIPs and i got asked to investigate if I could write a new rule to do this:
I have several virtual servers called
apache1.qa1.ee.com
apache2.qa1.ee.com
apache3.qa1.ee.com
apache1.qa2.ee.com
apache2.qa2.ee.com
apache3.qa2.ee.com
then i have an iRule related to that VS that says
apache1.ee.com
when HTTP_REQUEST {
if { [HTTP::host] contains "qa1" } {
pool apache1.qa1.ee.com
} elseif { [HTTP::host] contains "qa2" } {
pool apache1.qa2.ee.com
}
}
and then again the same thing for apache2.. and i have about 210 virtual servers. with 210 iRules,
is there anyway that i can get the the VS name into a variable then parse it and only get the first part and then use that to create only one rule for all of the servers?
something like this
generic rule
when HTTP_REQUEST {
if { [HTTP::host] contains "qa1" } {
pool $VS.qa1.ee.com
} elseif { [HTTP::host] contains "qa2" } {
pool $VS.qa2.ee.com
}
Thanks
Fernando
5 Replies
- Nicolas_Menant
Employee
Hi,
You can use the virtual command to do so: Click here
Or you can create a datagroup to make an association between a vs name and the destination pool Click here - If you are always triggering off of the second part of the virtual and the mapping is always to apache1."field 2".ee.com, then you can use getfield to extract that value and then dynamically build the pool name
when HTTP_REQUEST { set token [getfield [HTTP::host] "." 2] pool "apache1.$token.ee.com" }
You might want to throw in some error validation to make sure that your generated pool name exists. If it does not, then the iRule will terminate and the connection will be broke.when HTTP_REQUEST { set token [getfield [HTTP::host] "." 2] if { [catch { pool "apache1.$token.ee.com" } ] } { log local0. "Error using pool apache1.$token.ee.com" } else { do some error handling in here. } }
If there isn't a one-to-one mapping, then you'll likely need to go with the findclass/matchclass option of building a lookup table.
Hope this helps...
-Joe - F_Ducloux_29246
Nimbostratus
wow thanks joe!!
that's exactly what i was looking for! - F_Ducloux_29246
Nimbostratus
i forgot to say..
now i can change 250 rules by 10 maybe 15 :D
thanks! - Glad to help! Please feel free to post any questions that come up in the mean time.
-Joe
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects