Forum Discussion

southern_nordic's avatar
southern_nordic
Icon for Altocumulus rankAltocumulus
Oct 06, 2023

Redirect URIs in datagroup to dedicated node

Hi

Could you help identify why I get the following error below when applying this irule. 

ERROR =====================================


:9: error: ["wrong # of arguments"][class match -value $request_uri equals_any -case_sensitive [class lookup $datagroup_name]]

The aim is to send specific requests to a dedicated node "1.2.2.2" in pool "myprodpool" that match a URI list datagroup "ACL_webforms" . This must also maintain sticky persistence cookie on this node. So when request that contain URIs in datagroup, send to node 1.2.2.2 with cookie persistence

The irule below gives this error

set is_match [class match -value $request_uri equals_any -case_sensitive [class lookup $datagroup_name]]



IRULE  ==============================

 

when HTTP_REQUEST {
# Define the name of your data group containing the URIs
set datagroup_name "ACL_Intranett-webforms"

# Get the request URI
set request_uri [HTTP::uri]

# Check if the request URI matches any entry in the data group
set is_match [class match -value $request_uri equals_any -case_sensitive [class lookup $datagroup_name]]

if { $is_match } {
# Set the node to your specific IP address
set node_ip "1.2.2.2"

# Set the persistence cookie name
set persistence_cookie_name "sticky_cookie_name"

# Check if the persistence cookie exists
set cookie_value [HTTP::cookie $persistence_cookie_name]

if { $cookie_value eq "" } {
# If the cookie doesn't exist, create and set the cookie
set cookie_value [IP::client_addr]
HTTP::cookie insert $persistence_cookie_name $cookie_value
}

# Set the persistence based on the cookie
persist uie cookie $persistence_cookie_name
pool $node_ip
return
}
}









7 Replies

  • southern_nordic For various reasons you should try not to send traffic to a specific node and instead you should create a pool for this single node and reference that pool instead. I believe the following will correct your error as well as send traffic to a pool with just the single node in it rather than referencing the node by itself. This iRule also assumes you have a default pool configured on the VS and will send traffic to that pool if it doesn't match the data-group list.

    when CLIENT_ACCEPTED priority 500 {
    
        set DEFAULT_POOL [LB::server pool]
    
    }
    
    when HTTP_REQUEST priority 500 {
    
        # Get the request URI
        set request_uri [HTTP::uri]
    
        # Check if the request URI matches any entry in the data group
        if { [class match -- ${request_uri} == ACL_Intranett-webforms] } {
    
            # Set the persistence cookie name
            set persistence_cookie_name "stick_cookie_name"
    
            # Check if the persistence cookie exists
            set cookie_value [HTTP::cookie ${persistence_cookie_name}]
    
            if { ${cookie_value} == "" } {
                # If the cookie doesn't exist, create and set the cookie
                set cookie_value [IP::client_addr]
                HTTP::cookie insert ${persistence_cookie_name} ${cookie_value}
            }
    
            # Set the persistence based on the cookie
            persist uie cookie ${persistence_cookie_name}
            pool POOL_ACL_Intranett_Webforms
        
        } else {
            pool ${DEFAULT_POOL}
        }
    
    }

     

    • southern_nordic's avatar
      southern_nordic
      Icon for Altocumulus rankAltocumulus

      Thanks Paulios, I should have mentioned we have a default pool and I had intended to create a seperate pool for this traffic.

      I applied your irule , however I received the following error

      01070151:3: Rule 13: error: ["== is unexpected; it should be one of 'contains ends_with equals starts_with'"][class match -- ${request_uri} == ACL_Intranett-webforms]

      • Paulius's avatar
        Paulius
        Icon for MVP rankMVP

        southern_nordic It looks like class match doesn't like using "==" and instead wants "eq" which I have corrected below.

        when CLIENT_ACCEPTED priority 500 {
        
            set DEFAULT_POOL [LB::server pool]
        
        }
        
        when HTTP_REQUEST priority 500 {
        
            # Get the request URI
            set request_uri [HTTP::uri]
        
            # Check if the request URI matches any entry in the data group
            if { [class match -- ${request_uri} eq ACL_Intranett-webforms] } {
        
                # Set the persistence cookie name
                set persistence_cookie_name "stick_cookie_name"
        
                # Check if the persistence cookie exists
                set cookie_value [HTTP::cookie ${persistence_cookie_name}]
        
                if { ${cookie_value} == "" } {
                    # If the cookie doesn't exist, create and set the cookie
                    set cookie_value [IP::client_addr]
                    HTTP::cookie insert ${persistence_cookie_name} ${cookie_value}
                }
        
                # Set the persistence based on the cookie
                persist uie cookie ${persistence_cookie_name}
                pool POOL_ACL_Intranett_Webforms
            
            } else {
                pool ${DEFAULT_POOL}
            }
        
        }
  • The irule now compiles with no errors. However when I generate traffic I see the following error in the logs:

    ERR_ARG (line 1) invoked from within "HTTP::cookie insert ${persistence_cookie_name} ${cookie_value}"

    I guess it is having trouble when executing the cookie insert as result persistence is not honoured

     

    • Paulius's avatar
      Paulius
      Icon for MVP rankMVP

      southern_shredd You might try the following.

      when CLIENT_ACCEPTED priority 500 {
      
          set DEFAULT_POOL [LB::server pool]
      
      }
      
      when HTTP_REQUEST priority 500 {
      
          # Get the request URI
          set request_uri [HTTP::uri]
      
          # Check if the request URI matches any entry in the data group
          if { [class match -- ${request_uri} eq ACL_Intranett-webforms] } {
      
              # Set the persistence cookie name
              set persistence_cookie_name "stick_cookie_name"
      
              # Check if the persistence cookie exists
              set cookie_value [HTTP::cookie ${persistence_cookie_name}]
      
              if { ${cookie_value} == "" } {
                  # If the cookie doesn't exist, create and set the cookie
                  set cookie_value [IP::client_addr]
                  HTTP::cookie insert name ${persistence_cookie_name} value ${cookie_value} path "/"
              }
      
              # Set the persistence based on the cookie
              persist uie cookie ${persistence_cookie_name}
              pool POOL_ACL_Intranett_Webforms
          
          } else {
              pool ${DEFAULT_POOL}
          }
      
      }
  • Apologies for the late response here.

    I have applied the irule above and while the irule did not give any errors, the webform still produces an error due to a "persistence" type error. When we run a test we see the requests to still changing servers.

    The webpage is a webform that is filled in and submitted and before submition but before submitio a verification process checks if the server that received the Submitted form is the same servers that loaded up the webform. This continues to give an error. I even tried to match just the URI without the "datagroup" by using the hostname, URI and persistence but the website still fails the "persistence" test.

    Are there any recommendations on how to update this irule to specifically match traffic from hostname "demo.technical.olive.com" and URI "/object.php?categoryID=3453" and send this traffic to pool "ACL_Intranett_Webforms" with persistence cookie? The rest of the traffic can default to the virtual server pool.

    The main aim to match all URIs in teh datagroup but for now I would like to test the hostname and URI first

    • Paulius's avatar
      Paulius
      Icon for MVP rankMVP

      southern_shredd Do these users hit multiple paths on this same VS? If the answer is yes, try configuring a /32 OneConnect profile and see if your issue persists.