Forum Discussion

SteveVernau_132's avatar
SteveVernau_132
Icon for Nimbostratus rankNimbostratus
Nov 15, 2016

String replace in URI when certain node active

Replace component of path when failed over to a certain node.

 

I have a bit of a tricky situation here.

 

First I have A priority group (say 10) of two nodes load balancing, and when there are less than one (ie no nodes) available in that priority group I want it to fail to the third node (say priority group 5) I understand thats easy just to do in the GUI.

 

The tricky part is, when those first two nodes go down and I fail over to that third node, I then want to replace a component in the URL path - for example sake I need to replace hello with goodbye before I send the request to the server (but only when that third node is the one receieving traffic) for example I need to replace

 

https://demo.com/hello/1234?num=1 with https://demo.com/goodbye/1234?num=1

 

I guess I can do the URI bit with this but how do I only do it when using that third node? And is the below right anyway?

 

when HTTP_REQUEST { HTTP::uri [string map -nocase {"/hello/" "/goodbye/"} }

 

2 Replies

  • May be time for redesign ? Start from scratch and think about the functionality required. This may lead to the priority group being scratched. I would recommend providing the required functionality for further assistance instead of trying to make it work within the existing set up.

    Having said that, if you still require something to work with the iRule, in order to replace the URI for any 3rd node, you can use this if-condition after HTTP_REQUEST:

    if { [active_members POOL_DEFAULT == 1] } {

  • Hi Steve,

    you may try the iRule below.

    The iRule uses the

    HTTP_REQUEST_SEND
    event to perform your required URI mapping right before the request is forwarded to a given pool member (filtered via its IP).

    when HTTP_REQUEST_SEND {
        if { [IP::server_addr] equals "10.10.10.10%1" } then {
            clientside {
                HTTP::path [string map { "hello" "goodby" } [HTTP::path]]
            }
        }
    }
    

    Note: Instead of using the

    [string map { "hello" "goodby" } [HTTP::path]]
    syntax you may also try
    "/goodby[string range [HTTP::path] [string length "/hello"] end]"
    . This syntax would be slightly more accurate and also require less CPU ressources.

    Cheers, Kai