20 Lines or Less #4

What could you do with your code in 20 Lines or Less? That's the question I ask every week, and every week I go looking to find cool new examples that show just how flexible and powerful iRules can be without getting complicated.

Last week I was out on vacation, serenading the good people of Shelton, WA with some thick, groovy funk. As such, the 20LoL had to be put on hold  You can consider this your special, super-elite, bonus edition of 20 Lines or Less though, since that sounds cooler.

This edition is all about the forums. There are all sorts of awesome things going on in the forums every day.We're seeing a positively epic volume of posts these days from the rockin' community which, lucky for me, are ripe with all sorts of tasty iRule tidbits that fit into the 20LoL format just great.

So here we are, this week's 20Lines or Less iRules, thanks to the forums and the awesome community behind them.

 

Round robin redirect requests

http://devcentral.f5.com/s/Default.aspx?tabid=53&forumid=5&postid=23540&view=topic

In this case the user needed to round robin select between a couple of different redirect statements to even out load on systems (presumably systems not behind the BIG-IP or in a pool). Here's a simple rule to get that handled, compliments of Joe.

when RULE_INIT {
set ::whichone 0
}
when HTTP_REQUEST {
switch $::whichone {
0 {
HTTP::redirect "http://Server1/blah"
set ::whichone 1
}
default {
HTTP::redirect "http://Server2/blah"
set ::whichone 0
}
}
}

Network based traffic routing

http://devcentral.f5.com/s/Default.aspx?tabid=53&forumid=5&postid=23714&view=topic

Hoolio comes through in this 4.x to 9.x rule conversion thread, helping another member get where they need to go. Apparently where they needed to go was two different pools, based on which client network the connections were coming in from. Matchclass and IP matching to the rescue.

when CLIENT_ACCEPTED {
if { [matchclass [IP::remote_addr] equals $::my_networks_class] } {
log local0. "[IP::client_addr]:[TCP::client_port] matched \$::my_networks_class: $::my_networks_class"
pool Visionware_web28
} else {
log local0. "[IP::client_addr]:[TCP::client_port] didn't match \$::my_networks_class: $::my_networks_class"
pool Visionware_web27
}
}

URI Based URI rewriting

http://devcentral.f5.com/s/Default.aspx?tabid=53&forumid=5&postid=23691&view=topic

In this thread I got to help out user stevehong by putting together an example that uses switch to determine when to rewrite the URI and when not, before passing the traffic to the default pool for the Virtual. Nothing fancy here, just a simple example of switch, URI replacement, and a little logging for flavor.

when HTTP_REQUEST { 
switch [HTTP::uri] {
"/app/DentegraPortal/TransEDI" -
"/app/DeltaCarePortal/TransEDI" -
"/app/B2BEnt/TransEDI" -
"/app/B2BPMI/TransEDI" {
log "Incoming uri - [HTTP::uri] being translated to /b2b/transportServlet/TransEDI"
HTTP::uri "/b2b/transportServlet/TransEDI"
}
}
}

 

There you have it, another 20LoL in the books. What did we learn this time? Forums FTW.  Hopefully you're finding these useful or at least interesting. If you are, be sure to pass them along to your friends, and maybe even let me know. And don't worry, no kittenz were harmed in the making of this post.

 

#Colin

Published May 07, 2008
Version 1.0

Was this article helpful?

No CommentsBe the first to comment