Technical World: F5 irules

Monday, May 7, 2018

F5 irules

simple permanent redirect
when HTTP_REQUEST {
    if { [HTTP::host] equals "www.xyz.com" } {
        HTTP::respond 301 Location "https://www.xyz.com"
    }
}
to select different ssl profile based on source IP
when CLIENT_ACCEPTED {
  if { [class match [IP::client_addr] equals clientIPList ]} {
    log local0. "MATCH! Profile client-ssl-profile selected for [IP::client_addr]"
    SSL::profile client-ssl-profile
  } else {
    #log local0. "Profile clientssl selected for [IP::client_addr]"
    SSL::profile wilcard-company
  }
}
irule to respond 200 ok without any pool
when HTTP_REQUEST {
if { ( [IP::addr [IP::client_addr] equals 10.0.0.0/8] ) or ( [IP::addr [IP::client_addr] equals 172.16.0.0/12] ) or ( [IP::addr [IP::client_addr] equals 192.168.0.0/16] )} {
HTTP::respond 200 content "Connection" "ok"
}
}
HTTP URI path based redirection for multiple URI
when HTTP_REQUEST {
    if { [HTTP::host] equals "www.company.com" } {
        switch -glob [HTTP::uri] {
            "/about-ie/newsroom/trials-medical-panel*" {
                HTTP::respond 301 Location "https://www.company.com/news-and-stories"
            }
            "/about-/newsroom/customer-improvements-move-next-stage*" {
                HTTP::respond 301 Location "https://www.company.com/news-and-stories"
            }
            "/about/profile/vivek-bhatia*" {
                HTTP::respond 301 Location "https://www.company.com/about-us/our-people/our-group-leadership-teama"
}
URI path redirection to different pool
when HTTP_REQUEST {
if {
[string tolower [HTTP::uri]]  contains "/scim1450" }
{
HTTP::uri [string map -nocase {"/SCIM1450/" "/"} [HTTP::uri]]
pool pl-SCIM1450}
elseif {
[string tolower [HTTP::uri]]  contains "/scim1451" }
{
HTTP::uri [string map -nocase {"/SCIM1451/" "/"} [HTTP::uri]]
pool pl-SCIM1451}
Display maintenance page if all pools members are down or disabled.
when HTTP_REQUEST {
if { [active_members [LB::server pool]] == 0 }
   { set http_reply "You have reached [HTTP::host],


Our website is offline while we make some important updates. Please check back again soon.

 Please contact helpdesk if you continue to experience issues after this maintenance window."
        HTTP::respond 200 content $http_reply

}
}
use maintenance page uploaded to f5 ifile with name maintenance-page
when HTTP_REQUEST {
if {[active_members [LB::server pool]] < 1} {

    switch [HTTP::uri] {
          default {HTTP::respond 200 content [ifile get "maintenance-page.html"] }
        }
    }
}

No comments: