Forum Discussion

Parveez_70209's avatar
Parveez_70209
Icon for Nimbostratus rankNimbostratus
Nov 06, 2013

Irules Data-Group

Hi,

Need your assistance into this topic related to Irule Based on Data-Groups:

  1. Currently we have total 120 Virtual-Servers( 60 HTTP profiles + 60 HTTPS Profiles) created into the Load-Balancer for single customer.
  2. And into every profile they specified/attached the below Irule:

Let’s say For HTTP Profile Irule:

when CLIENT_ACCEPTED { set default_pool [LB::server pool] log local0. "Default pool [LB::server pool] set" log local0. "Client IP is [IP::remote_addr]" }

when HTTP_REQUEST { set https_uri [string tolower [HTTP::uri]] log local0. "requested [HTTP::uri]" if {$https_uri equals "/" } { HTTP::redirect "https://parveez.com" pool pool_parveez.com log local0. "redirected from /"

                            return

} elseif { $https_uri starts_with "/iss_static" } {

log local0. "matched /iss_static"

pool pool_confarmsp.leni2.com_http 

log local0. "pool_confarmsp.leni2.com_http defined, [LB::server pool] selected" return

} elseif { $https_uri starts_with "/"} { log local0. "URI starts with /"

   pool pool_apuat_leni2.com_http

log local0. " pool_apuat_leni2.com_http defined, [LB::server pool] selected" return

            }  else {

log local0. "no match for rev. close connection"

pool pool_apuat_leni2.com_http
            }

}

  1. Just to give you a brief about the Irules, the client got two kinds of pages; One is Static content which is specified by "/iss_static" , while else option is for Dynamic content which is identified by entry /SEUILibrary/ which consists of many options inside.

Now requirement is to add/edit such an irule using Data-Groups so that when the user hits the Virtual-Server, it will automatically understand based on the "/iss_static" or else going to the pool and understands it as /SEUILibrary/ for dynamic content, into the same Data-groups it automatically should understand which pool to go BY SEEING its name.

For example:

  1. Lets say we have three Virtual-servers:

www.abc.com-HTTP ------ Pool named as : pool-abc.com-HTTP www.def.com-HTTPS ------ Pool named as : pool-def.com-HTTP www.ghi.com-HTTPS ------ Pool named as : pool-ghi.com-HTTP

  1. So, these got an Irule with "/iss_static" : for static page content and if not it will go for /SEUILibrary/ for dynamic page content.
  2. So, basically we are looking for an Irule using Data-Group which contains "/iss_static" and /SEUILibrary/ and also when this Irule is attached to the Virtual-server it will automatically should send which pool to Go by comparing the common parameters like abc Virtual-server which is matching with abc named pool( nomenclature is same: Virtual-server: www.abc.com-HTTP and Pool: pool-abc.com-HTTP), so in the above Irule we wanted to remove the pool part and to introduce Data-Group.

So, breaking the Irule:

The below part will remain same:

when CLIENT_ACCEPTED { set default_pool [LB::server pool] log local0. "Default pool [LB::server pool] set" log local0. "Client IP is [IP::remote_addr]" }

when HTTP_REQUEST { set https_uri [string tolower [HTTP::uri]] log local0. "requested [HTTP::uri]" if {$https_uri equals "/" } { HTTP::redirect "https://parveez.com" pool pool_parveez.com log local0. "redirected from /"

                            return

After this part it should use the Data-group which will replace the pool part from Irule and replaced the same by Data-Group

} elseif { $https_uri starts_with "/iss_static" } {

log local0. "matched /iss_static"

pool pool_confarmsp.leni2.com_http 

log local0. "pool_confarmsp.leni2.com_http defined, [LB::server pool] selected" return

} elseif { $https_uri starts_with "/"} { log local0. "URI starts with /"

   pool pool_apuat_leni2.com_http

log local0. " pool_apuat_leni2.com_http defined, [LB::server pool] selected" return

            }  else {

log local0. "no match for rev. close connection"

pool pool_apuat_leni2.com_http
            }

}

Thanks and Regards Parveez

  • Hi Sir,

     

    With your constant support and suggestion we modified the Irule and got almost the results, except one last part which is prevailing in 2nd part of the Irule: "/ISS_Static*" , where seems like some /ISS_Static parts are allowing while others are dropping( error 404).

     

    So, seems like 2nd part of the Irule(/ISS_Static) is case-sensitive, so thinking whether we can put something against this which is case-in-sensitive.

     

    So, planning to divide the Irule into three parts by HTTP_REQUEST by replacing the switch -glob syntax:

     

    Sir, how to modify the Final Irule:

     

    ===============================================

     

    when HTTP_REQUEST { switch -glob [HTTP::uri] { "/" { log local0. "redirecting from /" if { [class match [virtual] equals Common ] } { HTTP::respond 301 Location [lindex [split [class match -value [virtual] equals Common] ","] 2] pool [lindex [split [class match -value [virtual] equals Common ] ","] 0] log local0. "Went to root ( / ), index 0 - WEC pool after index 2 url set with 301" } else { log local0. "Static pool entry for xxxx[LB::server pool] not created yet" reject } return } "/ISS_Static*" { if { [class match [virtual] equals Common ] } { pool [lindex [split [class match -value [virtual] equals Common] ","] 1] log local0. "Went to default, index 1 - Confarm pool" } else { log local0. "Static pool entry for [virtual] not created yet" reject } return }

     

    default { if { [class match [virtual] equals Common ] } { pool [lindex [split [class match -value [virtual] equals Common ] ","] 0] log local0. "Went to default, index 0 - WEC pool" } else { log local0. "Dynamic pool entry for [virtual] not created yet" reject } return } } }

     

    =============================

     

    Kindly suggest Sir.

     

    Thanks and Regards Parveez

     

  • Sorry I was a bit brief yesterday. As well as adding "string tolower" to the switch subject, you also need to update the switch arms, in this case "iss_static" to use lowercase ie.

    switch -glob [string tolower [HTTP::uri]] {
        "/" {
        }
        "/iss_static" {
        }
        default {
        }
    }
    

    Hope that fixes it for you.

  • So Sir you mean like the below : ?

     

    switch -glob [string tolower [HTTP::uri]] { "/" { } * - "/iss_static*" { } default { } }

     

    Thanks and Regards Parveez

     

  • Like this;

    switch -glob [string tolower [HTTP::uri]] {
        "/" { 
        } 
        "/iss_static*" { 
        } 
        default { 
        } 
    }