For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

annielee_13548's avatar
annielee_13548
Icon for Nimbostratus rankNimbostratus
Jun 27, 2014

Maintenance page

Hi Guys,

 

I'm pretty new to iRules and trying to modify an existing code to do the following : 1) if pool is down, show page down 2) if pool is on high request, show high load page.. 3) both pages will have same images loaded in the ifiles

 

below is the code with 1) & 3) only and im not sure how to modify to include 2. any pointers will be appreciated.

 

when HTTP_REQUEST { if { [active_members pool_abc] < 1 } { log local0. "All pool members down: Redirecting to outage page." if { [HTTP::uri] eq "/assets/images/Company-Logo.png" } { HTTP::respond 200 content [ifile get companylogo.png] "Content-Type" "image/png" } else { HTTP::respond 200 content [ifile get maintenance.html]

 

} }

 

Thanks in advance.

 

10 Replies

  • Hi,

     

    You need to do use something to define what heavy load is.

     

    There's a good bit of code by Hoolio that sets a maximum number of connections which could be used as your heavy load threshold. You could modify this to suit your requirments.

     

    https://devcentral.f5.com/wiki/iRules.virtual_server_connection_limit_with_HTTP_response.ashx

     

    You could serve content from your iFiles instead of the static content in the example.

     

    Stewart.

     

  • sorry for not making it clear, there is already a 'code' to define heavy load traffic..

     

    i need some assistance on the if..then statement..

     

    if pool < 0 then load maintenance page, elseif heavy load traffic then load heavy load page. end if

     

    both pages will have the same images (uploaded to ifiles) but just different wordings..

     

    thanks in advance

     

  • if pool < 0 then load maintenance page, elseif heavy load traffic then load heavy load page. end if

     

    isn't this if-statement already correct?

     

  • i tried the below if statemen and it doesnt work, as in the images wont load.

     

    if { [active_members pool] < 1 } { HTTP::respond 200 content [ifile get maintenance.html] } elseif { highload > 2 } { HTTP::respond 200 content [ifile get highload.html] }

     

    for images on the html page store in ifiles)

    if { [HTTP::uri] eq "/assets/images/companylogo.png" } { HTTP::respond 200 content [ifile get company.png] "Content-Type" "image/png" } elseif { [HTTP::uri] eq "/assets/images/footer.png" } { HTTP::respond 200 content [ifile get footer.png] "Content-Type" "image/png" }

     

  • have you tried to swap order of the if-statements?

    if { [HTTP::uri] eq "/assets/images/companylogo.png" } { 
      HTTP::respond 200 content [ifile get company.png] "Content-Type" "image/png" 
    } elseif { [HTTP::uri] eq "/assets/images/footer.png" } { 
      HTTP::respond 200 content [ifile get footer.png] "Content-Type" "image/png" 
    }
    
    if { [active_members pool] < 1 } { 
      HTTP::respond 200 content [ifile get maintenance.html] 
    } elseif { highload > 2 } { 
      HTTP::respond 200 content [ifile get highload.html] 
    }
    
  • just noticed the log.. not sure what it meant..(with my initial code)

     

    TCL error: /Common/ - Operation not supported. Multiple redirect/respond invocations not allowed invoked from within "HTTP::respond 200 content [ifile get companylogo.png] "Content-Type" "image/png""

     

  • can you try something like this?

    if { [HTTP::uri] eq "/assets/images/companylogo.png" } { 
      HTTP::respond 200 content [ifile get company.png] "Content-Type" "image/png" 
      return
    } elseif { [HTTP::uri] eq "/assets/images/footer.png" } { 
      HTTP::respond 200 content [ifile get footer.png] "Content-Type" "image/png" 
      return
    }
    
    if { [active_members pool] < 1 } { 
      HTTP::respond 200 content [ifile get maintenance.html] 
    } elseif { highload > 2 } { 
      HTTP::respond 200 content [ifile get highload.html] 
    }
    
  • Thank you very much, it did load the images.. But do you mind to explain what does the return do ?

     

  • do you mind to explain what does the return do ?

     

    it does exit from current irule event.

     

    the problem was it is not possible to have multiple response for one request (i.e. request matches two HTTP::respond commands). return helps because it would exit from irule execution after matching HTTP::respond.

     

    return wiki

     

    https://devcentral.f5.com/wiki/iRules.return.ashx