active members check on multiple pools

I have an iRule that redirects traffic to another pool by uri. I want to be able to mark the site offline with a placeholder if the default pool is unavailable. I have a seperate pool for my placeholder server. It works fine for the default pool offline but not if I try teh redirected pool. Any suggestions?

iRule: when HTTP_REQUEST { set DEBUG 0 if { $DEBUG } { log local0. “Request: [HTTP::uri]” } if {[active_members QA-HC-HTTP] < 1} { pool QA-PH return } if { $DEBUG } { log local0. “Request: [HTTP::uri]” } switch -glob [string tolower [HTTP::uri]] { “/portals/" - "/js/” - “/controls/” - “/uk/" - "/us/” - “/ca/” - “/admin/controlpanel/" - "/webresource” - “/scriptresource” - “/resources/" - "/providers/” - “/linkclick” - “/documentation/" - "/desktopmodule/” - “/config/” - “/components/" - "/bin/” - “/app_themes/” - “/app_globalResources/" - "/app_data/” - “/app_code/” - “/app_browser/" - "/dnnaadmin/” - “/contactus/” - “/resourcecenter/i" - "/resourcecenter/r” - “/resourcecenter/j" - "/resourcecenter/e” { if { $DEBUG }{log local0. “Sending request to QA-HC-HTTPDNN”} if {[active_members QA-HC-HTTP] < 1} { pool QA-PH return } pool QA-HC-HTTPDNN } default { pool QA-HC-HTTP} } }

It works fine for the default pool offline but not if I try the redirected pool.

can you give an example which does not work?

by the way, did you forget to put special sequences (e.g. asterisk question mark), in the switch glob case?

iRules 101 - 04 - Switch by Joe Pruitt

when HTTP_REQUEST {
        set DEBUG 0
        if { $DEBUG } { log local0. "Request: [HTTP::uri]" }
        if { [active_members QA-HC-HTTP] < 1} {
                pool QA-PH
                return
        }
        if { $DEBUG } { log local0. "Request: [HTTP::uri]" }
        switch -glob [string tolower [HTTP::uri]] {
                "/portals/" -
                "/js/" -
                "/controls/" -
                "/uk/" -
                "/us/" -
                "/ca/" -
                "/admin/controlpanel/" -
                "/webresource" -
                "/scriptresource" -
                "/resources/" -
                "/providers/" -
                "/linkclick" -
                "/documentation/" -
                "/desktopmodule/" -
                "/config/" -
                "/components/" -
                "/bin/" -
                "/app_themes/" -
                "/app_globalResources/" -
                "/app_data/" -
                "/app_code/" -
                "/app_browser/" -
                "/dnnaadmin/" -
                "/contactus/" -
                "/resourcecenter/i" -
                "/resourcecenter/r" -
                "/resourcecenter/j" -
                "/resourcecenter/e" {
                        if { $DEBUG } {log local0. "Sending request to QA-HC-HTTPDNN" }
                        if { [active_members QA-HC-HTTP] < 1} {
                                pool QA-PH
                                return
                        }
                        pool QA-HC-HTTPDNN
                }
                default {
                        pool QA-HC-HTTP
                }
        }
}

Basically when the pool is unavailable if I go to qa.website.com the site maintenance page comes up. If I go to qa.website.com/us/blah blah blah I get a page not found. Where as if the pool is available the qa.website.com/us/blah blah blah page loads fine. My end goal is to have the maintenance page appear for both pools whenever the default pool is unavailable.

Your life will be a lot easier if you use a data group for this large list of URIs.

when RULE_INIT {
    set static::DEBUG 1
}
when HTTP_REQUEST {
    if { [active_members QA-HC-HTTP] < 1 } {
        if { $static::DEBUG } { log local0. "Primary pool offline" }
        pool QA-PH
    } elseif { [class match [string tolower [HTTP::uri]] starts_with uri_list] } {
        pool QA-HC-HTTPDNN
    } else {
        pool QA-HC-HTTP
    }
}

** where “uri_list” is a string-based data group. Example:

/portals/" := "" 
"/js/" := ""
"/controls/" := "" 
"/uk/" := ""
"/us/" := ""
"/ca/" := ""
"/admin/controlpanel/" := "" 
"/webresource" := ""
"/scriptresource" := ""
"/resources/" := ""
"/providers/" := ""
"/linkclick" := ""
"/documentation/" := "" 
"/desktopmodule/" := ""
"/config/" := ""
"/components/" := "" 
"/bin/" := ""
"/app_themes/" := "" 
"/app_globalResources/" := "" 
"/app_data/" := ""
"/app_code/" := ""
"/app_browser/" := ""
"/dnnaadmin/" := ""
"/contactus/" := ""
"/resourcecenter/i" := "" 
"/resourcecenter/r" := ""
"/resourcecenter/j" := ""
"/resourcecenter/e" := ""

If I go to qa.website.com/us/blah blah blah I get a page not found.

can you try to add “HTTP::uri /” into the irule?

if { [active_members QA-HC-HTTP] < 1} {
      HTTP::uri /
      pool QA-PH
      return
   }

So I took Kevin and nitass’s advice. I created a new rule: when RULE_INIT {

set static::DEBUG 1

}

when HTTP_REQUEST {

if { [active_members INF-HC-HTTP] < 1 } {
    if { $static::DEBUG } { log local0. "Primary pool offline" }
    HTTP::uri /
    pool QA-PH
} elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HC-URI] } {
    pool INF-HC-HTTPDNN
} else {
    pool INF-HC-HTTP
}

}}

with a string data group called QA-HC-URI and everything works like a charm except for one piece. When the maintenance page comes up it loads the text but the CSS and the images are missing. When I wireshark it, it says everything is fine and the logs on the server say it’s being delivered but they don’t show up. If I host file to the server directly it comes up perfectly. I’m clueless. Thanks.

When the maintenance page comes up it loads the text but the CSS and the images are missing.

it is because we change all request uri to root (/) in HTTP::uri / command. this has to be done for fixing the problem below.

If I go to qa.website.com/us/blah blah blah I get a page not found.

so, what we can do is to not change request uri for css and image. can you try something like this?

e.g.

when HTTP_REQUEST {
  if { [active_members INF-HC-HTTP] < 1 } {
    if { $static::DEBUG } { log local0. "Primary pool offline" }
    switch -glob [string tolower [HTTP::path]] {
      "*css" -
      "*jpg" -
      "*gif" -
      "*png" {
         do nothing
      }
      default {
        HTTP::uri /
      }
    }
    pool QA-PH
  } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HC-URI] } {
    pool INF-HC-HTTPDNN
  } else {
    pool INF-HC-HTTP
  }
}

No luck. I added a section for css and gif because that’s all we have and it made no difference.

No luck. I added a section for css and gif because that’s all we have and it made no difference.

do you know url of css and image which are missing? have you used http analyzer tool such as httpfox? it may be helpful.

HttpFox

https://addons.mozilla.org/en-US/firefox/addon/httpfox/

So I ran a wireshark after setting the rule and I understand why it’s not getting the file… GET /us/resource/images/logo.gif shouldn’t work, it’s not being redirected to the QA-PH pool. /images/logo.gif is the right path but /us/resource/ is the original source. So I have to figure out how to get it to GET /images/logo.gif without the /us/resource/

GET /us/resource/images/logo.gif shouldn’t work, it’s not being redirected to the QA-PH pool. /images/logo.gif is the right path but /us/resource/ is the original source.

why is the path not correct? isn’t it (maintenance html page) generated by GET / to pool QA-PH?

anyway, if you want to remove /us/resource/ in request for css and image file, you can use string map command similar to this.

e.g.

when HTTP_REQUEST {
  if { [active_members INF-HC-HTTP] < 1 } {
    if { $static::DEBUG } { log local0. "Primary pool offline" }
    switch -glob [string tolower [HTTP::path]] {
      "*css" -
      "*jpg" -
      "*gif" -
      "*png" {
        HTTP::uri [string map {/us/resource/ /} [HTTP::uri]]
      }
      default {
        HTTP::uri /
      }
    }
    pool QA-PH
  } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HC-URI] } {
    pool INF-HC-HTTPDNN
  } else {
    pool INF-HC-HTTP
  }
}

