Forum Discussion

Faresnani's avatar
Faresnani
Icon for Altostratus rankAltostratus
Feb 20, 2025

Editing iRule for Maintainance Page with image local in F5 Big-IP iFile

Dear Community,

I hope this message finds you well.

I am reaching out to request your assistance in editing the iRule to redirect users to a maintenance page when all nodes are down. While the iRule is currently functioning as intended, I would like to incorporate images that represent our organization and application for users. I have successfully uploaded the images to F5 using iFile however, I am uncertain about how to reference these images within the HTML code of the iRule.

Attached below, you will find a screenshot of the current page and a visual representation of the desired maintenance page.

 

The code below:

===================================================================================

 

when HTTP_REQUEST {
    if { [active_members [LB::server pool]] == 0 } {
        HTTP::respond 503 content "
<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Maintenance Page</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            color: rgb(27, 131, 111);
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            text-align: center;
        }
        .container {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        h1 {
            font-size: 2em;
            margin: 0;
        }
        p {
            font-size: 1.2em;
        }
        .logos {
            margin-bottom: 20px;
        }
        .logos img {
            height: 150px;
            margin: 0 15px;
        }
        .gear-icon {
            font-size: 3em;
            color: rgb(27, 131, 111);
        }
        @media (max-width: 600px) {
            h1 {
                font-size: 1.5em;
            }
            p {
                font-size: 1em;
            }
        }
    </style>
</head>
<body>
    <div class='container'>
        <div class='logos'>
            <img src='/iFiles/Blackboard-LOGO' alt='Blackboard Logo'>
            <img src='/iFiles/PSAU-LOGO' alt='PSAU Logo'>
        </div>
        <h1>We'll be back soon!</h1>
        <p>Our website is currently undergoing maintenance. We are working hard to improve your experience. Stay tuned!</p>
        <p>! الموقع حاليا تحت الصيانة, نحن نعمل بجد لتحسين تجربة المستخدم، ترقبوا</p>
        <div class='gear-icon'>⚙️</div>
    </div>
</body>
</html>
        " "Content-Type" "text/html"
    } else {
        switch [HTTP::uri] {
            "/iFiles/Blackboard-LOGO" {
                HTTP::respond 200 content [ifile get "Blackboard-LOGO"] "Content-Type" "image/png"
            }
            "/iFiles/PSAU-LOGO" {
                HTTP::respond 200 content [ifile get "PSAU-LOGO"] "Content-Type" "image/png"
            }
            default {
                # Optionally handle requests for other pages here
            }
        }
    }
}

 

=================================================================================

 

 

Thank you in advance for your support.

Regards

Omran Mohamed

 

8 Replies

  • Hi Omran,

    Below is the approach that I personally use when creating a maintenance page. It involves creating 3 x iFiles on the BIG-IP; one for your maintenance page HTML, and two others for your logo images. You can then use a switch glob statement to get the BIG-IP to display these files.


    Steps

    1. Grab all of your maintenance page HTML code and save it into a new file named "maintenance.html"

    2. Import maintenance page as an iFile:

      a) Import file in "System iFile List" via GUI: System > File Management > iFile List > Import

      b) Create iFile in "iRule iFile List" via GUI: Local Traffic > iRules > iFile List

     

    3.Create iRule and apply to virtual server

    when HTTP_REQUEST {
        if { [active_members [LB::server pool]] == 0 } {
            switch -glob [HTTP::uri] {
                "*Blackboard-LOGO" { HTTP::respond 200 content [ifile get "Blackboard-LOGO"] "Content-Type" "image/png" "Cache-Control"  "no-cache" "Connection" "Close" }
                "*PSAU-LOGO" { HTTP::respond 200 content [ifile get "PSAU-LOGO"] "Content-Type" "image/png" "Cache-Control"  "no-cache" "Connection" "Close" }
                default { HTTP::respond 503 content [ifile get "maintenance.html"] "Content-Type" "text/html" "Cache-Control"  "no-cache" "Connection" "Close" }
            }
        }
    }


    If you try this, let me know whether or not this works for you.

    Cheers,

    Michael

    • Faresnani's avatar
      Faresnani
      Icon for Altostratus rankAltostratus

      Dear Michael,

       

      Thank you for your support and detailed explanation, unfortunately, it didn't work for me I got the below result

       

      • Hi Omran,

        Apologies, I have updated the the iRule code in my original reply (I was referencing the $URI variable which I did not declare). This should hopefully be fixed now, Please try copying and pasting the iRule again.

  • f51's avatar
    f51
    Icon for Cumulonimbus rankCumulonimbus

    Try this out
    when HTTP_REQUEST {  
        # Check if all members of the pool are down  
        if { [active_members [LB::server pool]] == 0 } {  
            HTTP::respond 503 content "  
    <!DOCTYPE html>  
    <html lang='en'>  
    <head>  
        <meta charset='UTF-8'>  
        <meta name='viewport' content='width=device-width, initial-scale=1.0'>  
        <title>Maintenance Page</title>  
        <style>  
            body {  
                font-family: Arial, sans-serif;  
                background-color: #f4f4f4;  
                color: rgb(27, 131, 111);  
                display: flex;  
                justify-content: center;  
                align-items: center;  
                height: 100vh;  
                margin: 0;  
                text-align: center;  
            }  
            .container {  
                background: white;  
                padding: 20px;  
                border-radius: 8px;  
                box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);  
            }  
            h1 {  
                font-size: 2em;  
                margin: 0;  
            }  
            p {  
                font-size: 1.2em;  
            }  
            .logos {  
                margin-bottom: 20px;  
            }  
            .logos img {  
                height: 120px;  
                margin: 0 15px;  
            }  
            .gear-icon {  
                font-size: 3em;  
                color: rgb(27, 131, 111);  
            }  
            @media (max-width: 600px) {  
                h1 {  
                    font-size: 1.5em;  
                }  
                p {  
                    font-size: 1em;  
                }  
            }  
        </style>  
    </head>  
    <body>  
        <div class='container'>  
            <div class='logos'>  
                <!-- Reference iFiles using /iFiles/URIs -->
                <img src='/iFiles/Blackboard-LOGO' alt='Blackboard Logo'>  
                <img src='/iFiles/PSAU-LOGO' alt='PSAU Logo'>  
            </div>  
            <h1>We'll be back soon!</h1>  
            <p>Our website is currently undergoing maintenance. We are working to improve your experience. Stay tuned!</p>  
            <p>! الموقع حاليا تحت الصيانة, نحن نعمل بجد لتحسين تجربة المستخدم، ترقبوا</p>  
            <div class='gear-icon'>⚙️</div>  
        </div>  
    </body>  
    </html>  
            " "Content-Type" "text/html"  
        } else {  
            # Handle requests for iFiles (images)
            switch [HTTP::uri] {  
                "/iFiles/Blackboard-LOGO" {  
                    HTTP::respond 200 content [ifile get "Blackboard-LOGO"] "Content-Type" "image/png"  
                }  
                "/iFiles/PSAU-LOGO" {  
                    HTTP::respond 200 content [ifile get "PSAU-LOGO"] "Content-Type" "image/png"  
                }  
                default {  
                    # Optionally handle requests for other paths (if needed)  
                }  
            }  
        }  
    }

    • Faresnani's avatar
      Faresnani
      Icon for Altostratus rankAltostratus

      Hi f51,

       

      Thank you and I appreciate your assistance. As noted in the previous response, I have successfully tested the iRule code with iFile. This implementation not only enhances efficiency but also improves the structure, as evidenced by the shorter iRule code compared to the previous version.

       

      Regards

      Omran Mohamed