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

  • You should not be specifying file extensions when using iFiles. Remove them, make sure all the file names are unique and all should be well.
  • Posted By pgsmith@ufl.edu on 04/29/2013 08:32 AM

     

    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?

    it cut out my variable in the first line. The first line should read:

     

    The logs state that the ifile **POOLNAME** can not be found

     

     

     

  • Posted By What Lies Beneath on 04/29/2013 08:34 AM

     

    You should not be specifying file extensions when using iFiles. Remove them, make sure all the file names are unique and all should be well.

    Thanks for your reply What Lies Beneath,

     

    The irule apperars to be working correclty, with the exception of the DG lookup part.

     

    I will take your advice and strip out the file extensions in the iRule. I wanted to name them so it would be very easy to know what file type they were. Would it make sense to name them as index_html, image_jpg, image_gif or somthing along those lines instead of with the extensions?

     

     

     

  • The issues looks like it was related to partitions and pools. The ltm was spitting out /esi/pool1-pool as the pool and I had it as just pool1-pool in the DG. Updating the DG to use /esi/pool1 results in the sorry server being properly displayed.

     

     

    Thanks everyone for your quick and very helpful assistance!
  • The issues looks like it was related to partitions and pools. The ltm was spitting out /esi/pool1-pool as the pool and I had it as just pool1-pool in the DG. Updating the DG to use /esi/pool1-pool results in the sorry server being properly displayed.

     

     

    Thanks everyone for your quick and very helpful assistance!
  • Ignore, you posted before I did and I didn't see it;

     

    Sorry, did I misunderstand? If you can call each iFile with the extension and it works then feel free to leave that alone. If not, then yes it would make sense to name them as you suggest - good idea.

     

     

    Regarding the DG and Pool I'm rather lost as to what the issue is here and what you are trying to do. Are you looking up the values in the DG using the hostname and wanting to populate the variable with the keyname? For example, with APP1-pool := APP1index.html, you are searching on the second value and populating the variable with the first? If so, that's never going to work as APP1index.html isn't a valid hostname. Please elaborate.

     

  • The idea is that i know what application the source computer is using based off the pool its being directed to. Since i know the pool (it could be the hostname as well i chose the pool name) i look up the current pool and in my DG relate the pool name with an iFile. I then populate the variable with the appropriate iFile that relates to the current pool and display that iFile. Everything appears to be working correctly now.