Forum Discussion
Mar 07, 2015
BIG-IP : iRule test that variable exists and has certain value
F5 BIG-IP Virtual Edition v11.4.1 (Build 635.0) LTM on ESXi
What is the simplest most elegant syntax to test that a variable exists and has a certain value ?
For example if I want to determine t...
Kai_Wilke
Dec 14, 2016MVP
Hi BaltoStar,
if the given variable exists in 90% of the cases, then
[catch {}]
will do an awesome job...
when HTTP_REQUEST {
if { [catch {
if { $variable } then {
log local0.debug "The variable does exist and has a value of 1"
}
}] } then {
log local0.debug "The variable does not exists."
}
}
... but if the variable exists in less than 90% of the cases, then
[info exists]
will start to outperform [catch {}]
.
when HTTP_REQUEST {
if { ( [info exists variable] )
and ( $variable ) } then {
log local0.debug "the variable does exist and has a value of 1"
} else {
log local0.debug "The variable does not exists or has an value other than 1."
}
}
Note: The reson for this is that a successful
command is slightly faster than [catch {}]
but on the other hand an unsuccessful [info exists]
command is much slower than [catch {}]
.[info exists]
Cheers, Kai
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