Check if static variable exists before referencing to it
Hi All,
I have created an iRule performing DNS lookup and storing the result in static variable, so it could be referred from another iRule.
....
set static::my_variable "some value"
.....
As a precaution, in the second iRule I put verification of variable value before actually using it
if {"${static::my_variable}X" eq "X"}{
Input was empty, take default action
log local0.err "Lookup failed"
} else {
Variable is not empty, I can use it
log local0.err "Name resolved to $static::my_variable"
}
It worked fine during tests as I build iRules consequently.
It worked as expected even when I simulated DNS server failure and name actually could not be resolved - health check worked fine.
BUT.
When F5 was rebooted, log was flooded with error messages:
"tmm3 err tmm3[11714]: 01220001:3: TCL error: /Common/iRule_2 - can't read "static::my_variable": no such variable while executing "if {"${static::my_variable}X" eq "X"}{ Input was empty, take default action..."
errr... OK, I got it. My rule was checking if variable has empty value, but when F5 was rebooted second iRule was hit before the first one, so variable was not defined at all. So I should check not only variable value, but variable existence as well.
Question: how should I check if variable exists when variable is defined in another iRule?