Forum Discussion

rg-f5's avatar
rg-f5
Icon for Nimbostratus rankNimbostratus
Jun 07, 2025

Create an iRule that can search and replace

Looking for some irule help please this is a search and replace rule...

 

Step one in the message payload

 

Find <soapenv:Header/> and replace with 

<soapenv:Header>
<job:roleIdentifier>SERVER1</job:roleIdentifier>
</soapenv:Header>

 

or if the message is from Server2

 

Find <soapenv:Header/> and replace with 

<soapenv:Header>
<job:roleIdentifier>SERVER2</job:roleIdentifier>
</soapenv:Header>

 

 

12 Replies

  • Assuming that you can identify server1 and 2 based on IP you can use below exmaple

     

    when HTTP_REQUEST 
    {
    	switch [IP::client_addr] 
    	{
            "server1_IP" 
    		{
                set server "SERVER1"
    			HTTP::collect
            }
            "server2_IP" 
    		{
                set server "SERVER2"
    			HTTP::collect
            }
    	}
    }
    
    when HTTP_REQUEST_DATA 
    {
    	if {[info exists server]} 
    	{
    		set payload [HTTP::payload]
    		set new_header "<soapenv:Header><job:roleIdentifier>$server</job:roleIdentifier></soapenv:Header>"
    		regsub {<soapenv:Header/>} $payload $new_header payload
    		HTTP::payload replace 0 [string length [HTTP::payload]] $payload
    	}
    }

     

    • rg-f5's avatar
      rg-f5
      Icon for Nimbostratus rankNimbostratus

      thank you for your message, when you say identify the server, how can identify the server with irule code? 

       

      what if i just wanted to replace the below and then assign the irule to the virtual server, then i would have identified which server the message came from. 

       

      Step one in the message payload

       

      Find <soapenv:Header/> and replace with 

      <soapenv:Header>
      <job:roleIdentifier>SERVER1</job:roleIdentifier>
      </soapenv:Header>

       

       

  • It depends how is your topology.

    If you you a specific VS fo each server then you don't need to identify it.

     

    But if you have one VS then you somehow need to know which server it is.

    You can use IPs, headers, cookies, or whatever unique application may has.

    • Injeyan_Kostas's avatar
      Injeyan_Kostas
      Icon for Cumulonimbus rankCumulonimbus

      Another one is that you don't specify if this is a request or a response.

      So my example is for request.

      If you need it for a response it needs to be adjusted accordingly.

      • rg-f5's avatar
        rg-f5
        Icon for Nimbostratus rankNimbostratus

        The message will come through from an application to the Virtual Server, i'm not sure if this is a response or a request. The message will not have a role identifier. Hence I have to add in the following irule.

        Let's start with it being one virtual server and we want a basic example to get the irule started to search and replace.

        This is a message sent from the application, and an irule to replace <soapenv:Header/> with <soapenv:Header>
        <job:roleIdentifier>SERVER1</job:roleIdentifier>
        </soapenv:Header>

        Step one in the message payload

         

        Find <soapenv:Header/> and replace with 

        <soapenv:Header>
        <job:roleIdentifier>SERVER1</job:roleIdentifier>
        </soapenv:Header>

    • rg-f5's avatar
      rg-f5
      Icon for Nimbostratus rankNimbostratus

      Server 1 and Server 2 are both separate. I thought the irule can be attached to each server. 

      • Injeyan_Kostas's avatar
        Injeyan_Kostas
        Icon for Cumulonimbus rankCumulonimbus

        Oh when you say server you mean virtual server?

        If so yes you can attach same irule to both virtual servers.

        But again you somehow need to identify which virtual server was used.

        You need to modify the request or the response?