Forum Discussion

Eddy_161863's avatar
Eddy_161863
Icon for Nimbostratus rankNimbostratus
Jul 07, 2016

Host a HTML Maintenance Page on LTM

Hi,

 

I am trying to create an irule to host a maintenance page. The problem is the content is not displayed in the center and I if I try to add images, iRule is not accepting it and giving me error: Below is the irule

 

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

 

HTTP::respond 200 content "No Access

 

Temporarily Unavailable

We apologize for the inconvenience. Our website is temporarily unavailable

 

"

 

} }

 

if I use img src="abc.jpg" LTM is not accepting this command...How can I use images in the HTML page ?

 

22 Replies

  • Hi,

    you can use the following irule as an alternative. It's working perfect on several production environments :

    when CLIENT_ACCEPTED {
        set default_pool [LB::server pool]
    }
    
    when HTTP_REQUEST {
        if { [active_members $default_pool] < 1 } { 
            HTTP::respond 200 content [ifile get "/Common/maintenance.html"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate" 
        }
    } 
    
    when LB_FAILED { 
        HTTP::respond 200 content [ifile get "/Common/maintenance.html"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate" 
    }
    
    • Eddy_161863's avatar
      Eddy_161863
      Icon for Nimbostratus rankNimbostratus

      Hi Yann, thanks for the Irule, our requirement is only to show maintenance page if the whole VIP is down i.e. none of the servers are operational.

       

      So I guess I will just use the last condition in your iRule?

       

      And also, how can we use a logo in the iFile? do I just import a picture directly as an iFile on f5?

       

    • Eddy_161863's avatar
      Eddy_161863
      Icon for Nimbostratus rankNimbostratus

      SO BASICALLY I HAVE A HTML PAGE WITH LOGO AT THE TOP...I'M USING THE FOLLOWING IRULE:

       

      when HTTP_REQUEST { if { [active_members [LB::server pool]] == 0 } { HTTP::respond 200 content [ifile get MAINTENANCE.html] "Content-Type" "text/html"

       

      } }

       

      SO WHEN ALL SERVERS ARE DOWN , IT'S DISPLAYING PAGE LIKE THIS:

       

      &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

       

      WHAT IS THE FORMAT OF THE IFILE, WHAT FORMAT SHOULD I UPLOAD ON F5?

       

    • Yann_Desmarest_'s avatar
      Yann_Desmarest_
      Icon for Nacreous rankNacreous

      Hi,

       

      To use ifiles, you should upload the html content in plain text in System >> Files

       

      Then you need to declare a ifile name in The Local Traffic >> iRules >> iFiles section

       

      and finally you can get the content of your ifile using the following command [ifile get MAINTENANCE.html]

       

      Note that MAINTENANCE.html is the name of the ifile declaration previously done on Local Traffic >> iRules >> iFiles

       

  • Hi,

    you can use the following irule as an alternative. It's working perfect on several production environments :

    when CLIENT_ACCEPTED {
        set default_pool [LB::server pool]
    }
    
    when HTTP_REQUEST {
        if { [active_members $default_pool] < 1 } { 
            HTTP::respond 200 content [ifile get "/Common/maintenance.html"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate" 
        }
    } 
    
    when LB_FAILED { 
        HTTP::respond 200 content [ifile get "/Common/maintenance.html"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate" 
    }
    
    • Eddy_161863's avatar
      Eddy_161863
      Icon for Nimbostratus rankNimbostratus

      Hi Yann, thanks for the Irule, our requirement is only to show maintenance page if the whole VIP is down i.e. none of the servers are operational.

       

      So I guess I will just use the last condition in your iRule?

       

      And also, how can we use a logo in the iFile? do I just import a picture directly as an iFile on f5?

       

    • Eddy_161863's avatar
      Eddy_161863
      Icon for Nimbostratus rankNimbostratus

      SO BASICALLY I HAVE A HTML PAGE WITH LOGO AT THE TOP...I'M USING THE FOLLOWING IRULE:

       

      when HTTP_REQUEST { if { [active_members [LB::server pool]] == 0 } { HTTP::respond 200 content [ifile get MAINTENANCE.html] "Content-Type" "text/html"

       

      } }

       

      SO WHEN ALL SERVERS ARE DOWN , IT'S DISPLAYING PAGE LIKE THIS:

       

      &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

       

      WHAT IS THE FORMAT OF THE IFILE, WHAT FORMAT SHOULD I UPLOAD ON F5?

       

    • Yann_Desmarest's avatar
      Yann_Desmarest
      Icon for Cirrus rankCirrus

      Hi,

       

      To use ifiles, you should upload the html content in plain text in System >> Files

       

      Then you need to declare a ifile name in The Local Traffic >> iRules >> iFiles section

       

      and finally you can get the content of your ifile using the following command [ifile get MAINTENANCE.html]

       

      Note that MAINTENANCE.html is the name of the ifile declaration previously done on Local Traffic >> iRules >> iFiles

       

  • Here a complete maintenance irule with css, jpg, png and html payload :

    when CLIENT_ACCEPTED {
        set default_pool [LB::server pool]
    }
    
    when HTTP_REQUEST {
        if { [active_members $default_pool] < 1 } { 
            HTTP::respond 200 content [ifile get "/Common/maintenance.html"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate" 
            return
        }
    
        switch -glob [string tolower [HTTP::path]] {
            "*maintenance-logo.png" {
                HTTP::respond 200 content [ifile get "/Common/maintenance-logo.png"] noserver "Content-Type" "image/png" "Cache-Control" "no-cache, must-revalidate" 
            }
            "*maintenance.jpg" {
                HTTP::respond 200 content [ifile get "/Common/maintenance.jpg"] noserver "Content-Type" "image/jpg" "Cache-Control" "no-cache, must-revalidate" 
            }
            "*maintenance.css" {
                HTTP::respond 200 content [ifile get "/Common/maintenance.css"] noserver "Content-Type" "text/css" "Cache-Control" "no-cache, must-revalidate" 
            }
        } 
    }  
    
    when LB_FAILED { 
      HTTP::respond 200 content [ifile get "/Common/maintenance.html"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate" 
    }
    
    • Eddy_161863's avatar
      Eddy_161863
      Icon for Nimbostratus rankNimbostratus

      thanks I did...I uploaded it as a text file, it worked.

       

      But it's not displaying the logo on the Page which we have as a part of maintenance page.

       

      How can we use logo and text together?

       

      I tried this but didn't work:

       

      when HTTP_REQUEST { if { [active_members [LB::server pool]] == 0 } { HTTP::respond 200 content [ifile get maintenance.html] "Content-Type" "text/html" and [ifile get logo.png] "Content-Type" "image/gif"

       

      } }

       

    • Yann_Desmarest's avatar
      Yann_Desmarest
      Icon for Cirrus rankCirrus

      Hi,

      you have to follow how I built my irule for maintenance. in the maintenance.html file, you should have a reference to the logo like this :

      and your irule should looks like this :

      when HTTP_REQUEST {
          if { [active_members $default_pool] < 1 } { 
              HTTP::respond 200 content [ifile get "/Common/maintenance.html"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate" 
              return
          }
      
          if { [string tolower [HTTP::path]] equals "/logo.png" } {
                  HTTP::respond 200 content [ifile get "/Common/logo.png"] noserver "Content-Type" "image/png" "Cache-Control" "no-cache, must-revalidate" 
          }
      } 
      
    • Eddy_161863's avatar
      Eddy_161863
      Icon for Nimbostratus rankNimbostratus

      I tried this but didn't work..... for the logo I still see a 'X' there.

       

      Why are you using '/Common' before the iFile like /Common/logo.png.

       

      Is there any other way to provide reference to the logo? like I don't want to use another 'If' statement. Can it be integrated in one 'if' statement - both Image and HTML?

       

      Like if I use only logo IF statement, it works and if I use only HTML IF statement, it works but if I use both together, Image doesn't come up.

       

      Any help??

       

  • Here a complete maintenance irule with css, jpg, png and html payload :

    when CLIENT_ACCEPTED {
        set default_pool [LB::server pool]
    }
    
    when HTTP_REQUEST {
        if { [active_members $default_pool] < 1 } { 
            HTTP::respond 200 content [ifile get "/Common/maintenance.html"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate" 
            return
        }
    
        switch -glob [string tolower [HTTP::path]] {
            "*maintenance-logo.png" {
                HTTP::respond 200 content [ifile get "/Common/maintenance-logo.png"] noserver "Content-Type" "image/png" "Cache-Control" "no-cache, must-revalidate" 
            }
            "*maintenance.jpg" {
                HTTP::respond 200 content [ifile get "/Common/maintenance.jpg"] noserver "Content-Type" "image/jpg" "Cache-Control" "no-cache, must-revalidate" 
            }
            "*maintenance.css" {
                HTTP::respond 200 content [ifile get "/Common/maintenance.css"] noserver "Content-Type" "text/css" "Cache-Control" "no-cache, must-revalidate" 
            }
        } 
    }  
    
    when LB_FAILED { 
      HTTP::respond 200 content [ifile get "/Common/maintenance.html"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate" 
    }
    
    • Eddy_161863's avatar
      Eddy_161863
      Icon for Nimbostratus rankNimbostratus

      thanks I did...I uploaded it as a text file, it worked.

       

      But it's not displaying the logo on the Page which we have as a part of maintenance page.

       

      How can we use logo and text together?

       

      I tried this but didn't work:

       

      when HTTP_REQUEST { if { [active_members [LB::server pool]] == 0 } { HTTP::respond 200 content [ifile get maintenance.html] "Content-Type" "text/html" and [ifile get logo.png] "Content-Type" "image/gif"

       

      } }

       

    • Yann_Desmarest_'s avatar
      Yann_Desmarest_
      Icon for Nacreous rankNacreous

      Hi,

      you have to follow how I built my irule for maintenance. in the maintenance.html file, you should have a reference to the logo like this :

      and your irule should looks like this :

      when HTTP_REQUEST {
          if { [active_members $default_pool] < 1 } { 
              HTTP::respond 200 content [ifile get "/Common/maintenance.html"] noserver "Content-Type" "text/html" "Cache-Control" "no-cache, must-revalidate" 
              return
          }
      
          if { [string tolower [HTTP::path]] equals "/logo.png" } {
                  HTTP::respond 200 content [ifile get "/Common/logo.png"] noserver "Content-Type" "image/png" "Cache-Control" "no-cache, must-revalidate" 
          }
      } 
      
    • Eddy_161863's avatar
      Eddy_161863
      Icon for Nimbostratus rankNimbostratus

      I tried this but didn't work..... for the logo I still see a 'X' there.

       

      Why are you using '/Common' before the iFile like /Common/logo.png.

       

      Is there any other way to provide reference to the logo? like I don't want to use another 'If' statement. Can it be integrated in one 'if' statement - both Image and HTML?

       

      Like if I use only logo IF statement, it works and if I use only HTML IF statement, it works but if I use both together, Image doesn't come up.

       

      Any help??