Welcome!

Java IoT Authors: Yeshim Deniz, Pat Romanski, Liz McMillan, Zakia Bouachraoui, Carmen Gonzalez

Related Topics: Java IoT, Microservices Expo

Java IoT: Blog Feed Post

Twenty Lines or Less #29

That's the question I ask (almost) every week

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.

29 editions later and still going strong. The 20LoL is a testament to just how many different things can be done with iRules in just a few lines of code.  Just imagine the possibilities if this were the 30LoL.

This week I’ve got three more examples, all from the forums. Today we’ll cover dealing with port numbers in HTTP requests, checking pool status from within an iRule, and more fun with nested switching.  The community keeps putting out fantastic examples so I just keep on writing about them.  Keep it up.

Removing HTTP request port numbers

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

Hoolio came up with a trio if examples of how to deal with port numbers in your HTTP requests. All of them are good, depending on your situation, but I’m only going to highlight one here.  Go check out the forum post above to see the other two and get the context of the thread.

when HTTP_REQUEST {
# Check if Host contains a colon
if {[HTTP::host] contains ":"}{
# Redirect client to requested host minus the port and preserve the original URI
HTTP::redirect "
https://[getfield [HTTP::host] ":" 1][HTTP::uri]"
}
}

 

Checking pool member status

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

User cmbhatt, another one of our power-users, came up with a very cool example of using the LB::select command and HTTP::respond to show the status of a selected pool member.  It even has a built in meta-refresh so you can continually monitor the status. Pretty neat stuff.

when HTTP_REQUEST {
if {[HTTP::uri] eq "/status" } {
scan [LB::select] %s%s%s%s%d command current_pool command2 current_member current_port
eval [LB::select]
set response "<html><head><title>$current_pool Pool Status - [clock format [clock seconds]]</title><meta http-equiv='refresh' content='10; url=
http://[HTTP::host]/status'></head>"
if { [active_members $current_pool] < 1 } {
append response "POOL NAME:$current_pool<br/> CURRENT MEMBER:$current_member:$current_port<br/> STATUS: DOWN <br/></body></html>"
} else {
append response "POOL NAME:$current_pool<br/> CURRENT MEMBER:$current_member:$current_port<br/> STATUS: UP <br/></body></html>"
}
}
HTTP::respond 200 content $response "Content-Type" "text/html"
}

More nested switching and pool selection vs. redirection

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

This rule stemmed from cmbhatt, once again, then I went in and made some tweaks where I think it made sense, as you can see in the thread.  The idea is that the user is looking to do some inspection of first the host, then in some cases, depending on what the host is, the URI as well.  Based on what’s found either a load balancing decision is made or a redirect is issued.  This is yet another awesome example of how iRules can turn something that would be ridiculously tricky or even impossible elsewhere into something pretty straight-forward.

when HTTP_REQUEST {
switch [HTTP::host] { 
"www.mydomain.eu" {
switch [HTTP::uri] {
"/" {  HTTP::respond 301 Location "
http://www.mydomain.eu/zz/index.html" }
default { pool mydomain_eu_pool    }
}
}
"www.mydomain.be" {
switch [HTTP::uri] {
"/" { HTTP::respond 301 Location "
http://www.mydomain.eu/be/zz/index.jsp" }
default { pool mydomain_be_pool }
}
}
"www.mydomain.nl" { HTTP::respond 301 Location "
http://www.mydomain.eu/nl/zz/index.jsp" }
"www.mydomain.fr" -
"mydomain.fr" { HTTP::respond 301 Location "
http://www.mydomain.eu/fr/zz/index.jsp }
"www.mydomain.lu" { HTTP::respond 301 Location "
http://www.mydomain.eu/lu/zz" }
}
}

 

There you have it, three more iRules to get you on your way in less than 21 lines of code.  Feel free to submit ideas, suggestions of feedback, as always.

Read the original blog entry...

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.

IoT & Smart Cities Stories
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...