Srinivasan_G_31
Oct 25, 2012Nimbostratus
iRule help
Hi,
I want an iRule which can match a specific URI on an incoming http request and redirect traffic to a specific pool member of a pool. Please help.
Srini
Hi,
I want an iRule which can match a specific URI on an incoming http request and redirect traffic to a specific pool member of a pool. Please help.
Srini
sol9800: Using an iRule to load balance HTTP requests to multiple pools
http://support.f5.com/kb/en-us/solutions/public/9000/800/sol9800.html
sol13753: Using HTTP Classes to load balance HTTP requests to multiple pools
http://support.f5.com/kb/en-us/solutions/public/13000/700/sol13753.html
hope this helps.
Thank you for the reference. Is there a way i can match decimal digits 0 to 9 in an iRule and make a decision on which node/pool member it should go to? I don't want to use regular expressions though since that may hamper the performance.
Yes. The decimal is on the URI. Following is the example.
http://help.abcd.com/1234.aspx
The string is random (0-9).
[root@ve10:Active] config b virtual bar list
virtual bar {
snat automap
destination 172.28.19.79:80
ip protocol 6
rules myrule
profiles {
http {}
tcp {}
}
}
[root@ve10:Active] config b pool foo1 list
pool foo1 {
members 200.200.200.101:80 {}
}
[root@ve10:Active] config b pool foo2 list
pool foo2 {
members 200.200.200.111:80 {}
}
[root@ve10:Active] config b pool foo list
pool foo {
members 200.200.200.101:80 {}
}
[root@ve10:Active] config b rule myrule list
rule myrule {
when HTTP_REQUEST {
set path [HTTP::path]
switch -glob [HTTP::path] {
"*1234*" { pool foo1 }
"*5678*" { pool foo2 }
default { pool foo }
}
}
when HTTP_RESPONSE {
log local0. "[IP::client_addr]:[TCP::client_port] -> [clientside {IP::local_addr}]:[clientside {TCP::local_port}] -> [IP::remote_addr]:[TCP::remote_port] | [LB::server pool] | $path | [HTTP::status]"
}
}
[root@ve10:Active] config tail -f /var/log/ltm
Oct 28 09:18:37 local/tmm info tmm[7926]: Rule myrule : 172.28.20.11:59463 -> 172.28.19.79:80 -> 200.200.200.101:80 | foo1 | /1234.aspx | 404
Oct 28 09:18:39 local/tmm info tmm[7926]: Rule myrule : 172.28.20.11:59464 -> 172.28.19.79:80 -> 200.200.200.111:80 | foo2 | /5678.aspx | 404
Oct 28 09:18:43 local/tmm info tmm[7926]: Rule myrule : 172.28.20.11:59465 -> 172.28.19.79:80 -> 200.200.200.101:80 | foo | /something/index.html | 404
Will this example only look for "1234" as a string and perform redirect to a pool or i can match any string from 0 to 9 at any length using the switch statement?
In nitass' example, any request with a HTTP path containing 1234 will be sent to Pool foo1, containing 5678 to Pool foo2. If you wanted to account for other combinations you would need to keep adding text to match and pool statements. Is there a specific position in the URL you would like to match on (first digit, seccond, third...)?
[root@ve10:Active] config b rule myrule list
rule myrule {
when HTTP_REQUEST {
if { [scan [HTTP::uri] {/%[^.]} f_name] == 1 } {
switch -regexp $f_name {
^[0-9]+$ { log local0. "URI is [HTTP::uri] | $f_name is number" }
default { log local0. "URI is [HTTP::uri] | $f_name is not number" }
}
}
}
}
[root@ve10:Active] config cat /var/log/ltm
Oct 29 21:26:01 local/ve10 err mcpd[3815]: 01020066:3: The requested rule (myrule) already exists in partition Common.
Oct 29 21:29:49 local/tmm info tmm[7926]: Rule myrule : URI is /1234.aspx | 1234 is number
Oct 29 21:29:57 local/tmm info tmm[7926]: Rule myrule : URI is /1234abcd.aspx | 1234abcd is not number
Oct 29 21:30:10 local/tmm info tmm[7926]: Rule myrule : URI is /xyz1234.aspx | xyz1234 is not number
Oct 29 21:30:14 local/tmm info tmm[7926]: Rule myrule : URI is /somethingelse | somethingelse is not number
this is another example we have discussed in the past.
how to match 6 digtals via command except matches_regex
https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/aft/2158816/asg/54/Default.aspx
Steve, Nitass - I would prefer not to use regexp as few references say it degrades the performance. Any other suggestions?