Forum Discussion
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
17 Replies
- nitass
Employee
e.g. - Srinivasan_G_31
Nimbostratus
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.
- nitass
Employee
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? where is the decimal? is it in uri, http header or somewhere else? can you provide an example? - Srinivasan_G_31
Nimbostratus
Yes. The decimal is on the URI. Following is the example.
http://help.abcd.com/1234.aspx
The string is random (0-9).
- nitass
Employee
there are several ways to achieve. you know each has pro and cons. this is just one example of them.[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
- Srinivasan_G_31
Nimbostratus
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?
- What_Lies_Bene1
Cirrostratus
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...)?
- nitass
Employee
[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
- Srinivasan_G_31
Nimbostratus
Steve, Nitass - I would prefer not to use regexp as few references say it degrades the performance. Any other suggestions?
- Srinivasan_G_31
Nimbostratus
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com