Forum Discussion

Andrew_Smith_16's avatar
Andrew_Smith_16
Icon for Nimbostratus rankNimbostratus
Jun 15, 2016
Solved

iRule with pool status and maintenance page

I have several iRules that currently have 20+ switch elements that matches on a specific uri which takes you to a particular pool. I now need to display a maintenance page if there are no members in the pool. Is there an easier way to achieve this without adding an 'IF' statement in for each pool? I assume I could replace status and the maintenance page redirection with a process but it still seems long winded - probably comes from a poor design but partly dictated by the customer. Thanks in advance.

e.g.

when HTTP_REQUEST {
  switch -glob [HTTP::uri] {
    "/foo1" { if {[active_members pool1] <1}{
      switch [HTTP::uri] {
        "/logo.jpg" {
          HTTP::respond 200 content [ifile get logo.gif] "Content-Type" "image/gif"
        }
        default {
          HTTP::respond 200 content [ifile get error.html] "Content-Type" "text/html"
        }
      }
    } else {pool pool1 }}
    "/foo2" { if {[active_members pool2] <1}{
      switch [HTTP::uri] {
        "/logo.jpg" {
          HTTP::respond 200 content [ifile get logo.gif] "Content-Type" "image/gif"
        }
        default {
          HTTP::respond 200 content [ifile get error.html] "Content-Type" "text/html"
        }
      }
} else {pool pool2 }}
    "/foo3" { if {[active_members pool3] <1}{
      switch [HTTP::uri] {
        "/logo.jpg" {
          HTTP::respond 200 content [ifile get logo.gif] "Content-Type" "image/gif"
        }
        default {
          HTTP::respond 200 content [ifile get error.html] "Content-Type" "text/html"
        }
      }
} else {pool pool3 }}
  }
  }
  • Hi,

    Here is an irule example that do the same as your own irule :

    when HTTP_REQUEST {
        if { [active_members pool1] <1 or [active_members pool2] <1 or [active_members pool3] <1} {
            if { [URI::basename [HTTP::uri]] eq "logo.jpg" } {
                HTTP::respond 200 content [ifile get logo.gif] "Content-Type" "image/gif"
            } else {
                HTTP::respond 200 content [ifile get error.html] "Content-Type" "text/html"
            }
        } else {
            switch -glob [HTTP::uri] {
                "/foo1*"  { pool pool1 }
                "/foo2*" { pool pool2 }
                "/foo3*" { pool pool3 }     
            }       
        }           
    }
    

4 Replies

  • Hi,

    Here is an irule example that do the same as your own irule :

    when HTTP_REQUEST {
        if { [active_members pool1] <1 or [active_members pool2] <1 or [active_members pool3] <1} {
            if { [URI::basename [HTTP::uri]] eq "logo.jpg" } {
                HTTP::respond 200 content [ifile get logo.gif] "Content-Type" "image/gif"
            } else {
                HTTP::respond 200 content [ifile get error.html] "Content-Type" "text/html"
            }
        } else {
            switch -glob [HTTP::uri] {
                "/foo1*"  { pool pool1 }
                "/foo2*" { pool pool2 }
                "/foo3*" { pool pool3 }     
            }       
        }           
    }
    
    • Andrew_Smith_16's avatar
      Andrew_Smith_16
      Icon for Nimbostratus rankNimbostratus
      Thanks very much. I made a mistake in my example as well but this looks a lot cleaner.
  • Hi,

    Here is an irule example that do the same as your own irule :

    when HTTP_REQUEST {
        if { [active_members pool1] <1 or [active_members pool2] <1 or [active_members pool3] <1} {
            if { [URI::basename [HTTP::uri]] eq "logo.jpg" } {
                HTTP::respond 200 content [ifile get logo.gif] "Content-Type" "image/gif"
            } else {
                HTTP::respond 200 content [ifile get error.html] "Content-Type" "text/html"
            }
        } else {
            switch -glob [HTTP::uri] {
                "/foo1*"  { pool pool1 }
                "/foo2*" { pool pool2 }
                "/foo3*" { pool pool3 }     
            }       
        }           
    }
    
    • Andrew_Smith_16's avatar
      Andrew_Smith_16
      Icon for Nimbostratus rankNimbostratus
      Thanks very much. I made a mistake in my example as well but this looks a lot cleaner.