IRule to select IRule doesn't work even if the condition triggers
Problem Statement:
Trying to create a I-Rule to forward traffic to a pool "pool-troubleshooting" in case a header is passed in a request, the "if" condition triggers as the logs are part of the loop but still the traffic goes to the default pool at Virtual server.
BIG-IP 14.1.2
IRule:
when HTTP_REQUEST {
if { [HTTP::header exists testing] } {
pool pool-troubleshooting
foreach aHeader [HTTP::header names] {
log local0. "Redirecting to troubleshooting pool HTTP REQUEST HEADER $aHeader: [HTTP::header value $aHeader]"
}
}
}
Logs:
Rule troubleshooting-pool <HTTP_REQUEST>: Redirecting to troubleshooting pool HTTP REQUEST HEADER Host: example.com
Rule troubleshooting-pool <HTTP_REQUEST>: Redirecting to troubleshooting pool HTTP REQUEST HEADER User-Agent: curl/7.68.0
Rule troubleshooting-pool <HTTP_REQUEST>: Redirecting to troubleshooting pool HTTP REQUEST HEADER Accept: */*
Rule troubleshooting-pool <HTTP_REQUEST>: Redirecting to troubleshooting pool HTTP REQUEST HEADER testing: True
Rule troubleshooting-pool <HTTP_REQUEST>: Redirecting to troubleshooting pool HTTP REQUEST HEADER TLS-Version: TLSv1.2
Rule troubleshooting-pool <HTTP_REQUEST>: Redirecting to troubleshooting pool HTTP REQUEST HEADER TLS-Cipher: EXXXXX
Any help in troubleshooting will be appreciated. :)
To know what pool was selected, maybe you have lot of pool selection logic or possibly the default may have been selected too, to know what's happening in HTTP_REQUEST, use this,
when HTTP_REQUEST { if { [HTTP::header exists testing] } { log local0. "Pre Pool selected is [findstr [LB::server pool] "" 8 ]" pool pool-troubleshooting foreach aHeader [HTTP::header names] { log local0. "Post Pool selected is [findstr [LB::server pool] "" 8 ]" log local0. "Redirecting to troubleshooting pool HTTP REQUEST HEADER $aHeader: [HTTP::header value $aHeader]" } } }
So if you see your intended pool not selected, you can do this,
when LB_SELECTED { if { [LB::server pool] == "/Common/DEFAULT-POOLNAME-443" && [active_members pool-troubleshooting] > 0 } { pool pool-troubleshooting LB::reselect } }