Forum Discussion
Lee_Sutcliffe
Nov 01, 2017Nacreous
Ok, so I've taken another look at this as sounds like you want to have a default redirect in the event the pool member (and therefore the VIP is down). It was starting to get messy with nested 'if' statements within the switch. Also there was a lot of repetition so thought using a loop may be better, rather than adding more conditions.
I've put your redirects and pool details for each region in a datagroup and added them to an array so that the variable can be used in the loop. I've tested the syntax but not the functionality
Please leave feedback
DATAGROUP:
ltm data-group internal geo_dg {
records {
NA {
data "POOL my_NA_pool|URL http://app-NA.abc.com"
}
EU {
data "POOL my_EU_pool|URL http://app-EMEA.abc.com"
}
AS {
data "POOL my_AS_pool|URL http://app-APAC.abc.com"
}
SA {
data "POOL my_SA_pool|URL http://app-NA.abc.com"
}
AF {
data "POOL my_AF_pool|URL http://app-EMEA.abc.com"
}
OC {
data "POOL my_AF_pool|URL http://app-APAC.abc.com"
}
}
type string
}
IRULE:
when HTTP_REQUEST {
set dgLocation geo_dg
set regions {NA EU AS SA AF OC}
set ipLocation [whereis [IP::client_addr] continent]
set defaultRedirect "http://app-NA.abc.com"
if {[HTTP::path] eq "/" } {
check GeoLocation matches what is defined in the datagroup
if {[class match $ipLocation equals $dgLocation]} {
loop through the regions in the list
foreach region $regions {
create array based on DG values
array set geoArray [split [string trim [class lookup $region $poolDg]] "|"]
check for active members
if { [active_members $geoArray(POOL)] >= 1 } {
HTTP::redirect $geoArray(URL)
} else {
default redirect if pool is down
HTTP::redirect $defaultRedirect
}
array unset geoArray
}
} else {
default redirect if GeoLocation doesn't match datagroup
HTTP::redirect $defaultRedirect
}
}
}