Add 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 /

}

}

I 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.

There 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      
        
      }

Another method would simply be to pass the server IP in a special HTTP header. This would be much lighter weight, but obviously not as easy to look at.

(updated with some cleanup and comments)

Thank you for your help.

I added a Irule with your script and added as a second rule in the resource pool.

I tested but the title I have not changed.

Could you give me an example of another method would simply be to pass the server IP in a special HTTP header.

This is my header below:

======================================================

Poste de travail TOTO

=====================================================

Sorry, your example of Irule works.

Only when I connect, I have a first html page and secondary that opens automatically.

The JBoss server address is displayed in the windows secondary but not in the first.

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] 
 }

Aaron

Sorry Aaron, I tried your example

when HTTP_RESPONSE {

HTTP::header insert Server_IP [IP::server_addr]

}

but I can not make it work

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?

Aaron

I 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.

In a normal transaction, the headers will look something like this:

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

The first set of headers is sent by the browser, the second is the set of responses from the webserver. hoolio’s iRule adds the server IP to the server response headers as follows:

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

I modified the example of Aaron as below and it works

when HTTP_REQUEST_SEND {

log local0. “server addr: [IP::server_addr]”

log local0. “server port: [TCP::server_port]”

clientside { HTTP::header replace Host [IP::server_addr] }

}

thank you

I set the logs in the example of jquinby.

I see an error when running the command HTTP::payload replace. Below errors and attached the log

Dec 16 16:22:49 tmm tmm[1537]: 01220001:3: TCL error: Rule irule_set_ip_member_pool_in_title_browser

- Out of bounds (line 1) invoked from within "HTTP::payload replace 0 $content_length $newdata "

and

Dec 16 16:22:49 tmm tmm[1537]: 01220001:3: TCL error: Rule irule_set_ip_member_pool_in_title_browser

- Out of bounds (line 1) invoked from within "HTTP::payload replace 0 $content_length $newdata "

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       
 }

Interesting - I don’t see any errors. All I get are the following lines:

Dec 16 10:25:57 bigip tmm tmm[PID]: Rule temp : CONTENT_LENGTH: 4624   
   Dec 16 10:25:57 bigip tmm tmm[PID]: Rule temp : NEWDATA: (then a whole lot of stuff follows)

What version of code are you running on your LTM?

If you want to insert text in the response content, you could use a stream profile and iRule to configure it. You can use this rule by adding a blank stream profile to the VIP and a custom HTTP profile with Response Chunking set to Rechunk.

when HTTP_RESPONSE { 
  
     Check if response type is text 
    if {[HTTP::header value Content-Type] contains "text"}{ 
  
        Replace  with 1.1.1.1 where 1.1.1.1 is the server IP adddress 
       STREAM::expression "@<\[Tt\]\[Ii\]\[Tt\]\[Ll\]\[Ee\]>@[IP::server_addr] - @" 
  
        Enable the stream filter for this response only 
       STREAM::enable 
  
    } else { 
  
        Response wasn't text, so disable the stream filter 
       STREAM::disable       
    } 
 } 
 when STREAM_MATCHED { 
  
      This event can is for debug only and can be removed once testing is complete 
     log local0. "Matched: [STREAM::match]" 
 }

I’d guess the TCL error with the payload replace is occurring when the response size is over 1Mib and the collection is being limited to just a portion of the response payload.

Aaron

The stream profile approach is much better. That’s where I went first, but somehow couldn’t get IP::server_addr evaluated rather than simply displayed as a string.

…also, you might consider substituting LB::server for IP::server_addr. This would display the pool name, IP and port of the server, and might be useful if you have more than one jboss instance running on each node.

Thank you very much for your help hoolio and jquinby , the solution stream profile suits me. I have just one last question:

Are there any disadvantages to validate the stream profile in the virtual server configuration.

jquinby, if you wrap the stream expression in curly braces, the commands inside are interpreted literally and aren’t executed. Using double quotes allows for execution, but then you have to escape the square braces in the regex components to prevent them from being executed.

Bruno, are you asking if there is any downside to using a stream profile (without an iRule)? The reason you’d want to use an iRule to configure the stream filter is that you can explicitly enable it only for responses and only for text content. If that’s not what you’re asking, can you explain again?

Thanks,

Aaron

I’m sorry but I encounter a problem with the establishment of the “stream filter”.

The display of my page worked well but now the images are not displayed and all is white.

When I withdraw the rule and I repositions the stream profile to none everything works??

Below this error

Dec 17 15:37:22 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:22 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:22 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:22 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:22 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:23 tmm tmm[1537]: 011f0007: repeated 25 times

Dec 17 15:37:40 tmm tmm[1537]: Rule irule_REC_JBOSS_VIP4_SET_TITLE_BROWSER : Matched:

Dec 17 15:37:41 tmm tmm[1537]: Rule irule_REC_JBOSS_VIP4_SET_TITLE_BROWSER : Matched:

Dec 17 15:37:41 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:41 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:42 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:42 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:42 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:42 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:44 tmm tmm[1537]: 011f0007: repeated 55 times

Dec 17 15:37:44 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_BODY_COMPLETE during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:44 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_BODY_COMPLETE during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:44 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:44 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:44 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_EGRESS_DATA during ST_HTTP_PREPEND_HEADERS

Dec 17 15:37:47 tmm tmm[1537]: 011f0007: repeated 9 times

Which LTM version are you running? You might consider opening a case with F5 Support as there doesn’t seem to be a simple explanation for this error when using a stream profile.

Aaron

I set a record after

STREAM:: expression “@ <\[Tt\]\[Ii \]\[Tt\]\[Ll\]\[Ee\]>@ [IP: server_addr] - @”

local0 log. “@ <\[Tt\]\[Ii\]\[Tt\]\[Ll\]\[Ee\]>@ [IP: server_addr] - @”

and I see that I began two lines with two members of my pool

Dec 17 16:40:46 tmm tmm[1537]: Rule irule_SET_NVIP_BROWSER : @<[Tt][Ii][Tt][Ll][Ee]>@10.242.81.157 - @

Dec 17 16:40:46 tmm tmm[1537]: Rule irule_SET_NVIP_BROWSER : @<[Tt][Ii][Tt][Ll][Ee]>@10.242.81.156 - @

Dec 17 16:40:46 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_BODY_COMPLETE during ST_HTTP_PREPEND_HEADERS

Dec 17 16:40:46 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_BODY_COMPLETE during ST_HTTP_PREPEND_HEADERS

Dec 17 16:40:46 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_BODY_COMPLETE during ST_HTTP_PREPEND_HEADERS

Dec 17 16:40:46 tmm tmm[1537]: 011f0007:3: http_process_state_prepend - Invalid action EV_BODY_COMPLETE during ST_HTTP_PREPEND_HEADERS

Dec 17 16:40:47 tmm tmm[1537]: 011f0007: repeated 26 times