| By Colin Walker | Article Rating: |
|
| August 6, 2009 07:30 PM EDT | Reads: |
2,290 |
What could you do with your code in 20 Lines or Less? That's the question I ask (almost) every week for the devcentral community, and every week I go looking to find cool new examples that show just how flexible and powerful iRules can be without getting in over your head.
Here are a few more cool iRules from the forums. This week I’ve included one of the simplest, shortest iRules to ever make the 20LoL. It just struck me as something quite useful that I’m willing to bet several people will look at and say “oh, that’s handy” despite the fact that it’s not complex or long.
Keep the code coming.
Multiple Matches with Switch
http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=60678&view=topic
Joe answered a plea for help from the forums that showed how to modify an existing iRule that mad use of switch dropping through to multiple match cases. This is a great way to streamline your rule and I wanted to post this here as it’s a good example of what it looks like.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/xml/order.asp*" -
"/xml/status.asp*" -
"/vmsxml/order.asp*" -
"/vmsxml/status.asp*" -
"/_xmlbeta/status_mismo21.asp*" -
"/_xmlbeta/status.asp*" -
"/_xmlbeta/rels_status_mismo21.asp*" -
"/vendor/status.asp*" {
pool host.mydomain.com_B2B_HTTPS
}
"/BatchProcessing*" {
pool host.mydomain.com_BatchPro_HTTPS
}
default {
pool host.mydomain.com_GUI_HTTPS
}
}
}
Mod_Rewrite to iRules conversion
http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=62642&view=topic
Hoolio strikes again with this awesome conversion of some mode rewrite rules into an iRule format. This is extremely handy for centralizing and streamlining these types of rewrites. He makes it look so easy, doesn’t he?
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: Original URI: [HTTP::uri]"
# Check if URI matches first format using scan
if {[scan [HTTP::uri] {/%[Oo]ffers/%[0-9:].html} a b] == 2}{
# Scan matched two strings, so rewrite the URI with the second match value
HTTP::uri "/pages/ViewOffer.aspx?id=$b"
} elseif {
# Continue with next rule
}
}
when HTTP_REQUEST priority 501 {
# This event is added for debug only to log the updated HTTP::uri value
# Comment it out/remove after testing is complete
log local0. "[IP::client_addr]:[TCP::client_port]: Updated URI: [HTTP::uri]"
}
Insert Pool Info
http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=60663&view=topic
In likely the shortest, simplest iRule to date in the 20 Lines or Less, hoolio shows how to insert information about the chosen pool into a header on a server response. This one struck me as useful enough to post. I usually go for things that are a little more flashy but there’s something to be said for simplicity if it gets the job done.
when HTTP_RESPONSE {
# Insert pool name, member IP:port in a header named Pool-Info
HTTP::header insert Pool-Info [LB::server]
}
The things that you can do in less than 21 lines of iRules code continue to amaze and interest me, so I’ll be back next week with three more examples of just how much you can accomplish in those scant few lines of code.
Read the original blog entry...
Published August 6, 2009 Reads 2,290
Copyright © 2009 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Colin Walker
Coming from a *Nix Software Engineering background, Colin is no stranger to long hours of coding, testing and deployment. His personal experiences such as on-stage performance and the like have helped to foster the evangelist in him. These days he splits his time between coding, technical writing and evangalism. He can be found on the road to just about anywhere to preach the good word about ADCs, Application Aware networking, Network Side Scripting and geekery in general to anyone that will listen.
Colin currently helps manage and maintain DevCentral (http://devcentral.f5.com). He is also a contributor in many ways, from Articles to Videos to numerous forum posts, to iRules coding and whatever else he can get his hands on that might benefit the community and allow it to continue to grow.
- 1st Annual Government IT Conference & Expo: Themes & Topics
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- IBM, Microsoft, Others in Lock-Picking Cloud API Push
- RothmanResearch.com Market Review and Company Analysis on FULT, DISH, ASBC, CTRP, FSLR and CRBC
- Yahoo! Query Language
- United Planet offers practical portal building tips for SMBs
- Stock in Focus: Sunwin International Neutraceuticals
- The Time Is Right for Enterprise Cloud Computing
- The Bunker achieves PCI DSS Compliance
- Qt DevDays 2009 - Munich
- Testing the Limits with Jack Margo SVP of Developer Shed, (part 1)
- Excuse Me But Is That a Gazebo On Your Site?!
- 1st Annual Government IT Conference & Expo: Themes & Topics
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Is Microsoft as Free as Open Source?
- The Curious Case of Build Release Management eBook
- Cloud Security Is Nothing New but It Changes Everything!
- IBM, Microsoft, Others in Lock-Picking Cloud API Push
- Research and Markets: Global Developer Population and Demographic Study 2009, V1 Will Estimate Specific Developer Target Markets' Size
- RothmanResearch.com Market Review and Company Analysis on FULT, DISH, ASBC, CTRP, FSLR and CRBC
- Yahoo! Query Language
- United Planet offers practical portal building tips for SMBs
- Stock in Focus: Sunwin International Neutraceuticals
- The Time Is Right for Enterprise Cloud Computing
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- The Top 250 Players in the Cloud Computing Ecosystem
- Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
- Ulitzer to Give Drupal 6.0 Its Biggest Scalability Challenge Yet
- An Introduction to Ant
- Appcelerator Named "Platinum Sponsor" of AJAX World Conference & Expo
- "What's New and Exciting About the Web Right Now?" Asks Time Magazine
- Oracle To Keynote Cloud Computing Expo
- First Eclipse Project Targeting PHP Now Available
- AJAX World - Two Great PDF Creators
- C#, Turbo Pascal, C++, PHP...and the LEGO Brick: Denmark's Leading Exports
- Rolling Your Own MVC: The Page Load Scenario


































