Forum Discussion
Irule Integration
Hi guys,
I have this irule:
when HTTP_REQUEST {
switch [HTTP::cookie hectorlbhkg] { - - {
pool [HTTP::cookie hectorlbhkg]
set selected ""
}
default {
set rand [expr { rand() }]
if { ($rand < .33) and ([active_members www.hector.com_cluster_2a] >= 3) } {
pool www.hector.com_cluster_2a
set selected www.hector.com_cluster_2a
} elseif { ($rand < .66) and ([active_members www.hector.com_cluster_2b] >= 3) } {
pool www.hector.com_cluster_2b
set selected www.hector.com_cluster_2b
} elseif {([active_members www.hector.com_cluster_2c] >= 3)} {
pool www.hector.com_cluster_2c
set selected www.hector.com_cluster_2c
}
}
} } when HTTP_RESPONSE { if {$selected ne ""}{ HTTP::cookie insert name hectorlbhkg value $selected path "/" } }
And I have created this one:
when HTTP_REQUEST { if { [string tolower [HTTP::header User-Agent]] contains “msie7” or "msie8" } { pool } }
Is there a way I can integrate in to one without having to create them separately?
Cheers
1 Reply
- Stanislas_Piro2
Cumulonimbus
Hi,
your "new" irule is not working.
The condition must be:
([string tolower [HTTP::header User-Agent]] contains "msie7") or ([string tolower [HTTP::header User-Agent]] contains "msie8")And you can optimize the irule like that:
when RULE_INIT { array set static::pools { 0 "www.hector.com_cluster_2a" 1 "www.hector.com_cluster_2b" 2 "www.hector.com_cluster_2c" } } when HTTP_REQUEST { if { ([string tolower [HTTP::header User-Agent]] contains "msie7") or ([string tolower [HTTP::header User-Agent]] contains "msie8") } { pool www.hector.com_cluster_2k } elseif { [info exists static::pools([HTTP::cookie hectorlbhkg])]} { pool $static::pools([HTTP::cookie hectorlbhkg]) } else { set PoolID [expr { int(rand()*[array size static::pools])}] while { [info exists static::pools($PoolID)] } { log local0. $PoolID if { ([active_members $static::pools($PoolID)] >= 3) } { pool $static::pools($PoolID) set selected $static::pools($PoolID) break } else {incr PoolID} } } } when HTTP_RESPONSE { if {[info exists selected]}{ HTTP::cookie insert name hectorlbhkg value $selected path "/" } }The random value is an integer between 0 and the size of the static array. Adding a new entry in the array will apply without any change in the irule.
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