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

avnishvyas_1974's avatar
avnishvyas_1974
Icon for Nimbostratus rankNimbostratus
Aug 05, 2015

Maintenance Page using V11

Hi guys

 

Ive read the brilliant article by https://devcentral.f5.com/articles/v111-ndashexternal-file-access-from-irules-via-ifiles which has been most useful and im actually about to attempt this in our live environment. So I have a HTML file which I have imported into the Ifile management list. The iRule I want to use is quite basic and doesnt have any fancy features. I simply want to write an iRule that if pool members are no longer available, then to simply redirect to the maintenance page via the iFile

 

I saw this example, but i dont understand the jpg files its pulling

 

when HTTP_REQUEST { if {[active_members [LB::server pool]] < 1} { switch [HTTP::uri] { "/guardian_header.jpg" { HTTP::respond 200 content [ifile get "guardian_header_jpg"] } "/guardian_logo.jpg" { HTTP::respond 200 content [ifile get "guardian_logo_jpg"] } default { HTTP::respond 200 content [ifile get "maint_index_html"] } } } }

 

This is what I think my iRule should look like and I want your help in tweaking it to suit..

 

when HTTP_REQUEST { if {[active_members [LB::server pool]] < 1} { switch [HTTP::uri] { " { HTTP::respond 200 content [ifile get "My_ifile"] } default { HTTP::respond 200 content [ifile get "maint_index_html"] } } } }

 

Can you guys have a look and let me know if this is ok??

 

9 Replies

  • In its simplest form:

    when HTTP_REQUEST { 
        if { [active_members [LB::server pool]] < 1 } { 
            switch [HTTP::uri] { 
                "/maintenance_page_logo.jpg" { 
                    HTTP::respond 200 content [ifile get "maintenance_page_logo_jpg"] 
                } 
                default { 
                    HTTP::respond 200 content [ifile get "maint_index_html"] 
                } 
            } 
        } 
    }
    

    So basically what's happening is that if there are no pool members, the iRule will look at the request URI. The first request will most certainly fall through to the default condition and render the maintenance page HTML file. Inside that html you may have other linked content (images, scripts, stylesheets). Example:

    
    

    So the browser will make subsequent requests for this linked content to finish rendering the page. Since the pool still has no active members, the browser's request for /maintenance_page_logo.jpg will get pulled from an ifile.

  • So two things:

    1. If you were using images in your maintenance page, the image ifiles would be in whatever image format, and the html page ifile would be a text file. In most cases you also want to include the "Content-Type" header in the response so the browser knows how to handle the object.

    2. Since you don't have any images in your maintenance page, the iRule is considerably simpler:

      when HTTP_REQUEST { 
          if { [active_members [LB::server pool]] < 1 } { 
              HTTP::respond 200 content [ifile get "maint_index_html"] 
          } 
      } 
      
  • Hi Kevin when HTTP_REQUEST { if { [active_members [LB::Customer_pool] == 0 } { switch [HTTP::uri] { " { HTTP::respond 200 content [ifile get Maintenance_Page"] } } }

     

    It seems the F5 is not taking the above and its complaining of errors. Can you see anything wrong with this iRule?

     

  • First thing, "[LB::Customer_pool]" isn't a thing. Use "[LB::server pool]" as described in the previous iRule example. This will expand to the currently configured pool when the event is triggered. You can optionally specify a literal pool name:

    if { [active_members "Customer_pool"] == 0 }
    

    Second thing, you're still trying to switch on the HTTP::uri, but you don't need this since you're not presenting anything more than a single HTML page. Did you try the previous iRule example?

  • Hi Kevin I went by your example and simply modified the name of the pool this is the rule I have done exactly which is throwing a PARSE error Missing bracket 33 (missing a closing bracket) Ive also removed the [HTTP::uri]

     

    when HTTP_REQUEST { if { [active_members [LB::Customer_5013_5014_pool] == 0 } { " { HTTP::respond 200 content [ifile get "Maintenance_Page"] } } }

     

  • So again, "[LB::Customer_5013_5014_pool]" isn't a valid command. You can either use "[LB::server pool]" to expand the configured pool automatically when the HTTP_REQUEST event is triggered, or you can put in the literal string name of the pool:

    if { [active_members "Customer_5013_5014_pool"] == 0 } 
    

    So the following should be exactly what you need:

    when HTTP_REQUEST { 
        if { [active_members [LB::server pool]] < 1 } { 
            HTTP::respond 200 content [ifile get "Maintenance_Page"] 
        } 
    }
    
  • ive been playing with the Brackets its complaining of this now and im getting confused with what I should be using here if { [active_members [LB::server pool Pool Name?] ==0 } { http::respond 200 content [ifile get "maintenance_page] } }

     

    Still the F5 rejects! the above

     

  • Hi Kevin That worked!! I actually thought you had to specify the pool name. which is what i did hence it wasnt taking the iRule I have removed that now and the F5 accepted the iRule

     

    Thanks for your help on this

     

  • At the very least you're missing an ending bracket:

    if { [active_members [LB::server pool]] ==0 }
    

    But more important, your LB::server syntax is incorrect. There is no option to add a pool name after "LB::server pool". It's just:

    [active_members [LB::server pool]]
    

    If you want to specify the pool statically instead of letting it expand the value dynamically, then

    [active_members my-test-pool]
    

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

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