Using lsearch with host list
Posted by jay
Hi,
Would like a secondary/tertiary eyes on the following aFlex regarding using lsearch to find a match in a host list:
Virtual service configuration does not have a pool configured in it, just the aFlex. The results are, after requesting host1.mysite.com orhost1test.mysite.com, I get a blank page, no error and the aFlex stats shows this code loading on init, but no failures or successes.
The following works fine as a temporary measure, but the list is what is needed:
So, what has worked for anyone using list/lsearch with HTTP::host?
Cheers!
Jay
Hi,
Would like a secondary/tertiary eyes on the following aFlex regarding using lsearch to find a match in a host list:
Code: |
when RULE_INIT {
set ::host_pool [list "host1" "host1test"]
}
when HTTP_REQUEST {
set HOST [string to lower [HTTP::host]]
set SEARCH_INDEX [lsearch $::host_pool $HOST]
if { $SEARCH_INDEX != -1} {
pool "HOST V212"
}
} |
Virtual service configuration does not have a pool configured in it, just the aFlex. The results are, after requesting host1.mysite.com orhost1test.mysite.com, I get a blank page, no error and the aFlex stats shows this code loading on init, but no failures or successes.
The following works fine as a temporary measure, but the list is what is needed:
Code: |
when HTTP_REQUEST {
if { [HTTP::host] contains "host1" or "host1test" } {
pool "HOST V212"
}
} |
So, what has worked for anyone using list/lsearch with HTTP::host?
Cheers!
Jay
0
Comments
Two little comments on that aFleX.
1. Convert a string to lowercase
The TCL command is "string tolower" (with no space between "to" and "lower")
2. Host comparison
In the aFleX1 (lsearch), you compare the Host from the client "host1.xyz.com" with "host1". Of course they don't match.
In the aFleX2, you check if the Host from the client "host1.xyz.com" contains "host1". Of course they match.
Conclusion:
I can suggest that aFleX (with lsearch) to you:
when RULE_INIT { set ::host_pool [list "host1.xyz.com" "host1test.xyz.com"] } when HTTP_REQUEST { set HOST [string to lower [HTTP::host]] set SEARCH_INDEX [lsearch $::host_pool $HOST] if { $SEARCH_INDEX != -1} { pool "HOST V212" } }
Hi Dimitri,
Thanks for responding.
For 1...auto correct introduced that space between to and lower in this post only, not in the real script. My apologies.
For 2, I've tried this prior to posting and decided to test without the domain. I just posted the last script I tried. Either way, I still come up with a blank page.
The second aFlex was just added to show that the real servers do work.
But, since those are the only issues you saw in my aFlex, then I am to presume that the aFlex scripting is good and I'm to look elsewhere for the failure?
I'll have customer retest.
Thanks!
Jay
What can suggest for your next test is to "add some logs" to know what happens.
Here is a suggestion:
when RULE_INIT { set ::host_pool [list "host1.xyz.com" "host1test.xyz.com"] } when HTTP_REQUEST { set HOST [string to lower [HTTP::host]] log "Host = $Host" set SEARCH_INDEX [lsearch $::host_pool $HOST] if { $SEARCH_INDEX != -1} { log "Host = $Host is in the ::host_pool" pool "HOST V212" } }
The aFlex rules absolutely works via HTTP. When it's used in HTTPS, customer gets the blank pages. When we remove the aFlex and just add a service group, HTTPS seems to work fine. Introduce the aFlex and we get blank pages with exception to using the aFlex with the HTTP VIP.
The failures are showing up as aborts when we see the blank page it looks like
Name Event Type Total Executions Failures Aborts
Host_Based_Redir RULE_INIT 2 0 0
Host_Based_Redir HTTP_REQUEST 49 0 12
Test_Host_Redir HTTP_REQUEST 21 0 1
when RULE_INIT { set ::host_pool [list "host1.xyz.com" "host1test.xyz.com"] } when HTTP_REQUEST { set HOST [string to lower [HTTP::host]] log "Host = $Host" set SEARCH_INDEX [lsearch $::host_pool $HOST] if { $SEARCH_INDEX != -1} { log "Host = $Host is in the ::host_pool" pool "HOST V212" } }
This is because we configured the log command to look for $Host when it did not exist. So, this caused the whole aFlex to not work.
The following did work, when we removed the log command:
when RULE_INIT { set ::host_pool [list "host1.xyz.com" "host1test.xyz.com"] } when HTTP_REQUEST { set HOST [string to lower [HTTP::host]] set SEARCH_INDEX [lsearch $::host_pool $HOST] if { $SEARCH_INDEX != -1} { pool "HOST V212" } }
This code did not work yesterday before I started posting (we tried many variations and nothing worked) yet somehow this afternoon, it started working (after removing my syntax mistakes from the log command).
Thanks for your help Dimitri
Wanted to post final findings. Reason why the indicated aFlex didn't seem to work was because the units kept failing over back and forth. Reason for this is in the current release of 2.6.1-p1 up to sp3, if a Virtual Port configuration includes an aFlex, but no Service Group, whenever the Virtual Port is accessed, a failover occurs. Product Support has told me that a fix will come in 2.6.1-p2 mid September.