Forum Discussion
BMARTIN_12200
Nimbostratus
Dec 15, 2008Add Ip member pool in my header browser
Hello, my application is spread over 24 servers JBOSS cluster of 6 pools of 4 members. To facilitate maintenance I would like to appear in the title of the browser the IP address of the member on which it is connected.
I read a lot on the forum but I need a concrete example based on my Irule below. Thank you
Can you help me ?
=================================================
when HTTP_REQUEST timing on {
set electedpool [HTTP::cookie "persist"]
if {"" ne $electedpool} {
if { [active_members HOM_JBOSS_VIP1_POOL_$electedpool] >= 1 } {
pool HOM_JBOSS_VIP1_POOL_$electedpool
} else {
set P [expr ($electedpool+1) %2]
set electedpool ""
pool HOM_JBOSS_VIP1_POOL_$P
}
} else {
set P [expr (int(rand()*1000000))%2]
if { [active_members HOM_JBOSS_VIP1_POOL_$P] >= 1 } {
pool HOM_JBOSS_VIP1_POOL_$P
} else {
set P [expr ($P+1) %2]
pool HOM_JBOSS_VIP1_POOL_$P
}
}
}
when HTTP_RESPONSE timing on {
if {"" eq $electedpool} {
HTTP::cookie remove persist
HTTP::cookie insert name persist value "$P" path /
}
}
- James_Quinby_46Historic F5 AccountI don't have any JBOSS servers around here to test with, but one method of attack might be to use a second iRule to insert the information into the title when there's an HTTP response. This would keep the two activities separate and maybe easier to troubleshoot and such.
- James_Quinby_46Historic F5 AccountThere are, in all likelihood, more elegant ways of doing this, but this works on my lab unit:
when HTTP_REQUEST { Don't allow data to be chunked - override whatever the browser has told us. if { [HTTP::version] eq "1.1" } { if { [HTTP::header is_keepalive] } { HTTP::header replace "Connection" "Keep-Alive" } HTTP::version "1.0" } } when HTTP_RESPONSE { if we know how much we're getting back, grab it all. If we don't know how much we're getting back, grab an arbitrarily long chunk of data that ought to get it all. if { [HTTP::header Content-Type] starts_with "text/html" } { if { [HTTP::header exists "Content-Length"] } { set content_length [HTTP::header "Content-Length"] } else { set content_length 1000000000 } if { $content_length > 0 } { HTTP::collect lets us manipulate the data via the next stanza below. HTTP::collect $content_length } } } when HTTP_RESPONSE_DATA { and now the payoff - a regex substitution of the opening title tag with the tag + the value contained in IP::server_addr. Additional text could be added as well. regsub -all "" [HTTP::payload] " [IP::server_addr]" newdata HTTP::payload replace 0 $content_length $newdata HTTP::release }
- BMARTIN_12200
Nimbostratus
Thank you for your help. - BMARTIN_12200
Nimbostratus
Sorry, your example of Irule works. - hoolio
Cirrostratus
If you wanted to insert text in the response payload, you could use a stream profile and iRule. It would be more efficient than collecting the response. If you can use an HTTP header, that would be more efficient than modifying the payload. The rule would be simple:when HTTP_RESPONSE { HTTP::header insert Server_IP [IP::server_addr] }
- BMARTIN_12200
Nimbostratus
Sorry Aaron, I tried your example - hoolio
Cirrostratus
What doesn't work? If you use a browser plugin like HttpFox for FF or Fiddler for IE, do you see the header in the response? If not, do you see any TCL errors in /var/log/ltm? - James_Quinby_46Historic F5 AccountI should have explained - by "insert a response in the headers", I meant that the LTM would be passing the server IP along with the rest of the HTTP response headers. These are not displayed by the browser or in the page source. To see them, you will need to use one of the plug-ins mentioned by hoolio above.
GET / HTTP/1.1 Host: 10.10.10.30 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Pragma: no-cache Cache-Control: no-cache HTTP/1.x 200 OK Date: Tue, 16 Dec 2008 14:46:23 GMT Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch X-Powered-By: PHP/5.2.4-2ubuntu5.3 Last-Modified: Tue, 09 Dec 2008 14:46:23 GMT Cache-Control: no-cache Content-Length: 4636 Connection: close Content-Type: text/html; charset=utf-8
HTTP/1.x 200 OK Date: Tue, 16 Dec 2008 14:49:45 GMT Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch X-Powered-By: PHP/5.2.4-2ubuntu5.3 Last-Modified: Tue, 09 Dec 2008 14:49:46 GMT Cache-Control: no-cache Content-Length: 4624 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/html; charset=utf-8 Server_IP: 10.10.10.21
- BMARTIN_12200
Nimbostratus
I modified the example of Aaron as below and it works - BMARTIN_12200
Nimbostratus
I set the logs in the example of jquinby.when HTTP_REQUEST { Don't allow data to be chunked - override whatever the browser has told us. if { [HTTP::version] eq "1.1" } { if { [HTTP::header is_keepalive] } { HTTP::header replace "Connection" "Keep-Alive" } HTTP::version "1.0" } } when HTTP_RESPONSE { if we know how much we're getting back, grab it all. If we don't know how much we're getting back, grab an arbitrarily long chunk of data that ought to get it all. if { [HTTP::header Content-Type] starts_with "text/html" } { if { [HTTP::header exists "Content-Length"] } { set content_length [HTTP::header "Content-Length"] } else { set content_length 1000000000 } if { $content_length > 0 } { HTTP::collect lets us manipulate the data via the next stanza below. HTTP::collect $content_length log local0. "CONTENT_LENGTH: $content_length" } } } when HTTP_RESPONSE_DATA { and now the payoff - a regex substitution of the opening title tag with the tag + the value contained in IP::server_addr. Additional text could be added as well. regsub -all "" [HTTP::payload] " [IP::server_addr] " newdata log local0. "NEWDATA: $newdata" log local0. "PAYLOAD: [HTTP::payload]" HTTP::payload replace 0 $content_length $newdata HTTP::release }
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects