Forum Discussion
iRule to read key/value pair from Data Group lists
Cany anybody help or provide any suggestions for the above condition iRule.
Thanks.
- Ryan_Paras_7933Nimbostratusto be clear, sample=sample1 will be passed as some type of http header, or will sent as part of a HTTP POST or GET?
- Colin_Walker_12Historic F5 Account
So all you're looking for is to look up a custom header value in a Data Group and have that map to a pool member address. That's very doable. You'd want something like:
when HTTP_REQUEST { if {[HTTP::header exists "myCustomHeader"]} { set member [class match -value [HTTP::header "myCustomHeader"] equals myClassName] if {$member ne ""} { pool member $member 80 } } }
This would require a data group named myClassName that looks like you described above, sample1 with a value of 192.168.1.11, sample2 with a value of 192.168.1.12, etc. and it assumes the custom header is named "myCustomHeader" with the values of sample1, sample2, etc.
You can, of course, change any of the variable or data group names to be more to your liking.
Colin
- Narendra_26827NimbostratusIt comes as an http post in http request header
- Colin_Walker_12Historic F5 AccountYeah, that should be fine. If there's a header that contains the value, the above rule should work once you put in the right names for the header and create the data group, alter the data group name in the iRule, etc.
- Narendra_26827NimbostratusThanks Colin.
- Colin_Walker_12Historic F5 AccountIf you just want the name of the key you can use the -name option. You can also read more about the class command here - Click Here
- hooleylistCirrostratus
I always like to check that the value of a header or cookie is not null instead of checking to see if it exists before trying to use the value. It's an odd corner case to check for, but I've seen a few rules break by assuming the header or cookie will have a value if it's present.
if {[HTTP::header "myCustomHeader"] ne ""} { ...
If the header isn't set, the header command will return a null string. You don't have to worry about an error if the header doesn't exist.
Aaron
- Narendra_26827NimbostratusThanks Aaron i will take that note into consideration.
- Colin_Walker_12Historic F5 AccountWell, I can tell you that the pool member command is expecting either no port, or a port as a third argument. I'm not sure how well it's going to handle having the port tacked on with a colon. You might need to use split to separate the IP and port and pass them in separately, but that's pretty easy.
- Narendra_26827NimbostratusThanks a lot Colin for your suggestions and insights.
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