Forum Discussion

Patrick_Stiever's avatar
Patrick_Stiever
Icon for Nimbostratus rankNimbostratus
Sep 09, 2011

iRules amatuer What does this iRule do?

Hello all,

 

 

I do not have much experience with iRules, and I am hoping some here can give me an idea what this iRule is doing:

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] starts_with "/onlineserv/HB" ||

 

[HTTP::uri] starts_with "/beta/HB" ||

 

[HTTP::uri] starts_with "/preprod/HB" }

 

{

 

Lookup the host based on the HTTP host header

 

log local0. "host = '[HTTP::host]'"

 

set ibHost [class lookup [HTTP::host] $::USP_IB_REDIRECT_DG]

 

 

if { $ibHost != "" }

 

{

 

log local0. "ibHost found: '$ibHost'"

 

node $ibHost

 

}

 

else

 

{

 

log local0. "ibHost not found"

 

HTTP::respond 404

 

}

 

}

 

else

 

{

 

SSL::disable serverside

 

}

 

}

 

 

 

Thank you.
  • above URI list i.e. /onlineserv/HB, /beta/HB, /preprod/HB will be sent to specific HTTPS server (node) which is defined in USP_IB_REDIRECT_DG data group (class).
  • You'll need to remove the $:: prefix from the datagroup name reference in the iRule:

     

     

    USP_IB_REDIRECT_DG

     

     

    See the class or CMP compatibility pages for details:

     

    http://devcentral.f5.com/wiki/iRules.class.ashx

     

     

    Aaron
  • Here's an updated version which uses a switch statement to check the URI and corrects the datagroup reference:

    
    when HTTP_REQUEST { 
       switch -glob [HTTP::uri] {
          "/onlineserv/HB" -
          "/beta/HB*" -
          "/preprod/HB*" {
              Lookup the host based on the HTTP host header
             log local0. "host = '[HTTP::host]'"
    
              Check if the host header exists and isn't an IP
             if {[string match -nocase {*[a-z]*} [HTTP::host]]}{
                set ibHost [class lookup [HTTP::host] USP_IB_REDIRECT_DG]
    
                if { $ibHost != "" } {
                   log local0. "ibHost found: '$ibHost'"
                   node $ibHost
                } else {
                   log local0. "ibHost not found" 
                   HTTP::respond 404
                }
             } else {
                SSL::disable serverside
             }
          }
          default {
              Default action is to use the VS default pool for non-matching URIs
          }
       }
    }
    

    Aaron