Forum Discussion

pgsmith_120398's avatar
pgsmith_120398
Icon for Nimbostratus rankNimbostratus
Apr 29, 2013

Use dynamic variable derived from datagroup in irule

This is probably a very easy question...

 

We are testing using iRules to host multiple web server clusters beneath a single public IP using iRules. We have an iRule that looks at a datagroup and based off the URL will direct it to the pool that hosts the webservers for that particular application.

 

 

when HTTP_REQUEST {

if { [class match [string tolower [HTTP::host]] eq /ESI/wild.erp-dg] } {

set hostvar [class search -value /ESI/wild.erp-dg eq [string tolower [HTTP::host]]]

pool $hostvar }

}

 

That all works just fine and dandy.

 

Now we are attempting to set up an iRule to handle the sorry server functionality. I have the sorry server rule running fine with the code:

 

 

 

when HTTP_REQUEST {

 

if { [active_members [LB::server pool]] < 1} {

 

switch [string tolower [HTTP::uri]] {

 

"/" {

 

HTTP::respond 200 content [ifile get index_html] "Content-Type" "text/html"

 

}

 

"/ufstyle.css" {

 

HTTP::respond 200 content [ifile get ufstyle.css] "Content-Type" "text/css"

 

}

 

"/myuflheaderborder.jpg" {

 

HTTP::respond 200 content [ifile get myuflheaderborder.jpg] "Content-Type" "image/jpeg"

 

}

 

"/myuflheader_bg.jpg" {

 

HTTP::respond 200 content [ifile get myuflheader_bg.jpg] "Content-Type" "image/jpeg"

 

}

 

"/myuflheader.gif" {

 

HTTP::respond 200 content [ifile get myuflheader.gif] "Content-Type" "image/jpeg"

 

}

 

"/myufllogo.gif" {

 

HTTP::respond 200 content [ifile get myufllogo.gif] "Content-Type" "image/jpeg"

 

}

 

"/uflwordmark.gif" {

 

HTTP::respond 200 content [ifile get uflwordmark.gif] "Content-Type" "image/jpeg"

 

}

 

}

 

}

 

}

 

 

This produces a nice HTML page in the event the pool members are down.

 

Our application development team has created unique sorry pages for each application. The HTML pages will be different but the images and CSS will all remain the same. The idea i had was to simply upload each applicaitons HTML page as an iFile with a unique name.

 

ex: app1index_html, app2index_html, etc.

 

I would then create a data group that would relate the current pool name to the appropriate appliation index_html file.

 

pool1 := pool1index_html

 

once i have the resulting match i would store the matching entry in a variable and use that variable in the http::respond portion of the iRule that displays the HTML page.

 

 

The code i have right now is:

 

 

when HTTP_REQUEST {

 

if { [class match [string tolower [LB::server pool]] eq /ESI/sorryserver-dg] } {

 

set hostvar [class search -value /ESI/sorryserver-dg eq [string tolower [LB::server pool]]]

 

}

 

if { [active_members [LB::server pool]] < 1} {

 

switch [string tolower [HTTP::uri]] {

 

"/" {

 

HTTP::respond 200 content [ifile get $hostvar] "Content-Type" "text/html"

 

}

 

"/ufstyle.css" {

 

HTTP::respond 200 content [ifile get ufstyle.css] "Content-Type" "text/css"

 

}

 

"/myuflheaderborder.jpg" {

 

HTTP::respond 200 content [ifile get myuflheaderborder.jpg] "Content-Type" "image/jpeg"

 

}

 

"/myuflheader_bg.jpg" {

 

HTTP::respond 200 content [ifile get myuflheader_bg.jpg] "Content-Type" "image/jpeg"

 

}

 

"/myuflheader.gif" {

 

HTTP::respond 200 content [ifile get myuflheader.gif] "Content-Type" "image/jpeg"

 

}

 

"/myufllogo.gif" {

 

HTTP::respond 200 content [ifile get myufllogo.gif] "Content-Type" "image/jpeg"

 

}

 

"/uflwordmark.gif" {

 

HTTP::respond 200 content [ifile get uflwordmark.gif] "Content-Type" "image/jpeg"

 

}

 

}

 

}

 

}

 

 

As you can see i really just mashed the first two iRules together to try to accomplish what i think should work. However this does not return any HTML file. Does anyone out there have any suggestions on how to get this working and if im going in the right direction to accomplish my end goal of presenting dynamic HTML iFiles based off pools.

 

18 Replies