| By Colin Walker | Article Rating: |
|
| October 30, 2009 01:12 PM EDT | Reads: |
698 |
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.
Well we made it to 30 editions of the 20LoL. Soon we’ll break 100 iRule examples that are under 21 lines of code each. Pretty neat stuff, if you ask me. This week is the hoolio show, it seems. The guy is just a monster in the forums, what can I say? I sure am glad he’s on our side. I’ve got three examples that I randomly pulled from the forums because I thought they were cool. Only later did I realize that he had penned them all. So big thanks yet again to Aaron and all his hard work to better the community.
Pre-loaded searches based on host name
http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=86016&view=topic
This cool little example is a neat spin on a simple HTTP redirect. The basic idea is to redirect to a given search site and set the search parameter to be the original host name of the request. So I could request bobschickenshack.com and be redirected to a search for bobschickenshack on the search page of my choosing. Very cool idea, and darn easy to implement.
when HTTP_REQUEST {
# Rewrite the host header to www.yahoo.com and the
# uri to /search?q=$host where $host is the originally requested hostname
HTTP::header replace "www.yahoo.com"
HTTP::uri "/search?q=[HTTP::host]"
}
More fun with nested switch
http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=85807&view=topic
I know we’ve covered switch before, but this is yet another good use of it and I really like the idea of selecting snatpools based on which server the request is going to end up going to. I trimmed this one down a little but only by removing a few of the possible snatpool options, all logic is the same, even though it’s just an excerpt of the overall solution provided.
when LB_SELECTED {
switch [LB::server addr] {
222.35.42.126 {
switch [IP::client_addr] {
192.168.3.11 { snatpool snat_crt_test2 }
default { snatpool snat_crt_pool }
}
}
221.218.248.155 {
switch [IP::client_addr] {
192.168.3.11 { snatpool snat_uni_test2 }
default { snatpool snat_uni_pool }
}
}
default { snat automap }
}
}
Updating referrers
http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=85807&view=topic
Hoolio does a good job of not only pointing out the inherent problem with trying to replace referrer headers with hostnames from requests, but giving an option that works as desired even if it’s a little bit different direction than the OP was headed. This is a good example of in-line string replacement with string map, too, which is an often under used command that’s worth a look.
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: New [HTTP::method] request to [HTTP::host][HTTP::uri]\
with Referer [HTTP::header Referer]"
if {[HTTP::header exists "MyHeader"]} {
log local0. "[IP::client_addr]:[TCP::client_port]: Updating Referer to\
[string map -nocase {http:// https://} [HTTP::header Referer]"
HTTP::header replace Referer "[string map -nocase {http:// https://} [HTTP::header Referer]"
}
}
when HTTP_REQUEST priority 501 {
log local0. "[IP::client_addr]:[TCP::client_port] (501): Current Referer [HTTP::header Referer]"
}
There you have it, 3 more iRules to show off just how much you can do in only 20 lines of code. Next time we’ll break past the 100 examples mark. See ya then.
#Colin
Read the original blog entry...
Published October 30, 2009 Reads 698
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.
- Qt DevDays 2009 - Munich
- The Power of Google and the Promise of Cloud Computing
- Unlocking the Cloud with Enterprise Private PaaS
- Big Data Kills 30-Year-Old Market
- Securing the Cloud and Establishing a Level of Trust
- ExaGrid Sets New Standard in Backup Price, Performance and Capacity with Launch of EX10000E Disk Backup System with Data Deduplication and Expanded 100TB GRID Capacity
- Cloud Computing: Transformative Technology With Financial Benefits
- The Enterprise Private Cloud - From Infrastructure to Applications
- Moving HPC Apps to the Cloud: The Practitioner's Perspective
- Business Service Management: Aligning Business & IT
- IGEL and Quest Software Advance Virtual Desktop Management by Integrating Quest vWorkspace into IGEL Universal Desktops
- World's First 16GB, 2 Virtual Rank Memory Module
- Is Microsoft as Free as Open Source?
- IBM’s Linux-Based ‘Cloud-in-a-Box’ Makes its First Sale
- United Planet offers practical portal building tips for SMBs
- Qt DevDays 2009 - Munich
- The Power of Google and the Promise of Cloud Computing
- Developing APIs for the Cloud
- Unlocking the Cloud with Enterprise Private PaaS
- Testing the Limits with Jack Margo SVP of Developer Shed, (part 1)
- The Bunker achieves PCI DSS Compliance
- Big Data Kills 30-Year-Old Market
- Securing the Cloud and Establishing a Level of Trust
- Excuse Me But Is That a Gazebo On Your Site?!
- The Top 250 Players in the Cloud Computing Ecosystem
- Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
- An Introduction to Ant
- Google Web Toolkit: Finally Java Has Been Put into JavaScript!
- AJAX World RIA Conference News - AJAX & RIA with Server-Side JavaScript
- Python Creator Guido van Rossum to Present the Next-Generation Python 3000
- White Paper: "Extended Validation SSL Certificates"
- CEO of Hyperic, Javier Soltero on SYS-CON.TV
- Rating JRuby, Jython, and Groovy on the Java Platform
- Perforce Software Delivers State-of-the-Art Application Lifecycle Management
- TurboGears - Python-Based Framework for AJAX Web Development
- iPhone 3G Only Looks Cheaper





























