Forum Discussion
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
- Kevin_Stewart
Employee
This should totally work. As a test, log the value of $hostvar before the switch statement and see if it returns a value that is the same name as your iFile. - nitass
Employee
can you try this?when HTTP_REQUEST { get pool name 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]]] } check whether pool is down if { [active_members $hostvar] < 1} { switch [string tolower [HTTP::uri]] { "/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" } default { HTTP::respond 200 content [ifile get $hostvar] "Content-Type" "text/html" } } send to pool if pool is not down } else { pool $hostvar } } - nitass
Employee
sorry the default HTTP::respond was incorrect. can you correct it as following?from HTTP::respond 200 content [ifile get $hostvar] "Content-Type" "text/html" to HTTP::respond 200 content [ifile get ${hostvar}index_html] "Content-Type" "text/html" - pgsmith_120398
Altostratus
Hey nitass,
The only issue i saw with bundling these into a single iRule was that we need to have seperate VS for each SSL certificate and one for HTTP sites. We have a wildcard cert for some sites, but other applications require their own SSL certs. In this respect we will need to have multiple VS. My initial thought was to split the DG lookup and the sorry server into 2 iRules so that each VS would have its own pool irule and they would share a single SS rule. My thoughts were that this would provide the least overhead of irule execution and allow for management of a single SS rule instead of ~6. Do you see an issue with each VS recursing through the same SS iRule. I would prefer for it to be seperate for use in multiple VS.
- pgsmith_120398
Altostratus
Posted By nitass on 04/29/2013 07:50 AM sorry the default HTTP::respond was incorrect. can you correct it as following?from HTTP::respond 200 content [ifile get $hostvar] "Content-Type" "text/html" to HTTP::respond 200 content [ifile get ${hostvar}index_html] "Content-Type" "text/html"In this change would my datagroup only contain the application name APP1, APP2, instead of the entire file name APP1index_html, APP2index_html? Right now the DG contains the full file name.
- nitass
Employee
i see. would you mind trying this one?
when HTTP_REQUEST priority 600 {
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]] {
"/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"
}
default {
HTTP::respond 200 content [ifile get $hostvar] "Content-Type" "text/html"
}
}
}
} - pgsmith_120398
Altostratus
nitass,
That iRule provides the sorry page as expected. - pgsmith_120398
Altostratus
sorry i didnt include the first lines. Im trying again...
- pgsmith_120398
Altostratus
natass,
that rule results in a page not found error.
I believe i need to check what exactly the rule is seeing for the pool name. I have it in the DG exactly what its named in the ltm but it may be getting some additonal text appended to the name of the pool and therefore not finding it in the DG.
- pgsmith_120398
Altostratus
The logs state that the ifile can not be found.
Maybe im misunderstanding what the DG lookup rule is doing. My impression was that it would search the DG for the current pool. If it found a match it would then lookup the matching entry in the DG and place that value into the variable.
APP1-pool := APP1index.html
In the first line the current pool is APP1-pool. In the second line APP1-pool match value is APP1index.html so insert APP1index.html as $hostvar.
Is that correct?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com