Forum Discussion
Yozzer
Nimbostratus
Jun 03, 2011Data Group List use in a switch
Hi
I have a Data Group list called allowed_urls that has a list of accepted urls which i want to use in an irule.
switch -glob [HTTP::uri] {
"*temp.txt" {
do stuff
}
"*users.txt" {
do stuff
How do i use Data Group lists in the example above?
Thanks
21 Replies
- hoolio
Cirrostratus
Hi Yozzer,
You can't really use a datagroup in a switch statement. You could use an if/elseif/.../else chain to check multiple datagroups.
Which version are you running? If you want better suggestions, can you provide a more detailed example of what you're trying to do?
Thanks, Aaron - Colin_Walker_12Historic F5 AccountMore realistically what you want to do is set up an action for each file type. If that's the case, then make sure the action is associated with the file type in the data group.
For instance:
class allowed_urls {
"temp.txt" {"action1"}
"users.txt" {"action2"}
}
etc.
Then you'd just need some code to act upon those things:when HTTP_REQUEST { set action [class match -value [string tolower [HTTP::uri]] equals allowed_urils] if {$action ne ""} do stuff $action } }
The only tricky part there is knowing which commands to use with the "$action" variable. I'm assuming they're all going to be similar actions though, like executing the pool command or something.
Colin - Matt_Breedlove_
Nimbostratus
I do something like this to do a two factor firewall type rule that includes a src ip whitelist chained to particular URI prefix's. I really like this and its not terrible to read/maintain and uses switch plus datagroups for the winwhen HTTP_REQUEST { switch -glob [URI::decode [string tolower [HTTP::uri]]] { /customer1* { if { ([class match [IP::remote_addr] equals $::customer1_ip_whitelist]) } { return } } /customer2* { if { ([class match [IP::remote_addr] equals $::customer2_ip_whitelist]) } { return } } /customer3* { if { ([class match [IP::remote_addr] equals $::customer3_ip_whitelist]) } { return } } default { discard } } HTTP::redirect "http://srypage.acme.com/sorry/nac/?hn=[HTTP::host][HTTP::uri]" } I suppose to just check the URI against the datagroup instead of the src ip, it could be changed inline for each condition Hope this helps Thanks M - Yozzer
Nimbostratus
Thanks all,
The datagroup will have various values that i want to test for in the url (i.e. a.txt, b.txt, c.txt, etc) and i want to perform actions when they are in the url.
I want to use a data group list so i can just remove the values from the data group list without having to alter the code.
If i cant use it within a switch statement how can i call the data group list from the if statement:
if [HTTP::uri] contains value from data group list then do stuff else do other stuff.
Thanks - Yozzer
Nimbostratus
The data group list isnt held in the irule but added or removed from the Data Group List tab (in the GUI under Local Traffic >> iRules >> Data Group List) - nitass
Employee
as far as i know, i don't think it's possible.
btw, i think your question is similar to this one.
Can you refer to a data group from within a switch?
http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/39/aft/27638/showtab/groupforums/Default.aspx
cheer! - Yozzer
Nimbostratus
Really! Its not possible to use data group lists with an if statement? - nitass
Employee
no, i mean i think it's not possible to use data group with switch. - hoolio
Cirrostratus
The datagroup will have various values that i want to test for in the url (i.e. a.txt, b.txt, c.txt, etc) and i want to perform actions when they are in the url.
I think Colin's suggestion is pretty close to this. What type of actions do you want to take? Can you give us some more specific examples of the URIs and corresponding actions?
Aaron - Yozzer
Nimbostratus
Hi
I just want to check if any of the individual values in the data group list are in the [HTTP::uri]. How do i call the data group list in the code (i.e. how do i call it to be used)? ::allowed_urls or allowed_urls or something else?
I can handle the actions to be performed.
Thanks
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
