Refine iRule with external class file

I have created an iRule where I pick which servers are used based off URI. IE. if www.mysite.ca/principal go to webnode and if www.mysite.ca/it go to drupal.

One thing I am having trouble with is the format of the external file. does anyone know how to write the rule so that only the excact match to the file is sent. Certain sites start similar , such /it and /italian. Wondering how the file can be written to pick the exact phrase I specify?

The iRule in place is

when HTTP_REQUEST {

if { [class match [HTTP::uri] starts_with DRUPALSITES] } {

pool DRUPAL

} else {

pool WEBNODE }

}

The External File looks like:

/eas,

/esaac,

/economics,

/edtech,

/efchr-events,

/emergency,

/emf,

etc.

I did try /eas/, and that works most of the time but certain sites would break. In this format, most sites append the / ; while others do not, and then i need to manually add the /

So I have opted not to have any trailing /

Anyone deal with a problem like this???

Thanks

Review this post. It should help you with the information that you need.

If not let us know.

http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/1170933/showtab/groupforums/Default.aspx

One thing I am having trouble with is the format of the external file. does anyone know how to write the rule so that only the exact match to the file is sent. Certain sites start similar , such /it and /italian. Wondering how the file can be written to pick the exact phrase I specify?

In this case it’s not how the class/datagroup is written exactly, but it’s the operator… You’re using “starts_with” so your /it is going to catch /italian as wel.. try “equals”..

Check out a list of valid operators in part 2 of iRules 101.. and while you’re at it, check out all the lectures in the series… They are very informative and really put the pieces together..

Thanks alot for the tips, I am going to look at the links.

I have tried the equals operator but still having problems , I think it is the way the external file is written. I just used a nano and created a list of files

/bi,

/africa,

etc

But I also tried /bi/ or /africa/. But very inconsistent results. sometimes the browser will return a error due to to many redirects and other times you need to add the / at the end or you get page not found.

I redirect between word press and drupal node on my cisco LB with absolutely no problems. It seems I am not able to match the right syntax in the external file.

with Cisco I have the rule as such:

Has anyone worked on a similar setup?

Thanks

owner WSG-McGill

content WSG-http--ehs-dir

vip address 132.216.177.140

protocol tcp

port 80

add service drupalnode1.wsg.http

add service drupalnode2.wsg.http

url “/ehs”

content WSG-http-ehs-con

vip address 132.216.177.140

protocol tcp

port 80

add service drupalnode1.wsg.http

add service drupalnode2.wsg.http

url “/ehs/*”

If you are willing to switch from an external file to class/datagroup, I think the code I posted here: DevCentral - An F5 Technical Community at “07/06/2011 11:27 PM” may be able help you accomplish what you are looking to do.

I agree, it does sound a bit like a ‘quick fix’ solution.Surely you can never be 100% absolutely certain that something won’t go wrong.

Thanks guys

we have refined the rule a bit , this works for the most part but I need to maintain 2 list, one for webnode and one for drupal nodes.

when HTTP_REQUEST {

if {[matchclass [HTTP::uri] starts_with $::WPS]}{

log local0. “Requested URL starts with [HTTP::uri], directing to pool WEBNODE”

pool WEBNODE

}

elseif {[matchclass [HTTP::uri] starts_with $::DRUPALSITES]}{

log local0. “Requested URL starts with [HTTP::uri], directing to pool DRUPAL”

pool DRUPAL

}

else {

log local0. “Requested URL does not match any class: [HTTP::uri], defaulting to pool WEBNODE”

pool WEBNODE

}

}

However, one of the developers is working on this iRule but it still not working.

when HTTP_REQUEST {

set SITE [lindex [split HTTP::uri “/”] 1]

log local0. “Requested site: $SITE”

if {[matchclass $SITE equals $::WPS]}{

log local0. “Requested URL starts with [HTTP::uri], directing to pool WEBNODE”

pool WEBNODE

}

elseif {[matchclass $SITE equals $::DRUPALSITES]}{

log local0. “Requested URL starts with [HTTP::uri], directing to pool DRUPAL”

pool DRUPAL

}

else {

log local0. “Requested URL does not match any class: [HTTP::uri], defaulting to pool WEBNODE”

pool WEBNODE

}

}

I did follow your post and found some interesting info which may us help refine this even more.

Chung

If your goal is to maintain one class, research the findstr command.

http://devcentral.f5.com/wiki/iRules.findstr.ashx

Working with one of our web programmers we found the right combination of iRule.

Thanks

when HTTP_REQUEST {

set SITE [lindex [split [string tolower [HTTP::uri]] “/”] 1]

if {[matchclass $SITE equals $::DRUPALSITES]}{

pool DRUPAL

}

elseif {[matchclass $SITE equals $::WPS2]}{

pool WEBNODE

}

else {

log local0. “Requested URL does not match any class: [HTTP::uri], defaulting to pool WEBNODE”

pool WEBNODE

}

}

The biggest problem I found was the external file format, although there are many examples no are specific on how the structure interacts with the iRule

using nano editor

“word”, is what I need for the equals variable.

“/word,” is fine for contains or starts_with variable.

“word”:=“key1” which is the b class format works but no one at F5 support could explain the the “key1” variable. And honestly, it is faster for me just to use the nano editor vs the b class format.

Thanks for everyone’s help.

Chung