Forum Discussion

zipperbox_11405's avatar
zipperbox_11405
Icon for Nimbostratus rankNimbostratus
Jan 14, 2013

Mulitple URL Replace and stream profile

I have a case where the internal naming of multiple servers have to be replaced by a single FQDN. I am succesful when dealing with one instance but not with many. Here is my current iRule, note: it seems to never hit on the second object.

 

when HTTP_RESPONSE {

 

 

if { [HTTP::is_redirect]} {

 

HTTP::header replace Location "[string map -nocase [list inside1.net fqdn.com] [HTTP::header value Location]]"

 

} else {

 

 

HTTP::header replace Location "[string map -nocase [list inside2.net fqdn.com] [HTTP::header value Location]]"}

 

}

 

 

Also; I have a stream profile applied to the VIP:

 

Source is blank.

 

Target: @inside1.net@fqdn.com@ @inside2.net@fqdn.com@

 

Any help would be much appreciated!

 

 

 

 

18 Replies

  • So here's a quick update...

     

     

    For clarity, I need:

     

    inside1.net to be replaced by fqdn.com

     

    inside2.net to be replaced by fqdn.com

     

    inside3.net to be replaced by fqdn.com

     

    etc..

     

     

    This irule (below) is successful but for whatever reason I can only get it to do one header replace at a time, rather then several, which is the objective.

     

     

    when HTTP_RESPONSE {

     

    log local1. "============================================="

     

    log local1. "$LogString (response) - status: [HTTP::status]"

     

    foreach aHeader [HTTP::header names] {

     

    log local1. "$aHeader: [HTTP::header value $aHeader]"

     

    }

     

    log local1. "============================================="

     

    if { [HTTP::is_redirect] } {

     

    HTTP::header replace Location "[string map -nocase [list http%3A%2F%2Finside2.net http%3A%2F%2Ffqdn.com] [HTTP::header value Location]]"

     

     

    See logs (successful)

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : =============================================

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Cookie: JSESSIONID=EE9C8FB6F1E9DB6B9A3E3CDB08446EC0

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Pragma: no-cache

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : X-Xorwarded-For: 00.000.000.000

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Cache-Control: no-cache, max-age=259200

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Connection: close

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : =============================================

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : =============================================

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : =============================================

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Client 121.122.122.122%6:31772 -> fqdn.com/scorm_launch/redirector?url=http%3A//inside2.net%3A80/Saba/AICCReporter%3FscormSessionKey%3DEE9C8FB6F1E9DB6B9A3E3CDB08446EC0%26sitename%3DSabaSite%26lms_data%3D%25253BconformanceLevel%25253D0%26cmi_entry%3Daireg000000000006535aises000000000002167&debug=false (response) - status: 200

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Date: Thu, 17 Jan 2013 14:53:27 GMT

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Server: Microsoft-IIS/6.0

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Connection: close

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Content-Type: text/plain

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : =============================================

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : =============================================

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Client 121.122.122.122%6:31772 -> fqdn.com/scorm_launch/redirector?url=http%3A//inside2.net%3A80/Saba/AICCReporter%3FscormSessionKey%3DEE9C8FB6F1E9DB6B9A3E3CDB08446EC0%26sitename%3DSabaSite%26lms_data%3D%25253BconformanceLevel%25253D0%26cmi_entry%3Daireg000000000006535aises000000000002167&debug=false (response) - status: 200

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Date: Thu, 17 Jan 2013 14:53:27 GMT

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Server: Microsoft-IIS/6.0

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Connection: close

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Client 121.122.122.122%6:31772 -> fqdn.com/scorm_launch/redirector?url=http%3A//inside2.net%3A80/Saba/AICCReporter%3FscormSessionKey%3DEE9C8FB6F1E9DB6B9A3E3CDB08446EC0%26sitename%3DSabaSite%26lms_data%3D%25253BconformanceLevel%25253D0%26cmi_entry%3Daireg000000000006535aises000000000002167&debug=false (response) - status: 200

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Date: Thu, 17 Jan 2013 14:53:27 GMT

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Server: Microsoft-IIS/6.0

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Connection: close

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Content-Type: text/plain

     

    Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : =============================================

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Content-Type: text/plain

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : =============================================

     

     

     

  • This irule (below) is successful but for whatever reason I can only get it to do one header replace at a time, rather then several, which is the objective. what does "one header replace at a time" mean? are you referring to inside2.net in query string below which is not replaced with fqdn.com?

     

     

    Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Client 121.122.122.122%6:31772 -> fqdn.com/scorm_launch/redirector?url=http%3A//inside2.net%3A80/Saba/AICCReporter%3FscormSessionKey%3DEE9C8FB6F1E9DB6B9A3E3CDB08446EC0%26sitename%3DSabaSite%26lms_data%3D%25253BconformanceLevel%25253D0%26cmi_entry%3Daireg000000000006535aises000000000002167&debug=false (response) - status: 200
  • Sorry - I meant that when I try the iRule with an 'Else' statement (as seen a the top of this thread) the replace funtion only triggers on the first variable. In the recent example (directly above) I removed the else statement, which allows for the replace to happen but again I'm limited to a single replace funtion. In that case I was replacing inside2.net to FQDN.com.

     

     

    Just not sure why the ELSE statement is breaking.

     

     

  • again I'm limited to a single replace funtion. In that case I was replacing inside2.net to FQDN.com.doesn't adding domain into the list work?

     

     

    e.g.

     

    HTTP::header replace Location "[string map -nocase [list http%3A%2F%2Finside1.net http%3A%2F%2Ffqdn.com http%3A%2F%2Finside2.net http%3A%2F%2Ffqdn.com http%3A%2F%2Finside3.net http%3A%2F%2Ffqdn.com] [HTTP::header value Location]]"
  • Thanks!

     

     

    I'm getting closer... now inside2.net works as required. As for inside1.net it no longer gives me a broken URL error, but the page renders as blank. Any ideas?

     

     

    when HTTP_REQUEST {

     

    set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]"

     

    log local1. "============================================="

     

    log local1. "$LogString (request)"

     

    foreach aHeader [HTTP::header names] {

     

    log local1. "$aHeader: [HTTP::header value $aHeader]"

     

    }

     

    log local1. "============================================="

     

    }

     

    when HTTP_RESPONSE {

     

    log local1. "============================================="

     

    log local1. "$LogString (response) - status: [HTTP::status]"

     

    foreach aHeader [HTTP::header names] {

     

    log local1. "$aHeader: [HTTP::header value $aHeader]"

     

    }

     

    log local1. "============================================="

     

    if { [HTTP::is_redirect] } {

     

    HTTP::header replace Location "[string map -nocase [list http%3A%2F%2Finside1.net http%3A%2F%2Ffqdn.com http%3A%2F%2Finside2.net http%3A%2F%2Ffqdn.com] [HTTP::header value Location]]"
  • but the page renders as blank. Any ideas? can you run tcpdump to see where the wrong is?

     

     

    e.g.

     

    tcpdump -nni 0.0:nnn -s0 -w /var/tmp/output.pcap host x.x.x.x or host y.y.y.y or host z.z.z.z

     

    x.x.x.x is virtual server ip address

     

    y.y.y.y and z.z.z.z are pool member ip addresses
  • Oddly enough, I'm seeing a "http/1.1 500 Internal Server Error\r\n" at the bottom of the TCP stream. When I dig deeper I see the following: java.net.UnknownHostException: fqdn.com

     

    \r\n

     

     

    Basically my understanding of this is that the application (server level) can not resolve fqdn.com. Almost like I need a reverse rewrite or something as well??

     

     

  • Fixed. The URL for inside2.net had a launcher that included an embedded redirect which happened to contain inside1.net, which was being rewritten to fqdn.com in the irule, but in this case we needed the redirect to remain unchanged. Simple change to the servers host file to trick it and we're in business.

     

     

    Thanks for all the help, appreciate it!