Forum Discussion

eirikn's avatar
eirikn
Icon for Nimbostratus rankNimbostratus
Mar 15, 2016

Individual Apology page with DataGroup

Hey,

I'm trying to present many different apology pages based on the incoming host header.

I have about 100 different hosts, and all hosts would need a different 301 redirect if the pool is unavailable.

I'm having some problems with my irule:

    when HTTP_REQUEST {

    set artifactid [class match -value [string tolower [HTTP::host]] contains my_apology_dg ]

    if {( $artifactid ne "") and ([active_members my_web_pool] < 1) }{
        HTTP::redirect $artifactid
        event disable
        }
    }

Here is my DG:

    ltm data-group internal /DMZ/my_apology_dg {
       records {
          mysite {
              data https://www.myapologyurl.com
          }
       }
        type string
    }

Requets to: https://mysite.com should redirect to https://www.myapologyurl.com when all members of my_web_pool is offline.

I will add many more sites to the datagroup once i get the logic working.

Any input would be much appreciated.

  • First thing I see is that in your data group, the key value is probably never going to be triggered that way. You'll need it to be

    mysite.com
    or
    www.mysite.com
    , which is what the
    HTTP::host
    value will be.

    Secondly, I'd change the event up a little bit. I assume you're using

    event disable
    so no other iRules will run on the connection. That command will disable the even for future requests on the same connection as well, so you may want to do one of 2 things. Either close the connection and force a new one, or re-enable the event before the response goes out.

     Option 1: Close the connection
    when HTTP_REQUEST {
        set artifactid [class match -value [string tolower [HTTP::host]] contains my_apology_dg ]
    
        if {( $artifactid ne "") and ([active_members my_web_pool] < 1) }{
            HTTP::respond 302 Location $artifactid "Connection" "Close"
             Disable all other iRules for this connections
            event disable all
        }
    }
    
     Option 2: Re-Enable the event
    when HTTP_REQUEST {
        set artifactid [class match -value [string tolower [HTTP::host]] contains my_apology_dg ]
    
        if {( $artifactid ne "") and ([active_members my_web_pool] < 1) }{
            HTTP::redirect $artifactid
            event HTTP_REQUEST disable
        }
    }
    
    when HTTP_RESPONSE_RELEASE {
        event HTTP_REQUEST enable
    }
    

    If you wanna see the event order on a connection, here's an article describing it, to get an idea of the flow.