Forum Discussion

madhawa_chamind's avatar
madhawa_chamind
Icon for Nimbostratus rankNimbostratus
Aug 19, 2018

Irules with parameter values in target url

Hi,

 

When defining irules inside a data group file is it possible to add the url parameters in to the target url. As an eg:- please check below

 

Eg:- "mysite.one.com" := "mysite.second.com/variable?PartnerIdpId=;

 

  • One way to do this is like below,

    datagroup with values of target host with full uri. As URI involves query parameter, planned to call the complete URI itself. Note the host and and URI are split by "|" in the data value.

    ltm data-group internal /Common/test_dgl {
    records {
    mysite.one.com {
    data "mysite.second.com|variable?PartnerIdpId=http://team02.com"
    }
    }
    type string
    }
    

    Irule: On the irule, using the "|" as a delimiter.

    ltm rule test_rule {
    when HTTP_REQUEST {
    set data_value ""
    set newhost_value ""
    set newuri_value ""
    
    if { [set data_value [class match -value [HTTP::host] equals test_dgl]] ne ""} then {
    set newhost_value [getfield $data_value "|" 1 ]
    log local0. "New HOST Value is $newhost_value"
    set newuri_value [getfield $data_value "|" 2 ]
    log local0. "New URI Value $newuri_value"
     Do something 
    }
    }
    }
    
  • HI,

    So First of you have to create a DataGroup (Local Trafic -> DataGroup -> List then create). Select String Type:

    Name: DG_parameters
    String: mysite.second.com
    Value: PartnerIdpId=http://team02.com
    

    Then create this irule and add it to your VS.

    when HTTP_REQUEST {
    
     Set hostname in the user request
    set hostname [string tolower [HTTP::host]]
    set uri [HTTP::uri]
    
     Check if this hostname exist in the DG 
    if { [class match $hostname contains DG_parameters] } {
         The hostname exist so we will retrieve the value, so th parameters
        set parameters_DG [class match -value $hostname contains DG_parameters]
    
         So now we will modify user request by adding the parameters
        HTTP::uri $uri$parameters_DG
    }
    
    }
    

    As you can noticed in my irule, I added parameters in all request. You can add additional condition that allow you to send parameters with specific hostname + uri.

    If you want to send the parameter only for specific URI and Hostname follow the following procedure

    So First of you have to create a DataGroup (Local Trafic -> DataGroup -> List then create). Select String Type:

    Name: DG_parameters
    String: mysite.second.com/variable (as you can noticed in the string we added hostname and URI)
    Value: PartnerIdpId=http://team02.com
    

    And create this irule...

    when HTTP_REQUEST {
    
     Set hostname in the user request
    set hostname [string tolower [HTTP::host]]
    set uri [HTTP::uri]
    
    set url "$hostname$uri"
    
     Check if this hostname exist in the DG 
    if { [class match $url contains DG_parameters] } {
         The hostname exist so we will retrieve the value, so th parameters
        set parameters_DG [class match -value $url contains DG_parameters]
    
         So now we will modify user request by adding the parameters
        HTTP::uri $uri$parameters_DG
    }
    
    }
    

    I did not test the irule and it will also optimize it by changing the contains by equal ... but step by step 🙂

    Keep me in touch.

    Regards