The path isn’t correct because /us/resource is part of the INF-HC-HTTP pool not part of the QA-PH pool. I would assume when I’m making a request to http://qa.hcareers.com/us/resouce and the INF-HC-HTTP pool is down that the request would be http://qa.hcareers.com/images/logo.gif not http://qa.hcareers.com/us/resource/images/logo.gif.

I would assume when I’m making a request to http://qa.hcareers.com/us/resouce and the INF-HC-HTTP pool is down

this is what i understand… when requesting http://qa.hcareers.com/us/resouce but INF-HC-HTTP pool is down, request would be changed to http://qa.hcareers.com/ due to HTTP::uri / command and sent to pool QA-PH. pool QA-PH will respond with maintenance html page. then client will send another request for object (e.g. css, image) which is inside the html page.

isn’t this how it works?

nope. The INF-HC-HTTP pool is currently offline. When I open a web page and enter http://qa.hcareers.com/us/resource/default.aspx I get the maintenance page with the text and no css or gif’s. When I look at my wireshark capture the GET is GET /us/resource/styles.css and GET /us/resource/images/logo.gif.

oh yes, you are correct. sorry, i misthought.

would you mind trying this?

when HTTP_REQUEST {
  if { [active_members INF-HC-HTTP] < 1 } {
    if { $static::DEBUG } { log local0. "Primary pool offline" }
    switch -glob [string tolower [HTTP::path]] {
      "/" -
      "*css" -
      "*jpg" -
      "*gif" -
      "*png" {
                do nothing
      }
      default {
        HTTP::redirect "http://[HTTP::host]"
      }
    }
    pool QA-PH
  } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HC-URI] } {
    pool INF-HC-HTTPDNN
  } else {
    pool INF-HC-HTTP
  }
}

It works but I don’t want to rewrite the URL back to the main page.

Also, It works in IE but Chrome and Firefox bring up error pages. Chrome is it’s usually Opps and Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

It works but I don’t want to rewrite the URL back to the main page.

in that case, you have to correct path for css and image before sending to pool QA-PH. :slight_smile:

I can’t get this figured and it can’t be this hard. All I want is an iRule that:

A) go to main page: qa.hcareers.com and if pool is unavailable go to another pool that has a site unavailable web page

B) go to login page: qa.hcareers.com/access/… and if pool is unavailable go to another pool that has a site unavailable web page (same pool and web page as A).

C) go to resource page: qa.hcareers.com/resource/… and if pool is unavailable go to another pool that has a site unavailable web page (same pool and web page as A).

If I use: if { [active_members INF-HC-HTTP] < 1 }

{ if { $static::DEBUG } { log local0. “Primary pool offline” }

HTTP::uri /
pool QA-PH

}

A) works fine. B) brings up the text but not the css or gif’s, HTTPFox and wire shark report the correct URL of qa.hcareers.com/images/logo.gif and 200 OK. C) same as B.

I am sooooooo close. Read through nitass reply and changed my rule around some. If I test with: when RULE_INIT

{ set static::DEBUG 1 }

when HTTP_REQUEST {

if { [active_members INF-HC-HTTP] < 1 }

{ switch -glob [string tolower [HTTP::path]]

{
  "*.gif" -
  "*.css" {
    HTTP::uri [string range [HTTP::uri] [string last / [HTTP::uri]] end]
  }
  default {
    HTTP::uri /
  }
}
pool QA-PH

} }

everything works like a charm on all parts of my web site. Main, resource and access all come up with images and CSS and it’s all right. Problem is if I try to add:

when RULE_INIT

{ set static::DEBUG 1 }

when HTTP_REQUEST {

if { [active_members INF-HC-HTTP] < 1 }

{ switch -glob [string tolower [HTTP::path]]

{
  "*.gif" -
  "*.css" {
    HTTP::uri [string range [HTTP::uri] [string last / [HTTP::uri]] end]
  }
  default {
    HTTP::uri /
  }
}
pool QA-PH

} } elseif

{ [class match [string tolower [HTTP::uri]] starts_with QA-HC-URI] } {

pool INF-HC-HTTPDNN

}

else { pool INF-HC-HTTP } }

I get 2 errors - Line 4 [wrong of args] and line 23 [command not valid in current scope]. I’ve dug through the code and I don’t see any missing open/close brackets and the logic og the if/elseif’s makes sense to me but I’ve got to be missing something.