Forum Discussion
geffryti_32102
Nimbostratus
Mar 17, 2010how to use data group
Requirements:
1. system for redirecting certain host+uri to a different server (no pools)
2. use data group file to maintain uri-to-server list, so I can keep using the same irule for other VS.
Questions:
1. how do I call a data group from an irule? (assuming I already created the class in GUI and the name is redlist) will $::redlist work? My redlist is a string type with three fields, and below is an example. (some only has two fields).
2. I want to be able to use the second field as the new HOST and the third field as the new URI, but I'm having problem with inserting them. Pls see my draft below and let me know what's wrong and if there's a better way of doing this. Thanks.
REDLIST
"10.6.254.10/dir3/ 172.16.254.115 "
"10.41.254.121/dir6/ 172.16.254.115 /dir60000/"
"10.8.224.44/dir32/ 172.16.254.115 /dir60000/"
DRAFT SCRIPT
when HTTP_REQUEST {
find a match using host+uri against the class and
returns the whole string (field1 field2 field3)then
set it as newURI variable.
set newURI "[findclass [[HTTP::host][HTTP::uri]] $::redlist]"
if { $newURI ne "" } {
pick 2nd field and set as variable (newhost)
set newhost "[getfield $newURI " " 2]"
pick 3rd field and set as variable (newuri)
set newuri "[getfield $newURI " " 3]"
change host and uri
HTTP::host $newhost
HTTP::uri $newuri
Clear the newURI variable
unset newURI
}
}
- hoolio
Cirrostratus
Do you really have clients making requests using several different IP addresses to the same host VIP? Or do you have this iRule applied to multiple host VIPs? Or are you using a 0.0.0.0:80 VIP?when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]" find a match using host+uri against the class and returns the whole string (field1 field2 field3)then set it as newURI variable. set newURI "[findclass [[HTTP::host][HTTP::uri]] $::redlist]" if { $newURI ne "" } { log local0. "[IP::client_addr]:[TCP::client_port]: Matched line $newURI" Parse the three fields in the matched datagroup line scan $newuri {%s %s %s} unused host uri log local0. "Parsed: $unused $host $uri" change host and uri if {$host ne ""}{ HTTP::host $host } if {$uri ne ""}{ HTTP::uri $uri } } }
- geffryti_32102
Nimbostratus
Hey, thanks for taking time Aaron. - geffryti_32102
Nimbostratus
Almost forgot, thanks for the script! very intuitive... - geffryti_32102
Nimbostratus
I get the error below when saving the irule...line 20: [wrong args] [HTTP::host $host ]
- L4L7_53191
Nimbostratus
I'm not sure you can set the HTTP::host variable quite like that (the wiki implies it's read-only). I'm just looking at it here with no time to test but try changing this single line in the "host" test block below:if {$host ne ""}{ HTTP::host $host <<-- Change this line to: }
if {$host ne ""}{ HTTP::header replace Host $host <<--this one }
- geffryti_32102
Nimbostratus
sweet!!! it accepted it. Now I'm going to run it, I'll let you know how it goes! - L4L7_53191
Nimbostratus
I see the issue, and I see one other minor one with the current rule. Posting a new one for you in a minute. - L4L7_53191
Nimbostratus
Ok give this a try please:when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]" find a match using host+uri against the class and returns the whole string (field1 field2 field3)then set it as newURI variable. set newURI "[findclass [HTTP::host][HTTP::uri] $::redlist]" if { $newURI ne "" } { log local0. "[IP::client_addr]:[TCP::client_port]: Matched line $newURI" Parse the three fields in the matched datagroup line scan $newURI {%s %s %s} unused host uri log local0. "Parsed: $unused $host $uri" change host and uri if {$host ne ""}{ log local0. "Setting new host to $host" HTTP::header replace Host $host } if {$uri ne ""}{ log local0. "Setting new uri to $uri" HTTP::uri $uri } } }
- geffryti_32102
Nimbostratus
great! it's working... can you share what happened there and what you did? the log entry fixed it? - L4L7_53191
Nimbostratus
Great news. There were two very minor issues:
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects