Forum Discussion
panos_101277
Nimbostratus
Apr 29, 2008Multiple irules using same local variable name
Hello,
First off thanks to all the contributors for their many examples and tips, it has really helped a lot.
My question is a simple one but I haven't been able to find an answer ...
hoolio
Cirrostratus
Apr 30, 2008It is somewhat inconvenient. You could try something like setting a single local variable (not in RULE_INIT) in each rule to something unique and then build the variable names in that particular rule based on the first variable. Maybe an example would be easier to demonstrate:
rule rule1 {
when CLIENT_ACCEPTED {
set var_prefix "rule1"
set ${var_prefix}var1 "this is rule1's var1 value"
log local0. "$var_prefix variable name ${var_prefix}var1, variable value: [set [subst ${var_prefix}var1]]"
}
}
rule rule2 {
when CLIENT_ACCEPTED {
set var_prefix "rule2"
set ${var_prefix}var1 "this is rule2's var1 value"
log local0. "$var_prefix variable name ${var_prefix}var1, variable value: [set [subst ${var_prefix}var1]]"
}
}
Here is the sample output from a request to a vip with both rule1 and rule2 added:
Rule test_rule1 : rule1 variable name rule1var1, variable value: this is rule1's var1 value
Rule test_rule2 : rule2 variable name rule2var1, variable value: this is rule2's var1 value
I guess you could put in a feature request with F5 support asking for the scope of local variables to be limited to the rule they're set in, but I'm guessing there is a good reason for the way it is now.
Aaron
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