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

rflon2015_23576's avatar
rflon2015_23576
Icon for Nimbostratus rankNimbostratus
Feb 11, 2016

iRule to determine whether to server Custom or default maintenance page

Hi all I am trying to get the following irule to work. Forgive me if it doesnt make sense as this is all new to me.

Ideally it should check whether a custom ifile should be served if it exists otherwise serve the default maintenance ifile. However I get stuck with a TCL error when there is no custom ifile and it never completes the statement to server the default maintenance page:

TCL error: /Common/IIS_maint - iFile IIS_websitename_pl not found (line 10) invoked from within "ifile get $myfile"

when HTTP_REQUEST {

            set $myfile to the name of the desired iFile found in the data-group IIS_DG
     ifile must match the name of the pool
            set myfile [class match -value [string tolower [HTTP::host]] equals IIS_DG ] 
             log local0. "Maint iRule, MYFILE=$myfile"  

            if { $myfile ne "" } {          
                             if myfile is not NULL, a valid name:value has been found
                             server the desired iFile

                            HTTP::respond 503 content [ifile get $myfile]

            } else { 
                             a valid name:value has not been found
                             serve the default iFile
                            HTTP::respond 503 content [ifile get IIS_maint_txt] }           

}

Any help really appreciated

4 Replies

  • Might just be me but why dont you just not add the entry to the datagroup? that way it'll serve the default OOS page, if you are adding things to datagroups then the uploading the page should be added as part of the process.

     

    • rflon2015_23576's avatar
      rflon2015_23576
      Icon for Nimbostratus rankNimbostratus
      The website is in the data group but I only want to serve a custom sorry page ifile if it actually exists (using ifile name that matches the entry in dg). The majority of sites will not have a custom sorry page ifile and will be served with the default sorry page ifile.
  • iFiles are defined in two places:

     

    Under System - File Management - iFile List Under Local Traffic - iRules - iFile List

     

    The name you use in the Local Traffic section is the one you'll reference in the iRule. Have you done this?

     

  • Hi Rflon2015,

    to implement an additional error handle, for the case that the data-group entry already exist, but the iFile can somehow not found, you may try the syntax below...

    when HTTP_REQUEST {
         set $myfile to the name of the desired iFile found in the data-group IIS_DG
         ifile must match the name of the pool
        set myfile [class match -value [string tolower [HTTP::host]] equals IIS_DG ] 
         log local0. "Maint iRule, MYFILE=$myfile"  
        if { $myfile ne "" } then {
             if myfile is not NULL, a valid name:value has been found
             server the desired iFile
            if { [catch {
                HTTP::respond 503 content [ifile get $myfile]
            }]} then {
                HTTP::respond 503 content [ifile get IIS_maint_txt] 
            }
        } else { 
             a valid name:value has not been found
             serve the default iFile
            HTTP::respond 503 content [ifile get IIS_maint_txt] 
        }
    }
    

    Cheers, Kai