Forum Discussion
Prakash_90163
Nimbostratus
Apr 05, 2012Perl script to create an Application service using f5.http template
Hi,
Do we have any Perl script available to create an Application service using f5.http template.
Thanks,
Prakash
Mar 04, 2008
You beat me to it. I would absolutely agree with removing the regular expressions. The getfield and findstr commands are much more optimized for extracting strings than are regular expressions so and we recommend not using regexps unless there is no other alternative.
Using a switch -vs- findclass or matchclass is really a decision for you to make. For 100 or fewer items, a switch will perform faster, but it may be easier to maintain the data in a separate list. Only you can answer that. If you do end up going with a data group, then make sure you take into account the case where a match isn't made. In your iRule, if there is no match, you will redirect to "http://$index" which most likely won't work.
Here's My take at the iRule using a switch.
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/ndk_website" } {
set website [getfield [HTTP::uri] "/" 3]
set index [findstr [HTTP::uri] "/cms"]
switch -glob $website {
"nsportal" {
this will match only "nsportal"
set redirect_map "server1"
}
"*otherportal" {
this will match anything ending in 'otherportal'
set redirect_map "server2"
}
"myportal*" {
this will match anything starting with 'myportal'
set redirect_map "server3"
}
default {
make sure you have a default case
set redirect_map "server4"
}
}
log local0. "URI: [HTTP::uri]"
log local0. "Website: $website"
log local0. "Index: $index"
log local0. "Redirect: $redirect_map"
HTTP::redirect "http://$redirect_map$index"
}
}
This code could be optimized a bit more by removing the local variables and I would definitely remove the log statements after you test this.
Hope this get's you going in the right direction.
-Joe
- Dario_GarridoMay 06, 2019
Noctilucent
You have a magnificent approach already explained by Stan
REF - https://devcentral.f5.com/questions/irule-to-query-sql-for-auth-and-attributes-52973
KR, Dario.
- Leonardo_Silva1Nov 15, 2021
Altostratus
The url posted by Dario is unavailable.
Is there any way to fetch this info? I really need it!
- Dario_GarridoNov 16, 2021
Noctilucent
Try this:
https://devcentral.f5.com/s/feed/0D51T00006zuYzdSAE