Forum Discussion
Syntax to Map Virtual-Server's Character with Data-Group which Contains Pool Name
Give this a shot:
when CLIENT_ACCEPTED {
set default_pool [LB::server pool]
log local0. "Default pool [LB::server pool] set"
log local0. "Client IP is [IP::remote_addr]"
}
when HTTP_REQUEST {
switch -glob [string tolower HTTP::uri]] {
"/" {
log local0. "redirecting from /"
HTTP::redirect "http://www.parveez.com"
return
pool pool_parveez.com-http
}
"/iss_static*" {
if { [class match [virtual] equals dg_parveez_static_pools] } {
pool [class match -value [virtual] equals dg_parveez_static_pools]
} else {
log local0. "Static pool entry for [virtual] not created yet"
reject
}
return
}
default {
if { [class match [virtual] equals dg_parveez_dynamic_pools] } {
pool [class match -value [virtual] equals dg_parveez_dynamic_pools]
} else {
log local0. "Dynamic pool entry for [virtual] not created yet"
reject
}
return
}
}
}
I fixed up some of the other syntax and added conditions for the possibility of there not being a data group entry for a given virtual server name (ie. you hadn't created it yet). This will keep the iRule from bombing on a null pool value.
You could also streamline this a little by using the same data group for both. If you put the dynamic pool and the static pool (comma separated) in the same value block, then you can use this value like a list. Example:
apuat.leni2.com-VS-HTTP := pool_apuat_leni2.com_http,pool_confarma1.leni2.com_http
apbuild.leni2.com-VS-HTTP := pool_apbuild.leni2.com_http,pool_confarma2.leni2.com_http
apctdev.leni2.com-VS-HTTP := pool_apctdev.leni2.com_http,pool_confarma3.leni2.com_http
And then your iRule might look like this:
when CLIENT_ACCEPTED {
set default_pool [LB::server pool]
log local0. "Default pool [LB::server pool] set"
log local0. "Client IP is [IP::remote_addr]"
}
when HTTP_REQUEST {
switch -glob [string tolower HTTP::uri]] {
"/" {
log local0. "redirecting from /"
HTTP::redirect "http://www.parveez.com"
return
pool pool_parveez.com-http
}
"/iss_static*" {
if { [class match [virtual] equals dg_parveez_static_pools] } {
pool [lindex [split [class match -value [virtual] equals dg_parveez_static_pools] ","] 1]
} else {
log local0. "Static pool entry for [virtual] not created yet"
reject
}
return
}
default {
if { [class match [virtual] equals dg_parveez_dynamic_pools] } {
pool [lindex [split [class match -value [virtual] equals dg_parveez_dynamic_pools] ","] 0]
} else {
log local0. "Dynamic pool entry for [virtual] not created yet"
reject
}
return
}
}
}
The data group query will return a comma delimited set of values. Example:
dynamic_pool,static_pool
So you'll first split this value on the comma to make a list, and then extract either the first or second element with the lindex command.
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